//Functions to get flash version & deploy flash/HTML depending on installed Vs required version

// v8 required for Flash to load GIFs
var flashinstalled = 0;
var installedFlashversion = GetFlashVersion();

function GetFlashVersion()	{
	var flashversion = 0;
	
	if (navigator.plugins && navigator.plugins.length) {
		x = navigator.plugins["Shockwave Flash"];
		if (x) {
			flashinstalled = 1;
			if (x.description) {
				y = x.description;
				//Updated 28/10/08, charAt() failed with player version 10 in FF (returns 0)
				//flashversion = y.charAt(y.indexOf('.')-1);
				//y=Shockwave Flash 10.0 r12
				
				fullstop = y.indexOf('.');
				y = y.substr(0, fullstop);
				lastspace = y.lastIndexOf(' ', y);
												
				flashversion = y.substring(lastspace+1);
				//alert('flashversion#'+flashversion+'#');
			}
		} else {
			flashinstalled = 1;
			if (navigator.plugins["Shockwave Flash 2.0"]) {
				flashinstalled = 1;
				flashversion = 2;
			}
		}
	
	return flashversion;	

	}	else {
		if (navigator.mimeTypes && navigator.mimeTypes.length)	{
			x = navigator.mimeTypes['application/x-shockwave-flash'];
			if (x && x.enabledPlugin) {
				flashinstalled = 1;
			} else {
				flashinstalled = 0;
			}
		} else {
			document.open();
			document.write('<SCRIPT LANGUAGE=VBScript\> \n');
			document.write('Function VBGetSwfVer() \n');
			document.write('	on error resume next \n');
			document.write('	Dim flashObject \n');
			document.write('	for i=15 to 2 Step - 1\n');  //current version is 9, but set to 12 for future-proofing.
			document.write('	Set flashObject = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n');
			document.write('	if IsObject(flashObject) then\n');
			document.write('		flashinstalled = 1\n');
			document.write('		flashversion=i\n');
			document.write('		Exit for \n');
			document.write('	end if\n');
			document.write('	next\n');
			document.write('	VBGetSwfVer = flashversion \n');
			document.write('End Function \n');
			document.write('<\/SCRIPT\> \n');
			document.close();
		}
		
		return VBGetSwfVer();
	}	

}


// Deploy a flash movie OR alternative HTML
function DeployFlashMovie(flashMovieURL, requiredFlashVersion, width, height, noFlashHTML) {
	var ShowFlash=false;

	//alert(flashinstalled + '.' + installedFlashversion + '.' + requiredFlashVersion);
	if (flashinstalled == 1){
		if (installedFlashversion>=requiredFlashVersion) {
			ShowFlash=true;
		}
	}
	document.open();
	
	if (ShowFlash==true) {
		document.write(' <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + width + '" height="' + height + '"> ');
		document.write(' <param name="movie" value="' + flashMovieURL + '"> ');
		document.write(' <param name="quality" value="high"> ');
		document.write(' <param name="wmode" value="#FFFFFF"> ');
		document.write(' <embed src="' + flashMovieURL + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" wmode="transparent"></embed>');
		document.write('</object>');
	} else {
		document.write(noFlashHTML);
		document.close();
	}
}

// Deploy a flash movie OR alternative HTML, attach a specific ID to the 
function DeployFlashMovieWithID(flashMovieURL, requiredFlashVersion, width, height, noFlashHTML, flashID) {
	
	var ShowFlash=false;

	//alert(flashinstalled + '.' + installedFlashversion + '.' + requiredFlashVersion);
	if (flashinstalled == 1){
		if (installedFlashversion>=requiredFlashVersion) {
			ShowFlash=true;
		}
	}
	document.open();
	
	if (ShowFlash==true) {
		//document.write(' <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" id="'+flashID+'" width="' + width + '" height="' + height + '"> ');
		//document.write(' <param name="movie" value="' + flashMovieURL + '"> ');
		//document.write(' <param name="quality" value="high"> ');
		//document.write(' <param name="wmode" value="transparent"> ');
		//document.write(' <embed src="' + flashMovieURL + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="'+flashID+'_embed" id="'+flashID+'_embed" width="'  + width + '" height="' + height + '" wmode="transparent"></embed>');
		//document.write('</object>');
		
		document.write(' <object type="application/x-shockwave-flash" data="' + flashMovieURL + '" width="' + width + '" height="' + height + '" id="'+flashID+'"> ');
		document.write(' <param name="movie" value="'+ flashMovieURL +'"> ');
		document.write(' <param name="quality" value="high"> ');
		document.write(' <param name="wmode" value="transparent"> ');		
		document.write(' </object>');
		
	} else {
		document.write(noFlashHTML);
		document.close();
	}
}


function setFlashWidth(divid, newW){
	
	document.getElementById(divid).width = newW+"px";
	document.getElementById(divid).width = newW;
	
	
}

function setFlashHeight(divid, newH){

	document.getElementById(divid).style.height = newH+"px";  
	document.getElementById(divid).height = newH;  

}

function setFlashSize(divid, newW, newH){
	setFlashWidth(divid, newW);
	setFlashHeight(divid, newH);
	
}

function show(){
	
	setFlashSize('flashResizer',950,500);
	setFlashSize('flashMenu',950,500);
	
}

function hide(){
		
	setFlashSize('flashResizer',950,18);
	setFlashSize('flashMenu',950,18);
	
}

function resizeflash(iHeight)
{
	if((!is_safari && is_mac) || (is_firefox && is_win))
		oFlash = document.getElementById("swf_movie_embed"); 
	else
		oFlash = document.getElementById("swf_movie");
	oFlash.height = iHeight;
}