
//	Flash-Detection und Gabelfunktion
//	inkl. atomatischer Syntax fuer XHTML

//	aw - pepperzak - Version: 2005-02-14

var xhtml = true;
	
var gIsWin;
var gIsMac;
var gIsIE;

var gBrowserVersion;
	
var gFlashVersion;
var gFlashNeeded;
var gFlashDetectable;
var gFlashInstalled;
var gFlashActive;
var gFlashImplementation;
var vbChecked;
var vbFlashInstalled;
var vbFlashVersion;
var gFlashOK;
var gEndTag = (xhtml == true) ? ' />' : '>';

Get_Environment();



//Alert_Status ();

//	----------

function Get_Environment () {

	if (typeof (gFlashNeeded) == 'undefined') gFlashNeeded = 6;

	gAppVersion = navigator.appVersion;
	gUserAgent = navigator.userAgent;
	
	gIsWin  = (gAppVersion.indexOf('Win') != -1) ? true : false;
	gIsMac  = (gAppVersion.indexOf('Mac') != -1) ? true : false;
	gIsIE	= (document.all) ? true : false;
	
	CheckMSIE = gUserAgent.indexOf('MSIE');
	
	if (CheckMSIE > -1) {	
		Short = gUserAgent.substr(CheckMSIE+5,100);
		gBrowserVersion = Short.substr(0,Short.indexOf(';'));
	}

	if (gIsWin && gIsIE && typeof (vbChecked) == 'undefined') {

		vbChecked = true;
		vbFlashInstalled = false;
		vbFlashVersion = false;
		
		document.writeln ('<script language="VBScript">');
		document.writeln ('Private i, ObjAct');
		document.writeln ('On Error Resume Next');
		document.writeln ('vbFlashInstalled = False');
		document.writeln ('vbFlashVersion = False');
		document.writeln ('For i = 10 To 1 Step -1');
		document.writeln ('Set ObjAct = CreateObject("ShockwaveFlash.ShockwaveFlash." & i)');	// Anfuehrungszeichen nicht tauschen!
		document.writeln ('vbFlashInstalled = IsObject(ObjAct)');
		document.writeln ('If vbFlashInstalled Then');
		document.writeln ('vbFlashVersion = CStr(i)');
		document.writeln ('Exit For');
		document.writeln ('End If');
		document.writeln ('Next');
		document.writeln ('</script>');
	}

	gFlashDetectable = true;
	gFlashInstalled = false;
	gFlashActive = false;
	gFlashVersion = -1;
	gFlashImplementation = -1;

	if (vbFlashInstalled) {
	
		gFlashInstalled = true;
		gFlashActive = gFlashInstalled;
		gFlashVersion = 1 * vbFlashVersion;
		gFlashImplementation = 'ActiveX';
		
	} else if (navigator.plugins && navigator.plugins.length > 0) {
	
		gFlashImplementation = 'Plugin';
		if (navigator.plugins['Shockwave Flash']) {
		
			gFlashInstalled = true;
			var StringTmp = navigator.plugins['Shockwave Flash'].description.split(' ');

			for (var i=0; i<StringTmp.length; ++i) {
			
				if (isNaN(parseInt(StringTmp[i]))) continue;
				gFlashVersion = 1*StringTmp[i];
			}
		}

		if (navigator.mimeTypes['application/x-shockwave-flash'])
 			gFlashActive = (navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin != null);
	}
	
	if (gIsIE && gIsMac && (1*gBrowserVersion) < 5) gFlashDetectable = false;
	if (gFlashVersion == -1) gFlashImplementation = -1;

	gFlashOK = (gFlashVersion >= (1 * gFlashNeeded));
	if (!gFlashActive || !gFlashDetectable) gFlashOK = false;

}

//	----------

