function getMovieRef(elemId) {
   	// IE and Netscape refer to the movie object differently.
	//IE/PC and Safari/Mac
	if(window[elemId] != null){
		//alert("returning window[elemId]");
		return window[elemId];
	//Others (Mozilla etc.)
	}else if(document[elemId] != null){
		//alert("returning document[elemId]");
		return document[elemId];
	}
	//Did not find id...
	return null;
}



//Global flash Object with info of if flash is installed plus what version.
var oFlash = null;

//Global variable for continuous checks if the flash movie has been loaded, used in initLoadFlashBanner, playFlashWhenLoaded
var swfLoadedInterval = null;


function loadFlashVideo(flashId)
{
  //globalFlashId is declared in the calling page
  var swfReferens = getMovieRef(flashId);

    if(swfReferens.PercentLoaded == undefined){
        
	    var iPercentLoaded = 0;
    }else{

        var iPercentLoaded = parseInt(swfReferens.PercentLoaded());
    }

  if(iPercentLoaded == 100)
  {
    swfReferens.SetVariable("isTriggered","1");
    if(swfLoadedInterval != null)
    {
      window.clearInterval(swfLoadedInterval);
      swfLoadedInterval = null;
    }
  }
}



//Detect flash version (if not installed, version will be 0 (zero)).
function getFlashplayerVersionMajor() {
    oFlash = getFlashInstalledObjInstance();
    if(oFlash.installed && oFlash.version >= 0){
        return oFlash.version;
        //alert("detectFlash, fc_highestVersion:" + fc_highestVersion);
    }
    return 0;
}


function writeFlashObj(flashId, flashSrc, width, height, bgcolor, flashvars){
  var generatedFlashStr = generateFlashStr(flashId, flashSrc, width, height, bgcolor, flashvars);
  document.write(generatedFlashStr);
}


function generateFlashStr(flashId, flashSrc, width, height, bgcolor, flashvars){
    //Find out current protocol to avoid security warning when in https.
    var currProtocol = window.location.protocol;

    if(currProtocol == null){
        currProtocol = "http:";
    }

    var embedCode_flash = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
	+ 'codebase="' + currProtocol + '//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" '
	+ 'width="'+ width +'" height="' + height + '" '
	+ 'id="'+ flashId +'">'
	+ '<param name="movie" value="' + flashSrc + '">'
	+ '<param name="quality" value="high">'
	+ '<param name="menu" value="false">'
	+ '<param name="bgcolor" value="'+ bgcolor +'">'
	+ '<param name="flashvars" value="' + flashvars + '">'
	+ '<param name="allowScriptAccess" value="always">'
	+ '<param name="play" value="true">'
	+ '<embed src="' + flashSrc + '" '
	+ 'menu="false" '
	+ 'quality="high" '
	+ 'bgcolor="' + bgcolor + '" '
	+ 'width="' + width + '" height="' + height + '" '
	+ 'allowScriptAccess="always" '
	+ 'play="true" '
	+ 'name="' + flashId + '" '
	+ 'type="application/x-shockwave-flash" '
	+ 'flashvars="' + flashvars + '" '
	+ 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
  + '</embed>'
	+ '</object>';

  return embedCode_flash;
}
//Exempel:
//<object>
//	<param name="flashvars" value="image=/img/showroom.jpg|movieref=/flv/showroom.flv|timerloadmoviesec=40" />
//</object>



/*
Name: getFlashObjInstance()
Purpose: Singleton. Returns a FlashObj with information if flash is installed and what version.
*/
function getFlashInstalledObjInstance(){
    if(oFlash == null){
        return new FlashInstalledObj();
    }else{
        return oFlash;
    }
}
/*
Name: FlashInstalledObj()
Purpose: Returns an Object with information if flash is installed and what version.
Attributes:
    installed - true if MM Flash is installed, false otherwise
    version - Major flashversion
Note: To test even higher future versions, edit variable "flash_versions".
*/
function FlashInstalledObj(){
	// This script test up to the following (future) version.
	flash_versions = 20;

	var flash = new Object();
	flash.installed=false;
	flash.version=0;

	// Test Netscape-compatible plugins.
	if (navigator.plugins && navigator.plugins.length) {
		for (x=0; x < navigator.plugins.length; x++) {
			if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
				var flashVersionWithLetters = navigator.plugins[x].description.split('Shockwave Flash ')[1];

				var flashVersionWithNumbers = "";
				var allowedChars = "0123456789.";
				for(i=0;i<flashVersionWithLetters.length;i++){
					var tmpChar = flashVersionWithLetters.charAt(i);
					if(allowedChars.indexOf(tmpChar) != -1){
						//alert(tmpChar);
						flashVersionWithNumbers += tmpChar;
					}else{
						break;
					}
				}
				//alert(flashVersionWithNumbers);
				flash.version = parseInt(flashVersionWithNumbers);
				flash.installed = true;
				break;
			}
		}
	}else if (window.ActiveXObject) {
	//Test ActiveX-plugins (shockwave) for IE.
        var objTestFlashActiveX = null;
        for (x = 2; x <= flash_versions; x++) {
			try {
				objTestFlashActiveX = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
				if(objTestFlashActiveX) {
					flash.installed = true;
					flash.version = parseInt(x + '.0');
				}
			}catch(e) {
				//Do nothing, just testing...
			}
		}
	}
	return flash;
}
//Set flashversion on global variable, fc_highestVersion.


