var ProgressController = {
	time		: 0,
	width		: 0,
	evenness	: 100,
	iterations	: 0,
	timer		: null,
	div			: null,
	window		: null,
	args		: null,
	endTime     : null,
	
	init: function(timeout)
	{
		this.time = timeout;
		this.div = document.getElementById("appdiv");
		this.width = parseInt(this.div.style.width.slice(0,3));
		var d = new Date();
		this.endTime = d.getTime() + this.time;
	},
	
	show: function()
	{
		var d = new Date();

		var newWidth = (this.endTime - d.getTime()) * 208 / this.time;

		if (d.getTime() > this.endTime) {
			newWidth = 208;
			clearInterval(this.timer);
			showFlash();
		}

		this.div.style.width = newWidth + "px";
	}
}


var isFlashLoaded = false;
function qwSWFLoaded(swfFile)
{
	isFlashLoaded = true;
}

function initAd () 
{
	// if banners present - init banners engine
	if (isAd) {
		showAd();
	}
	// otherwise show flash
	else {
		showFlash();
	}
}

function showAd()
{
	$('cFlash').style.display = 'none';
	$('cAdPlaceholder').style.display = '';
	
	ProgressController.init(adTimeOut);
	ProgressController.timer = setInterval("ProgressController.show()", ProgressController.evenness);
	ProgressController.show();            
}

function showFlash()
{
	isFlashCanPlay = true;
	flashStarter();

	$('cFlash').style.display = '';
	$('cAdPlaceholder').style.display = 'none';
}
	
function adGetMovieObject(movieName)
{
	  if (window.document[movieName]) 
	  {
		  return window.document[movieName];
	  }
	  if (navigator.appName.indexOf("Microsoft Internet")==-1)
	  {
		if (document.embeds && document.embeds[movieName])
		  return document.embeds[movieName]; 
	  }
	  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	  {
		return document.getElementById(movieName);
	  }

}
	
function adIsMoviesLoaded(objMovie) 
{
	return isFlashLoaded;
	/*
	if (typeof(objMovie) != "undefined") {
		 if (objMovie.nodeName == 'EMBED' && (objMovie.PercentLoaded == undefined || typeof(objMovie.PercentLoaded) != "function") ) {
			 return false;
		 }
		return objMovie.PercentLoaded();
	} else {
		return false;
	}*/
}

function flashStarter()
{
	// get our object
	var objMovie = adGetMovieObject('aDFlash');
	
   // alert( adIsMoviesLoaded(objMovie) );
	if ( adIsMoviesLoaded(objMovie) ) {
		//alert("Can play - starting object");
		objMovie.Play();
		return;
	}
	
	//alert("Cant play, waiting flash is loaded");
	setTimeout('flashStarter()', 1000);
}