function Show_Flash (File, XSize, YSize, VersionOpt, BGColorOpt, NoFlashImgOpt, NoFlashURLOpt, LooseOpt) {

	if (typeof (File) != 'string' || typeof (XSize) == 'undefined' || typeof (YSize) == 'undefined') return false;
	if (typeof (LooseOpt) == 'undefined') LooseOpt = '';
	gFlashOK = (gFlashVersion >= VersionOpt);
	
	if (typeof (VersionOpt) == 'undefined') VersionOpt = 5;
	if (typeof (BGColorOpt) == 'undefined') BGColorOpt = '#ffffff';
	if (BGColorOpt.length < 6) BGColorOpt = '#dd0000';
	
	if (gFlashOK) {
		Build_SWF (File, XSize, YSize, VersionOpt, BGColorOpt);
	} else {
		if (typeof (NoFlashURLOpt) == 'string' && NoFlashURLOpt != '') {
			location.replace (NoFlashURLOpt);
		} else if (typeof (NoFlashImgOpt) == 'string' && NoFlashImgOpt != '') {
			Build_Img (NoFlashImgOpt, XSize, YSize, LooseOpt);
		} else {
			Build_Alt (XSize, YSize, VersionOpt, BGColorOpt);
		}
	}
}

//	----------

function Build_SWF (FileAndParams, XSize, YSize, VersionOpt, BGColorOpt) {
	
	if (typeof (FileAndParams) == 'undefined') {
		document.write('<b>Build_SWF</b>: keine swf-Datei angegeben');
		return false;
	}

	if (typeof (XSize) == 'undefined' || typeof (YSize)=='undefined') {
		document.write('<b>Build_SWF</b>: keine Gr&ouml;&szlig;enangabe');
		return false;
	}

	FXSize = XSize;
	FYSize = YSize;
	
	if (FXSize == '100%') FXSize = window.innerWidth;
	if (FYSize == '100%') FYSize = window.innerHeight;
	if (isNaN (FXSize) || typeof (FXSize) == 'undefined' || FXSize == 0) FXSize = document.body.offsetWidth;
	if (isNaN (FYSize) || typeof (FYSize) == 'undefined' || FYSize == 0) FYSize = document.body.offsetHeight;
	
	if (isNaN (FXSize) || typeof (FXSize) == 'undefined' || FXSize == 0 || isNaN (FYSize) || typeof (FYSize) == 'undefined' || FYSize == 0) {
		document.write('<b>Build_SWF</b>: Fenstergr&ouml;&szlig;e kann nicht ermittelt werden');
		return false;
	}

	srcPage = Replace (location.href, '&', '!');

	FileAndParams += (FileAndParams.indexOf('?') == -1) ? '?' : '&amp;';
	FileAndParams += ('ht=1&amp;js=1&amp;xsize=' + FXSize + '&amp;ysize=' + FYSize + '&amp;fver=' + gFlashVersion + '&amp;page=' + srcPage);
	
	FlLoop		= 'true';
	FlMenu		= 'false';
	FlQuality	= 'high';
	FlAlign		= 'lt';
	FlScale		= 'noscale';
//	FlMode		= 'opaque';
		
	FlashString	 = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	FlashString	+= 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + VersionOpt + ',0,0,0" ';
	FlashString	+= 'width="' + XSize + '" ';
	FlashString	+= 'height="' + YSize + '">';
	FlashString	+= '<param name="movie" value="' + FileAndParams + '"' + gEndTag;
	FlashString	+= '<param name="loop" value="' + FlLoop + '"' + gEndTag;
	FlashString	+= '<param name="menu" value="' + FlMenu + '"' + gEndTag;
	FlashString	+= '<param name="quality" value="' + FlQuality + '"' + gEndTag;
	FlashString	+= '<param name="scale" value="' + FlScale + '"' + gEndTag;
	FlashString	+= '<param name="salign" value="' + FlAlign + '"' + gEndTag;
//	FlashString	+= '<param name="wmode" value="' + FlMode + '"' + gEndTag;
	FlashString	+= '<param name="bgcolor" value="' + BGColorOpt + '"' + gEndTag;
	if (FileAndParams.indexOf('StroboScope') != -1)
	{
   	FlashString	+= '<param name="settings" value="hide"' + gEndTag;
		FlashString	+= '<param name="allowFullScreen" value="true"' + gEndTag;
	}
	FlashString	+= '<embed src="' + FileAndParams + '" ';
	FlashString	+= 'loop="' + FlLoop + '" ';
	FlashString	+= 'menu="' + FlMenu + '" ';
	FlashString	+= 'quality="' + FlQuality + '" ';
	FlashString	+= 'scale="' + FlScale + '" ';
	FlashString	+= 'salign="' + FlAlign + '" ';
//	FlashString	+= 'wmode="' + FlMode + '" ';
	FlashString	+= 'bgcolor="' + BGColorOpt + '" ';
	FlashString	+= 'width="' + XSize + '" ';
	FlashString	+= 'height="' + YSize + '" ';
	if (FileAndParams.indexOf('StroboScope') != -1)
	{
		FlashString	+= 'settings="hide" ';
		FlashString	+= 'allowFullScreen="true" ';
	}
	FlashString	+= 'type="application/x-shockwave-flash" ';
	FlashString	+= 'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
	FlashString	+= '</embed></object>';

	document.write (FlashString);
//	alert (FlashString);
}

