/*
version 2006.10
concept, design and production by Netvertising AG, Zurich 
*/
/*
-do not change this file
-do not put this code in a html-file! must be js-file.
-copy the commented code below into html-file.
-duplicate the function if you have multiple swf's.
-do not forget <noscript> tags in html.
-reqflashVersion is the required flash-version.
-params that are not set are not used.
noflash-version:
-'altPage' or 'altImg' should be URL's. 
-when both are not set no alternativ-version is provided.
'altImg' has the size of the flash.
*/

// EXAMPLE USAGE:
/*
var f=new function(){
this.reqflashVersion = 7;
this.flashName="test.swf";
this.flashId="myname"; //identification name
this.flashWidth=100;
this.flashHeight=100;
this.flashBgcolor="#FFFFFF";
this.flashScale="noborder"; //noborder, exactfit, noscale
this.flashAlign="top"; //top, bottom, left, right
this.flashSalign="TL"; // TL, TR, BL, BR
this.flashQuality="high"; // low, medium, high, autolow, autohigh
this.flashMenu="false"; //true, false
this.flashPlay=""; //true, false
this.flashLoop=""; //true, false
this.flashWmode="window"; //window,transparent, opaque
//this.altPage="noflash.php";
this.altImg="noflash.gif";
this.altHtml="<div>no flash installed</div>";
this.altFunc="showalt()";
this.moreParams="?sessid=1&lang=de";
this.badBrowsers=new Array("mac-safari", "win-ie");
this.flash();
}
*/
////////////////////////////
////////////////////////////
var debug=false;

Object.prototype.flash=flash;


function flash(){
	this.moreParams=(typeof(this.moreParams)!="undefined")? this.moreParams: "";
	var client=new ClientInfo();
	if((typeof(this.badBrowsers)!="undefined")? this.moreParams: ""){
		for(var i=0; i<this.badBrowsers.length; i++){
			var ar=this.badBrowsers[i].split("-");
			if(client[ar[0]] && client[ar[1]]){
				client.flashVersion=-1;
				break;
			}
		}
	}
	
	
	
	var htmltags="";
	//transparent hack for old opera and icab
	if(this.flashWmode=="transparent" && (client.opera_old || client.icab)){
		client.flashVersion=-1;
	}
	if(client.flashVersion >= this.reqflashVersion){
		htmltags+="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab' ";
		htmltags+=(typeof(this.flashId)!="undefined")? "id='"+this.flashId+"' ": "";
		htmltags+=(typeof(this.flashId)!="undefined")? "name='"+this.flashId+"' ": "";
		htmltags+=(typeof(this.flashWidth)!="undefined")? "width='"+this.flashWidth+"' ": "";
		htmltags+=(typeof(this.flashHeight)!="undefined")? "height='"+this.flashHeight+"' ": "";
		htmltags+=(typeof(this.flashAlign)!="undefined")? "align='"+this.flashAlign+"'": "";
		htmltags+=">\n";
		htmltags+="<param name=movie value='"+this.flashName+this.moreParams+"'>\n";
		htmltags+=(typeof(this.flashMenu)!="undefined")? "<param name=menu value='"+this.flashMenu+"'>\n": "";
		htmltags+=(typeof(this.flashSalign)!="undefined")? "<param name=salign value='"+this.flashSalign+"'>\n": "";
		htmltags+=(typeof(this.flashScale)!="undefined")? "<param name=scale value='"+this.flashScale+"'>\n": "";
		htmltags+=(typeof(this.flashQuality)!="undefined")? "<param name=quality value='"+this.flashQuality+"'>\n": "";
		htmltags+=(typeof(this.flashBgcolor)!="undefined")? "<param name=bgcolor value='"+this.flashBgcolor+"'>\n": "";
		htmltags+=(typeof(this.flashPlay)!="undefined")? "<param name=play value='"+this.flashPlay+"'>\n": "";
		htmltags+=(typeof(this.flashLoop)!="undefined")? "<param name=loop value='"+this.flashLoop+"'>\n": "";
		htmltags+=(typeof(this.flashWmode)!="undefined")? "<param name=wmode value='"+this.flashWmode+"'>\n": "";

		htmltags+="<embed src='"+this.flashName+this.moreParams+"' ";
		htmltags+=(typeof(this.flashId)!="undefined")? "name='"+this.flashId+"' ": "";
		htmltags+=(typeof(this.flashMenu)!="undefined")? "menu='"+this.flashMenu+"' ": "";
		htmltags+=(typeof(this.flashWidth)!="undefined")? "width='"+this.flashWidth+"' ": "";
		htmltags+=(typeof(this.flashHeight)!="undefined")? "height='"+this.flashHeight+"' ": "";
		htmltags+=(typeof(this.flashQuality)!="undefined")? "quality='"+this.flashQuality+"' ": "";
		htmltags+=(typeof(this.flashScale)!="undefined")? "scale='"+this.flashScale+"' ": "";
		htmltags+=(typeof(this.flashAlign)!="undefined")? "align='"+this.flashAlign+"' ": "";
		htmltags+=(typeof(this.flashSalign)!="undefined")? "salign='"+this.flashSalign+"' ": "";
		htmltags+=(typeof(this.flashBgcolor)!="undefined")? "bgcolor='"+this.flashBgcolor+"' ": "";
		htmltags+=(typeof(this.flashPlay)!="undefined")? "play='"+this.flashPlay+"' ": "";
		htmltags+=(typeof(this.flashLoop)!="undefined")? "loop='"+this.flashLoop+"' ": "";
		htmltags+=(typeof(this.flashWmode)!="undefined")? "wmode='"+this.flashWmode+"' ": "";
		htmltags+="pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'";
		htmltags+="></embed>";
		htmltags+="</object>";
		document.write();
		
	} else{
		if(this.altPage!="" && typeof(this.altPage)!="undefined"){
			location.href=this.altPage+this.moreParams;
		}
		else if(this.altImg!="" && typeof(this.altImg)!="undefined"){
			htmltags="<img src='"+this.altImg+"' width='"+this.flashWidth+"' height='"+this.flashHeight+"' border='0' alt=''>";
		}
		else if(this.altHtml!="" && typeof(this.altHtml)!="undefined"){
			htmltags=this.altHtml;
		}
		else if(this.altFunc!="" && typeof(this.altFunc)!="undefined"){
			eval(this.altFunc);
		}
	}
	document.write(htmltags);
	if(debug){
		alert("output content: \n"+htmltags);
	}
}

