/*
	Last change:
		2009-03-31 David Schulz
		Added height for embed-tag 
		2009-02-11 David Schulz
		Updated detectFlash to support versions >= 10
		2008-09-06 Ola Ljungars
		Added height variable
		2008-10-29 Ola Ljungars
		Fixed bug if height was undefined

*/


	//Internal javscript below

	var requiredVersion = 5;   

	// System globals
	var flash2Installed = false;
	var flash3Installed = false;
	var flash4Installed = false;
	var flash5Installed = false;
	var flash6Installed = false;
	var maxVersion = 6;
	var actualVersion = 0;
	var hasRightVersion = false;

	//detect os
	var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

	//detect browser
	var appVer = navigator.appVersion.toLowerCase();
	var iePos  = appVer.indexOf('msie');
	var isIE = (iePos !=-1) ? true : false
	var strUserAgent =  navigator.userAgent.toLowerCase();

	//if IE detect version
	if (isIE) {
		is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
		is_major = parseInt(is_minor);	
	}

	jsVersion = 1.1;

	if(isIE && isWin){
	  document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	  document.write('on error resume next \n');
	  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
	  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
	  document.write('</SCRIPT\> \n'); 
	}
	
	//func_flash
	/*
	Tridion
	
	This function embeds an flash if the user has flash or else it shows an image.
	The function needs to be included on every page that uses flash (masterpages)
	
	*/
	function placeFlash(flashFile, alternateFile, objectClass, imageClass , alternateLink, altText, xmlFile, strHeight, strWidth){
		var height = strHeight;
		var width = strWidth;
		if(height!="" && typeof(height)!="undefined"){
			height=" height='" + height + "' ";
		}

		if(width!="" && typeof(width)!="undefined"){
			width=" width='" + width + "' ";
		}		
		if(flashFile.indexOf("swf")!=-1){
		    detectFlash(); //detect Flash version
		}
		
		//get values from xml
		var flashVars = "";
		
	
		if(hasRightVersion) {  // if we've detected an acceptable version
		    var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
          + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=3,0,0,0" '
          + height
		  + width
          + 'class="' + objectClass + '" >'
          + '<param name="movie" value="' + flashFile + '?xmlFile=' + xmlFile + '" />'
          + '<param name="bgcolor" value="white" />'
          + '<param name="scale" value="noborder" />'
          + '<param name="wmode" value="transparent">'
          + '<embed src="' + flashFile + '?xmlFile=' + xmlFile + '" '
          + 'class="' + objectClass + '" '
          + 'bgcolor="white" '
          + 'scale="noborder" '
          + 'wmode="transparent" '
          + height
		  + width
          + 'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
          + '</embed>'
          + '</object>';
		    document.write(oeTags); 
		  } 
		  else {
  			if(alternateLink != ""){
  			  if(alternateFile=="") 
  			    alternateFile = flashFile;
  			  var alternateContent = '<a href="' + alternateLink + '"><img class="' + imageClass + '" src="' + alternateFile + '" alt="' + altText + '" border="0" /></a>'
  			}
  			else{
  			  var alternateContent = '<img class="' + imageClass + '" src="' + alternateFile + '" alt="' + altText + '" border="0" />'
  			}
  		  document.write(alternateContent); 
		}
	}
	
	function detectFlash(){  
	  if (navigator.plugins){
	    if (navigator.plugins["Shockwave Flash 2.0"]
	        || navigator.plugins["Shockwave Flash"]){
	
	      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
	      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
	      
	      //var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
	      var flashVersion = parseInt(flashDescription.split(" ")[2].split(".")[0]);
	     
	      flash2Installed = flashVersion == 2;    
	      flash3Installed = flashVersion == 3;
	      flash4Installed = flashVersion == 4;
	      flash5Installed = flashVersion == 5;
	      flash6Installed = flashVersion >= 6;
	    }
	  }
	  
	  for (var i = 2; i <= maxVersion; i++){  
	    if (eval("flash" + i + "Installed") == true) actualVersion = i;
	  }
	  
	  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 3;  
		
	  if (actualVersion >= requiredVersion){
	    hasRightVersion = true;                
	  }
	}
