/*
 * Phaistos Networks S.A. Adman :: Flash  [1.1]
*/






/* ========================== Events  ========================== */

	if (window.ActiveXObject) 			{
		window.ie =  ( window[document.implementation ? (window.XMLHttpRequest ? 'ie7' : 'ie6') : 'ie5'] ) = true;	
	}
	window.onDOMContentLoaded = function(fn) {
		if( (!document.addEventListener || window.safari) ) {
			if( !window._DOMCLEvents ) {
				window._DOMCLEvents = 	window._DOMCLEvents || []

				var _DOMCLFn		= function() {
					clearInterval(window._DOMCLTimer);
					for(var i = 0; i < window._DOMCLEvents.length; i++ ) {
						 window._DOMCLEvents[i]();
					}
					window._DOMCLEvents = null;
				}
				// IE
				if(window.ActiveXObject) {
					document.write('<scr'+'ipt id=__ie_onload defer src=' + ( window.location.protocol == 'https' ? 'https://0' : 'javascript:void(0)' ) + '><\/scr'+'ipt>');
					window._DOMScriptElement = document.all['__ie_onload'];
					window._DOMScriptElement.onreadystatechange = function() {
						  if (this.readyState == 'complete') {
							   _DOMCLFn(); // call the onload handle
							   window._DOMScriptElement.onreadystatechange	= null;
							   window._DOMScriptElement 					= null;
						  }
					  };
				}
				// Safari 
				else if( document.childNodes && !document.all && !navigator.taintEnabled ) {
						 window._DOMCLTimer =  setInterval(function() {				
							if (/loaded|complete/.test(document.readyState)) {
								_DOMCLFn(); // call the onload handler
							}}, 50);
				} else  {
					window.onload = _DOMCLFn;
				}
			}
			window._DOMCLEvents.push(fn);
		} else {
			window.addEventListener( 'DOMContentLoaded', fn, false);		
		}
	}
	







function admanEventAdd ( node, type, fn ) {
	if(node.attachEvent){
		// Scope fixing
		if( !node.__ieEventHandlers )
			node.__ieEventHandlers = [];
		var handler = { fn : fn, efn : fn.bind(node) };
		node.__ieEventHandlers.push(  handler );
		node.attachEvent( "on" + type, handler.efn );

	} else if(node.addEventListener){
		node.addEventListener(type, fn, false); 
	} else if(typeof node["on" + type] == "function"){
		var fOld = node[ "on" + type];
		node["on"  + type] = function(e){ fOld(e); fn(e); };
	} else {
		node[type] = fn;
	};
}


/* Browser checkup */
if(typeof isArray === 'undefined')  {
	isArray = function(obj) {
		return obj.constructor && obj.constructor === Array;
	}
}


if (typeof $A == "undefined" ){
function $A( args )			{
	if (!args ) 
		return []; 
		
	// Is it a string?
	if (args.toArray) {
		return args.toArray();
	}
	else {
		var results = [];
		for (var i = 0; i < args.length; i++){				
			results.push(args[i]);
		}
	}

	// Object
	if (results.length == 0 && args.length != 0 && !isArray(args) ) { 
		var results = [];
		for( var i in args ) {
			results.push(args[i]);
		}
	}
    return results;
}
}

if( !Function.prototype.bind)  {
	Function.prototype.bind = function() {
		var __method = this;
		var args = $A(arguments);
		var object = args.shift();
		return function() {
			// FIXME: is this wrong?
			return __method.apply(object, args.concat($A(arguments)));
		//	return __method.apply(object, args );
		}
	}
}









if (flash_tag == null || flash_tag == "") flash_tag = "go";

if (typeof(adman_flash_mode)	== "undefined" || adman_flash_mode == "" )
	adman_flash_mode = "opaque";
	
if (typeof(flash_uncache) == "undefined" || flash_uncache != true) flash_uncache =  false;

if (typeof(admanFlashVars) == "undefined") admanFlashVars = ""; 