//	----------

function Build_Img (File, XSize, YSize, Opt) {

//	var ImgString = '<img src="' + File + '" alt="" width=' + XSize + ' height=' + YSize + ' border="0" align="top" usemap="#noFlashImage"' + gEndTag;
	var ImgString = '<img src=' + File + ' alt="" width=' + XSize + ' height=' + YSize + ' border="0" align="top"' + Opt + gEndTag;
	document.write (ImgString);
}

//	----------

function Build_Alt (XSize, YSize, Version, BGColor) {

	AltString  = '<table border="0" bgcolor="#dd0000" width=' + XSize + ' height=' + YSize + ' cellspacing="10" cellpadding="20">';
	AltString += '<tr><td align="center" valign="middle" bgcolor="' + BGColor + '">';
	AltString += 'FlashPlayer-Version nicht vorhanden<br>bzw. nicht ausreichend!<br>&nbsp;<br>';
	AltString += 'Ermittelte Version: ' + (1 * gFlashVersion) + '<br>&nbsp;<br>';
	AltString += '<br><a href="http://www.macromedia.com/de/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash&Lang=German" target="_blank">Zur Download-Seite</a>';
	AltString += '</td></tr></table>';
	
	document.write (AltString);
}

//	----------

function Show_FlashStatus (StatTxt)
{
	if (typeof (StatTxt) != 'string') StatTxt = ' ';
	if (StatTxt == '') StatTxt = ' ';
	window.status = unescape(StatTxt);
}

//	----------

function Alert_Status () {

	//	Kontrollausgabe der ermittelten Werte
	
	var aTxt = 'gIsWin: ' + (1 * gIsWin) + "\n";
	aTxt += 'gIsMac: ' + (1 * gIsMac) + "\n";
	aTxt += 'gIsIE: ' + (1 * gIsIE) + "\n";
	aTxt += 'gBrowserVersion: ' + (1 * gBrowserVersion) + "\n";
	aTxt += 'gFlashVersion: ' + (1 * gFlashVersion) + "\n";
	aTxt += 'gFlashNeeded: ' + (1 * gFlashNeeded) + "\n";
	aTxt += 'gFlashOK: ' + (1 * gFlashOK) + "\n";

	alert (aTxt);

}

//	----------

function Replace (SrcTxt, OldStr, NewStr) {

	//	Ersetzt einen Teil-String
	
	while (SrcTxt.indexOf(OldStr) != -1) {
	
		SrcTxt = SrcTxt.substring (0,SrcTxt.indexOf(OldStr)) + NewStr + SrcTxt.substring (SrcTxt.indexOf(OldStr) + OldStr.length ,SrcTxt.length); 
	}

	return (SrcTxt);
}
