// UFO Light 1.1
// Copyright 2005-2006 Internetdienste Eisemuth
var UFOLight = {
	specialParams: ["movie", "width", "height", "majorversion", "build"],
	DOMisReady: false,
	FlashList: [],
	create: function(params, id)
	{
		if (UFOLight.goodFlashVersion(params['majorversion'], params['build'])) {
			if ( UFOLight.isReady )	{
				UFOLight.writeFlash(params, id);
			} else {
				UFOLight.FlashList.push( [params, id] );
			}
		}
	},
	onDomReady: function() {
		if (!UFOLight.isReady) {
			UFOLight.isReady = true;
			if ( UFOLight.FlashList ) {
				for ( var i = 0; i < UFOLight.FlashList.length; i++ ) {
					UFOLight.writeFlash( UFOLight.FlashList[i][0], UFOLight.FlashList[i][1] );
				};
				UFOLight.FlashList = null;
			}
		}
	},
	
	specialvar: function (element)
	{
		for (var i = 0; i < UFOLight.specialParams.length; i++) {
	        if (UFOLight.specialParams[i] == element) {
	            return true;
	        }
	    }
	    return false;
	},
	
	goodFlashVersion: function (majorversion, build)
	{
		var flashVer = 0;
		var verMajor, verMinor;
		var version = parseFloat(majorversion + '.' + build);
		if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
			var flashDescription = navigator.plugins["Shockwave Flash"].description;
			if (flashDescription) {
				var descArray = flashDescription.split(' ');
				var tmpArrayMajor = descArray[2].split('.');
				verMajor = tmpArrayMajor[0];
				if ( descArray[3] != "" ) {
					var tmpArrayMinor = descArray[3].split('r');
				} else {	
					var tmpArrayMinor = descArray[4].split('r');
				}
				verMinor = tmpArrayMinor[1] > 0 ? tmpArrayMinor[1] : 0;
				flashVer = parseFloat(verMajor + '.' + verMinor);
			}
		} else if (window.ActiveXObject) {
			try {
				var flashobj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				var desc = flashobj.GetVariable("$version");
				if (desc) {
					var descArr = desc.split(' ');
					var versionArr = descArr[1].split(',');        
					verMajor = versionArr[0];
					verMinor = versionArr[2];
					flashVer = parseFloat(verMajor + '.' + verMinor);
				}
			}
			catch(e) {}
		}
		if (typeof(flashVer) == 'undefined') return false;
		return (flashVer >= version);
	},
	
	writeFlash: function(params, id)
	{
		var flashhtml;
		var el = UFOLight.eleById(id);
		UFOLight.eleVis(id, 0);
		if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
			flashhtml = '<embed type="application/x-shockwave-flash" src="' + params.movie + '" width="' + params.width + '" height="' + params.height + '" pluginspage="http://www.macromedia.com/go/getflashplayer"';
			for (var p in params) {
				if (!UFOLight.specialvar(p)) {
					flashhtml += ' ' + p+ '="' + params[p] + '"';
				}
			}
			flashhtml += '></embed>';
			el.innerHTML = flashhtml;
		} else {
			flashhtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + params.width + '" height="' + params.height + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + params.majorversion + ',0,' + params.build + ',0">';
			flashhtml += '<param name="movie" value="' + params.movie + '" />';
			for (var p in params) {
				if (!UFOLight.specialvar(p)) {
					flashhtml += '<param name="' + p + '" value="' + params[p]+'">';
				}
			}
			flashhtml += '</object>';
			el.innerHTML = flashhtml;
		}
		UFOLight.eleVis(id, 1);
	},
	eleVis: function(ele, bShow)
	{
		if (!(e=UFOLight.eleById(ele))) return;
		if (e.style && (typeof(e.style.visibility) != 'undefined')) {
			e.style.visibility = bShow ? 'visible' : 'hidden';
		}
	},
	eleById: function(e)
	{
		if (typeof(e)!='string') return e;
		if (document.getElementById) ele=document.getElementById(e);
		else if(document.all) ele=document.all[e];
		else ele=null;
		return ele;
	}
};


(function(){
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=ufolight__ie_onload defer src=https:///><\/script>");
var script = document.getElementById("ufolight__ie_onload");
script.onreadystatechange = function() {
    if (this.readyState == "complete") {
        UFOLight.onDomReady();
    }
};
script = null;
/*@end @*/
	if (window.addEventListener) {
		window.addEventListener("load", UFOLight.onDomReady, false);
	} else if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", UFOLight.onDomReady, false );	// FF compatible?
		document.addEventListener('load', UFOLight.onDomReady, false);
	} else if (window.attachEvent) {
		window.attachEvent('onload', UFOLight.onDomReady);
	}
})();
