// 	Flasheinbindung mit Versionsprüfung
// 	1.6 Martin Fünning / Marcus Sümnick
// 	Last edit: 27.08.2007
//	maximieren und minimieren von Flash ist möglich


// Browsercheck
var FI1isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var FI1isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var FI1isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false
var FI1isFirefox = (navigator.userAgent.indexOf("Firefox") != -1) ? true : false
var FI1isSafari = (navigator.userAgent.indexOf("Safari") != -1) ? true : false

if (FI1isOpera) {
  FI1isIE = true;
}

// Log
// benötigt Firefox mit FireBug
var FI1showLog = false;

// versioncheck
var FI1hasRightVersion = false;

// IE Spezifisches VB Script laden
if (FI1isIE) {
	FI1showLog = false;
}

// Standart movie config
var movieConfig = new Object();
movieConfig["menu"] = "false";
movieConfig["quality"] = "high";
movieConfig["play"] = "true";
movieConfig["loop"] = "false";
movieConfig["allowScriptAccess"] = "sameDomain";


function insertFlash() {
	
	//***************************************************************\\
	// Init der Variablen
	//***************************************************************\\
	var FI1flashPath = "";			//URL der SWF Datei
	var FI1flashContainerId = "";	//ID des Objektes das die Einbindung erhalten soll.
	var FI1flashVersion = "";		//Benötigte Flashversion
	var FI1flashWidth = "900";			//Breite des Movies
	var FI1flashHeight = "900";		//Höhe des Movies
	var FI1flashArgString = "";		//Im moment ungenutzt (evtl Parameter)
	for (var FI1i = 0; FI1i < insertFlash.arguments.length; FI1i=FI1i+4) {
		
		//***************************************************************\\
		// Speichern der Paramerter für den Movie
		//***************************************************************\\
		FI1flashPath = insertFlash.arguments[FI1i];
		FI1flashArgString = insertFlash.arguments[FI1i+1];
		FI1flashContainerId = insertFlash.arguments[FI1i+2];
		FI1flashVersion = insertFlash.arguments[FI1i+3];
		FI1flashWidth = document.getElementById(FI1flashContainerId).style.width.replace(/[a-z|A-Z]+/, "");
		FI1flashHeight = document.getElementById(FI1flashContainerId).style.height.replace(/[a-z|A-Z]+/, "");
		FI1hasRightVersion = DetectFlashVer(FI1flashVersion, 0, 0);
		
		paramName = "";
		paramNameActive = true
		
		for(FI_count = 0; FI_count < FI1flashArgString.length; FI_count++) {
			if (paramNameActive) {
				if(FI1flashArgString.charAt(FI_count).search(/[a-zA-Z0-9\-\_]/) != -1) {
					paramName = paramName+FI1flashArgString.charAt(FI_count);
				}
				if(FI1flashArgString.charAt(FI_count).search(/[:=]/) != -1) {
					movieConfig[paramName] = "";
					paramNameActive = false
				}			
			} else {
				if(FI1flashArgString.charAt(FI_count).search(/[a-zA-Z0-9\-\_]/) != -1) {
					movieConfig[paramName] = movieConfig[paramName]+FI1flashArgString.charAt(FI_count);
				}
				if(FI1flashArgString.charAt(FI_count).search(/[;]/) != -1) {
					paramName = "";
					paramNameActive = true
				}
			}			
		}
		
		//***************************************************************\\
		// Konsolenausgabe wenn Logging Aktiv
		//***************************************************************\\
		FI1showLog?console.log("Flashmovie: "+FI1flashPath):null;
		FI1showLog?console.info("Pfad: ", FI1flashPath):null;
		FI1showLog?console.info("Get String: ", FI1flashGetString):null;
		FI1showLog?console.info("Container ID: ", FI1flashContainerId):null;
		FI1showLog?console.info("Benötigte Version: ", FI1flashVersion):null;
		FI1showLog?console.info("Breite: ", FI1flashWidth):null;
		FI1showLog?console.info("Höhe: ", FI1flashHeight):null;
		if (FI1showLog) {
			FI1hasRightVersion?console.info("Versionscheck bestanden"):console.error("Clientversion nicht ausreichend");
		}
		
		///////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
				
		if (FI1hasRightVersion) {
			//***************************************************************\\
			// Ausgabe des Flashobjektes, wenn geforterte version stimmt
			//***************************************************************\\	
			var FlashObj, atrName, atrValue, objHagon, statAtr;
			var container = document.getElementById(FI1flashContainerId);

if (!FI1isIE) {
				embedObj = document.createElement("embed");
}
			var urlGetString = "";
			for (var paramName in movieConfig) {
				//Parameter übergabe
				if (paramName == 'noCache') {
					if (FI1flashPath.search(/[\?]/) != -1) {
						urlGetString = "&cachefix="+Math.random();
					} else {
						urlGetString = "?cachefix="+Math.random();	
					}	
				} else {
					paramString = paramString+'<param name="'+paramName+'" value="'+movieConfig[paramName]+'" />';
					if (!FI1isIE) {
						//embed
						atrName = paramName;
						atrValue = movieConfig[paramName];
						objHagon = embedObj;
						statAtr = document.createAttribute(atrName);
						statAtr.nodeValue = atrValue;
						objHagon.setAttributeNode(statAtr);
						atrName = false;
						atrValue = false;
						objHagon = false;
						statAtr = false;
				}	
			}
			}
			// Hauptobjekt
			if (FI1isIE) {
		
				var paramString = "";
				//Parameter übergabe
				paramString = paramString+'<param name="movie" value="'+FI1flashPath+urlGetString+'" />';
				
			}
			/////////////////////////////////////////////
			if (!FI1isIE) {
				atrName = "type";
				atrValue = "application\/x-shockwave-flash";
				objHagon = embedObj;
				statAtr = document.createAttribute(atrName);
				statAtr.nodeValue = atrValue;
				embedObj.setAttributeNode(statAtr);
				atrName = false;
				atrValue = false;
				objHagon = false;
				statAtr = false;
				
				atrName = "pluginspage";
				atrValue = "http://www.macromedia.com/go/getflashplayer";
				objHagon = embedObj;
				statAtr = document.createAttribute(atrName);
				statAtr.nodeValue = atrValue;
				objHagon.setAttributeNode(statAtr);
				atrName = false;
				atrValue = false;
				objHagon = false;
				statAtr = false;
	
				atrName = "width";
				//atrValue = FI1flashWidth;
				atrValue = "100%"
				objHagon = embedObj;
				statAtr = document.createAttribute(atrName);
				statAtr.nodeValue = atrValue;
				objHagon.setAttributeNode(statAtr);
				atrName = false;
				atrValue = false;
				objHagon = false;
				statAtr = false;
				
				atrName = "height";
				//atrValue = FI1flashHeight;
				atrValue = "100%"
				objHagon = embedObj;
				statAtr = document.createAttribute(atrName);
				statAtr.nodeValue = atrValue;
				objHagon.setAttributeNode(statAtr);
				atrName = false;
				atrValue = false;
				objHagon = false;
				statAtr = false;
				
				atrName = "src";
				atrValue = FI1flashPath+urlGetString;
				objHagon = embedObj;
				statAtr = document.createAttribute(atrName);
				statAtr.nodeValue = atrValue;
				objHagon.setAttributeNode(statAtr);
				atrName = false;
				atrValue = false;
				objHagon = false;
				statAtr = false;


/*
                                atrName = "wMode";
                                atrValue = "transparent";
                                objHagon = embedObj;
                                statAtr = document.createAttribute(atrName);
                                statAtr.nodeValue = atrValue;
                                objHagon.setAttributeNode(statAtr);
                                atrName = false;
                                atrValue = false;
                                objHagon = false;
                                statAtr = false;*/


			}
			// Ausgabe des erstellten objektes
			document.getElementById(FI1flashContainerId).style.display="";
			if (!FI1isIE) {
				container.appendChild(embedObj);
			} else {
				//container.appendChild(FlashObj); (zur zeit auskommentiert, da der ie des net mag)
				var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
				+ 'width="100%" height="100%"'
				+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
				+ paramString
				+ '<\/object>';
				document.getElementById(FI1flashContainerId).innerHTML = oeTags;
			}
			
		} else {
			//***************************************************************\\
			// Ausgabe der alternative
			//***************************************************************\\				
			document.getElementById(FI1flashContainerId).style.display="none";
			document.getElementById(FI1flashContainerId+"_noflash").style.display="";
		}
	}	
}

