/* adlogic.js © 2010 Black List Software */

var i = 0;
var timeID;
var toggle = 1;
var idArray = new Array ("ad01", "ad02", "ad03");
var imgArray = new Array ("img/ad01.bmp", "img/ad02.bmp", "img/ad03.bmp"); 
var mapArray = new Array ("#ad01", "#ad02", "#ad03");

function adTimer(state, delay)
{
	switch(state)
	{
		case 0: //off
			clearInterval(timeID);
		break;
		case 1: //on
			timeID = setInterval("runAd()", delay);
		break;
	}
} 

function runAd()
{
	switch(toggle)
	{
		case 0: //on
			document.getElementById('magic').innerHTML = "<div id='" + idArray[i] + "' onmouseover='stopAd()' onmouseout='startAd(5000)'  style='width:486px;height:262px;'><img src=\"" + imgArray[i] + "\" width='486' height='262' usemap='" + mapArray[i] + "' border='0'></div>";
			fadeAd(document.getElementById(idArray[i]),0);
			stopAd();
			startAd(5000);
			toggle = 1;
		break;
		case 1: //off
			fadeAd(document.getElementById(idArray[i]),1);
			stopAd();
			startAd(320);
			toggle = 0;
			i+=1;
			if(i>=3) {i=0;}
		break;
	}
}

function startAd(delay)
{
	adTimer(1, delay);
}

function stopAd()
{
	adTimer(0);
}

function fadeAd(id, state)
{
	switch(state)
	{
		case 0: //in
			fadeIn(id);
		break;
		case 1: //out
			fadeOut(id);
		break;
	}
}

function loadAd(index)
{
	stopAd();
	document.getElementById('magic').innerHTML = "<div id='" + idArray[index] + "' onmouseover='stopAd()' onmouseout='startAd(5000)'  style='width:486px;height:262px;'><img src=\"" + imgArray[index] + "\" width='486' height='262' usemap='" + mapArray[index] + "' border='0'></div>";
	i=index;
	startAd(5000);
}

function initAd()
{
	document.getElementById('magic').innerHTML = "<div id='ad01' onmouseover='stopAd()' onmouseout='startAd(5000)' style='width:486px;height:262px;'><img src=\"img/ad01.bmp\" width='486' height='262' usemap='#ad01' border='0'></div>";
	fadeAd(document.getElementById("ad01"),0);
	startAd(5000);
}