//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();

//window.alert('flash player version installed='+installedFlashversion);


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;
				//alert(y);
				
				//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 15 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="wmode" value="transparent"> ');
		document.write(' <param name="quality" value="high"> ');
		document.write(' <embed src="' + flashMovieURL + '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>');
		document.write('</object>');
	} else {
		document.write(noFlashHTML);
		document.close();
	}
}

// Deploy a flash movie OR alternative HTML
function DeployFlashMovieVideo(flashMovieURL, requiredFlashVersion, width, height, noFlashHTML, loadMovieURL, pageDivision, pageTitle) {
	var ShowFlash=false;
	
	//pageDivision used to postion vheight of preloader (height/pageDivision) e.g. 2 = 1/2 way down flash height, 4 = 1/4 way down flash height etc.
	
	//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 + '?filepath='+loadMovieURL+ '&pageDivision='+pageDivision+ '&pageTitle='+pageTitle+'"> ');
		document.write(' <param name="wmode" value="transparent"> ');
		document.write(' <param name="quality" value="high"> ');
		document.write(' <param name="allowFullScreen" value="true"> ');
		document.write(' <embed src="' + flashMovieURL  + '?filepath='+loadMovieURL+ '&pageDivision='+pageDivision+ '&pageTitle='+pageTitle+ '" allowFullScreen="true" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>');
		document.write('</object>');
	} else {
		document.write(noFlashHTML);
		document.close();
	}
}