//***************************************************************\\
// Adobe Flash Detection
//***************************************************************\\	

function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
} 

function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// loop backwards through the versions until we find the newest version	
	for (i=25;i>0;i--) {	
		if (FI1isIE && FI1isWin && !FI1isOpera && !FI1isFirefox) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);	
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(FI1isIE && FI1isWin && !FI1isOpera && !FI1isFirefox) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
	return (reqVer ? false : 0.0);
}



//*****************************************************************************
// Fleetmon von der Normale in die Vollbildverion überführen
//*****************************************************************************
function maxFleetmon( _sElementId, _iWidth, _iHeight,_iLeft, _iInnerWidth, _iInnerHeight ){

	var oToolbar = document.getElementById('toolbar');
	oToolbar.style.display = "block";
	
	var oMaxLink = document.getElementById('maxFleetmon');
	oMaxLink.style.display = "none";

	//Inneres Containerelement
	var oInnerContainer = document.getElementById(_sElementId[1]);
	oInnerContainer.style.width = _iInnerWidth;
	oInnerContainer.style.height = _iInnerHeight;
	oInnerContainer.style.left = _iLeft;
	
	oInnerContainer.style.marginLeft = "0px";

	//Äußeres Containerelement
	var oContainer = document.getElementById(_sElementId[0]);

	oContainer.style.width = _iWidth;
	oContainer.style.height = _iHeight;
	oContainer.style.top = "0px";
	oContainer.style.backgroundColor = "#A02031";
	oContainer.style.paddingLeft = "0px";

	//Allen Seiteninhalt verstecken um eine Scrallbar zu vermeiden (auch den
	//Footer
	var oContent = document.getElementById("main_div").style.display='none';
	var oFooter = document.getElementById("footer").style.display='none';
}