function getFlashVersion(client) {
	var flashVersion = -1;
	var flashVersion_DONTKNOW = -1;
	if (client.ns3) {
		return 0; //no flash for this old one
	}

	// NS3+, Opera3+, IE5+ Mac, firefox,safari (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') {
			for (i=15;i>0;i--) {
				if (flashPlugin.description.indexOf(i+'.') != -1){
					flashVersion = i;
					break;
				}
			}
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if ((client.ie4 || client.ie5) && client.vernum >= 4 && client.win) {
		//vb function for active-x
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('Function VBGetSwfVer(i) \n');
		document.write('on error resume next \n');
		document.write('Dim swControl, swVersion \n');
		document.write('swVersion = 0 \n');
		
		document.write('set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i)) \n');
		document.write('if (IsObject(swControl)) then \n');
		document.write('swVersion = swControl.GetVariable("$version") \n');
		document.write('end if \n');
		document.write('VBGetSwfVer = swVersion \n');
		document.write('End Function \n');
		document.write('</scr' + 'ipt\> \n');
		for (i=15;i>0;i--) {
			versionStr = VBGetSwfVer(i);
		}
		if(versionStr!=0 && versionStr!=-1){
			var tempArray = versionStr.split(" ");
			var tempString = tempArray[1];
			var versionArray = tempString .split(",");
			flashVersion=parseInt(versionArray[0]);
		}
		else {
			flashVersion = flashVersion_DONTKNOW;
		}
	}

	// older WebTV supports flash 2
	else if (client.webtv) flashVersion = 2;
	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}
	return flashVersion;
}

function ClientInfo(){
	this.agt=navigator.userAgent.toLowerCase();
	this.win = (this.agt.indexOf("win")!=-1 || this.agt.indexOf("16bit")!=-1);
	this.mac = !this.win;
	this.ver=navigator.appVersion;
	this.vernum=parseInt(navigator.appVersion);
	this.dom=document.getElementById? true: false;
	this.ie5=(this.ver.indexOf("MSIE")>-1 && this.dom);
	this.ie4=(document.all && !this.dom)? true: false;
	this.ie=(this.ie4 || this.ie5);
	this.ns5=(this.dom && this.vernum >= 5);
	this.ns4=(document.layers && !this.dom)? true: false;
	this.ns3=(this.agt.indexOf("mozilla/3")!=-1 && !this.ie4);
	this.opera = (window.opera)? true: false;
	this.opera_old=(this.opera && this.vernum<9);
	this.safari=(this.agt.indexOf("safari") !=-1);
	this.webtv=(this.agt.indexOf("webtv") != -1);
	this.icab=false;
	this.flashVersion=getFlashVersion(this);
	if(debug){
		var d="ClientInfo: \n";
		for(all in this){
			if(all!="flash"){
			d+=all+"="+this[all]+"\n";
			}
		}
		alert(d);
	}
	return this;
}