if(typeof(adman_skip_wmode) === 'undefined') {
	adman_skip_wmode  = false;
}

/* Define random Seed to be used in ids */
admanDate		= new Date();
admanRandom		= admanDate.getHours()+admanDate.getSeconds();
admanRandom 	= admanRandom+ "_"+Math.round((Math.random()*100));
admanRandom		= admanRandom.toString();		


if (flash_uncache == true)
	flash_click = flash_click + "&rnd=" + escape(admanRandom);




var i = 0;
//alert( adman_flash_version );

// hack
//admanFlashClsid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
//admanFlashCodebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,67";
//if( adman_flash_version > 7  ) {
	admanFlashClsid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000";
	admanFlashCodebase = "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0";
//}


//_addStyle = " style=\"visibility: visible;\" ";
var _addStyle = "";
var _isIE = document.all ? true : false;
if ( _isIE ) {
//	_addStyle = " style=\"display: none;\"";
//	_addStyle = " style=\"position: relative; z-index: 1;\"";
}
 


admanHTML  = "<object style=\"visibility: visible;\" " + _addStyle + " class=\"adman-banner\" classid=\""+admanFlashClsid+"\" id=\"fscommand\" width=\""+flash_width+"\" height=\""+flash_height+"\" >";
admanHTML += "<param name=\"movie\" value=\""+flash_src+"?"+flash_tag+"="+escape(flash_click)+"\">";
//admanHTML += "<param name=\"menu\" value=\"false\">";
//admanHTML += "<param name=\"play\" value=\"true\">";
admanHTML += "<param name=\"allowScriptAccess\" value=\"always\">";
admanHTML += "<param name=\"quality\" value=\"high\">";
admanHTML += "<param name=\"bgcolor\" value=\"#\">";
admanHTML += "<param name=\"flashvars\" value=\""+admanFlashVars+"\">";

if(adman_flash_base){
admanHTML += "<param name=\"base\" value=\""+adman_flash_base+"\">";
}
//if (adman_flash_mode != "")

if(!adman_skip_wmode) 
admanHTML += "<param name=\"wmode\" value=\""+adman_flash_mode+"\">";

admanHTML += "<embed " + (adman_flash_base ? " base=\""+adman_flash_base+"\"" : "") + " style=\"visibility: visible;\" allowScriptAccess=\"always\" play=\"true\" flashvars=\""+admanFlashVars+"\" quality=\"high\" src=\""+flash_src+"?"+escape(flash_tag)+"="+flash_click+"\" quality=\"high\"  " + (!adman_skip_wmode ? " wmode=\""+adman_flash_mode+"\"" : "") + " width=\""+flash_width+"\" height=\""+flash_height+"\" TYPE=\"application/x-shockwave-flash\" pluginspace=\"http://www.macromedia.com/shockwave/download/index.cgi P1_Prod_Version=ShockwaveFlash\"></embed>";
admanHTML += "</object>";





//if(!window.flashData) {
//	window.flashData = {};
//}
//window.flashData[flash_src] = {
//	'flash_container' : flash_container,
//	'admanHTML'			: admanHTML
//}

if(typeof adman_flash_container !== 'undefined') {
flash_container = adman_flash_container;
}

if( typeof flash_container != "undefined"  && ( flash_container = document.getElementById(flash_container) )  )  {
	//admanEventAdd(window, 'load', (function(cont, html) {
	//	cont.innerHTML = html;
;
	//}).bind(window, flash_container, admanHTML));


	window.onDOMContentLoaded((function(cont, html) {
			cont.innerHTML = html;
			// alert(html);
			// PNGFix.fix();
	}).bind(window, flash_container, admanHTML));


  
	/*

	admanEventAdd(window, 'load', function() { 

		
		if(console && console.log) {
			console.log(flash_container);
		}	
		flash_container.innerHTML = admanHTML;
		if(flash_onLoad) {
flash_onLoad();
}

	});
	*/
}
else {
	document.write ( admanHTML);
}