//*****************************************************************************
// Fleetmon vom Vollbildmodus in die ormale Verion überführen
//*****************************************************************************

function minFleetmon ( _sElementId, _iWidth, _iHeight,_iLeft, _iTop, _iInnerWidth, _iInnerHeight  ){
	
    var oToolbar = document.getElementById('toolbar');
    oToolbar.style.display = "none";

		var oMaxLink = document.getElementById('maxFleetmon');
		oMaxLink.style.display = "block";

    //Inneres Containerelement
    var oInnerContainer = document.getElementById(_sElementId[1]);

    oInnerContainer.style.width = _iInnerWidth;
    oInnerContainer.style.height = _iInnerHeight;
    oInnerContainer.style.left = _iLeft;
		/*oInnerContainer.style.marginLeft = "10px";*/

	//Äußeres Containerelement
    var oContainer = document.getElementById(_sElementId[0]);
    oContainer.style.width = _iWidth;
    oContainer.style.height = _iHeight;
    oContainer.style.top = _iTop;
    oContainer.style.backgroundColor = "transparent";
	
	//Allen Seiteninhalt verstecken um eine Scrallbar zu vermeiden (auch den
	//Footer
	var oContent = document.getElementById("main_div").style.display='block';
	var oFooter = document.getElementById("footer").style.display='block';
}

