var count = 0;
var index1 = 0;
var index2 = 0;
var tabClick = false;
var tabChosen, noticeImage, noticeLink;
var resultsTable;

function initializeFields()
{
	resultsTable = document.getElementById('resultsTable');
	noticeImage = document.getElementById('noticeImage');
	noticeLink = document.getElementById('noticeLink');
}

function incrementCounter()
{
	count++;
	if (count > 30)
	{
		count = 1;
	}
}

/*function setBanner()
{
	if (index1 == 0)
	{
		noticeImage.src = "img/dond.png";
		noticeLink.href =  "http://www.maltco.com/keno/terms.htm";
	}
	else if (index1 == 1)
	{
		noticeImage.src = "img/jackpot_blue.png?seed=" + new Date();//"img/jackpot_blue.png";
		noticeLink.href =  "http://www.maltco.com/super/";
	}
	else if (index1 == 2)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else if (index1 == 3)
	{
		noticeImage.src = "img/blackjack.gif";
		noticeLink.href =  "http://www.maltco.com/scratchers/blackjack/blackjack.php";		
	}
	else if (index1 == 4)
	{
		noticeImage.src = "img/jackpot_red.png?seed=" + new Date();//"img/jackpot_red.png";
		noticeLink.href =  "http://www.maltco.com/super/";
	}
	else if (index1 == 5)
	{
		noticeImage.src = "img/cashword.gif";
		noticeLink.href =  "http://www.maltco.com/scratchers/choose.htm";
	}
	else if (index1 == 6)
	{
		noticeImage.src = "img/vegas.png";
		noticeLink.href =  "http://www.maltco.com/scratchers/vegas/vegas.html";
	}
	else if (index1 == 7)
	{
		noticeImage.src = "img/poker.png";
		noticeLink.href =  "http://www.maltco.com/scratchers/choose.htm";
	}
	//else if (index1 == 8)
	//{
	//	noticeImage.src = "img/bigmatch.png";
	//	noticeLink.href = "http://www.maltco.com/ubet/";
	//}
	else if (index1 == 9)
	{
		noticeImage.src = "img/divided.png";
		noticeLink.href = "http://www.maltco.com/scratchers/divided.htm";
	}
	//else if (index1 == 10)
	//{
	//	noticeImage.src = "img/bingo.png";
	//	noticeLink.href =  "http://www.maltco.com/bingo75/";
	//}
	else
	{
		noticeImage.src = "img/bingo.png";
		noticeLink.href =  "http://www.maltco.com/bingo75/";
	}
}*/

function setBanner()
{
	if (index1 == 0)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else if (index1 == 1)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else if (index1 == 2)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else if (index1 == 3)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";	
	}
	else if (index1 == 4)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else if (index1 == 5)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else if (index1 == 6)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else if (index1 == 7)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else if (index1 == 8)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else if (index1 == 9)
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else
	{
		noticeImage.src = "img/qjackpot.png";
		noticeLink.href =  "http://www.maltco.com/lotto/";
	}
}

function chooseRandomBanner()
{
	var randNum = Math.floor(Math.random()*30);
	if (randNum < 5) index1 = 0; //KENO DOND
	else if (randNum < 8) index1 = 1; //JACKPOT BLUE
	else if (randNum < 10) index1 = 4; //JACKPOT RED
	else if (randNum < 15) index1 = 8; //BIG MATCH
	else if (randNum < 20) index1 = 2; //LOTTO
	else if (randNum == 20) index1 = 3; //SCRATCHERS 1
	else if (randNum == 21) index1 = 5; //SCRATCHERS 2
	else if (randNum == 22) index1 = 6; //SCRATCHERS 3
	else if (randNum == 23) index1 = 7; //SCRATCHERS 4
	else if (randNum == 24) index1 = 9; //SCRATCHERS 5 DIVIDED
	else if (randNum < 30) index1 = 10; //BINGO
	else index1 = 10; //BINGO
	
	setBanner();
}

function startTimer() 
{
	incrementCounter();
	
	if ((count % 11) == 0)
	{
		if (index1 > 10)
			index1 = 0;
		
		setBanner();
		
		index1++;
	}
	

	if (!tabClick)
	{
		if ((count % 10) == 0)
		{
			if (index2 > 3)
				index2 = 0;
				
			if (index2 == 0)
			{
				lottoTabClicked();
			}
			else if (index2 == 1)
			{
				super5TabClicked();
			}
			else if (index2 == 2)
			{
				kenoTabClicked();
			}
			else
			{
				scratchersTabClicked();
			}
	
			index2++;
		}
	}
	else
	{
		if ((count % 30) == 0)
		{
			if (tabChosen == 0)
			{
				lottoTabClicked();
			}
			else if (tabChosen == 1)
			{
				super5TabClicked();
			}
			else if (tabChosen == 2)
			{
				kenoTabClicked();
			}
			else if (tabChosen == 3)
			{
				scratchersTabClicked();
			}
			else if (tabChosen == 4)
			{
				ubetTabClicked();
			}
			else if (tabChosen == 5)
			{
				bingoTabClicked();
			}
		}
	}
	
	clearInterval(ref);
	start();
}

function start()
{
	ref = setInterval('startTimer()', 1000);
}

function chooseResultsTab()
{
	var now = new Date();
	var day = now.getDay();
	var hours = now.getHours();
	
	if ((day >= 0) && (day < 4)) //Sun to Wed
	{
		if ((day == 3) && (hours >= 20)) //Wed after 8pm
		{
			super5TabClicked();
		}
		else lottoTabClicked();
	}
	else //Thu to Sat
	{
		if ((day == 6) && (hours >= 20)) //Sat after 8pm
		{
			lottoTabClicked();
		}
		else super5TabClicked();
	}
}

function lottoTabClicked()
{
	tabChosen = 0;
	resultsTable.style.background = "url('img/results_lotto.png?seed=" + new Date() + "')";
}

function super5TabClicked()
{
	tabChosen = 1;
	resultsTable.style.background = "url('img/results_super5.png?seed=" + new Date() + "')";
}

function kenoTabClicked()
{	
	tabChosen = 2;
	resultsTable.style.background = "url('img/results_keno.png?seed=" + new Date() + "')";
}

function scratchersTabClicked()
{
	tabChosen = 3;
	resultsTable.style.background = "url('img/results_second.png?seed=" + new Date() + "')";
}

function ubetTabClicked()
{
	tabChosen = 4;
	resultsTable.style.background = "url('img/results_ubet.png?seed=" + new Date() + "')";
	
}

function hrTabClicked()
{
	tabChosen = 5;
	resultsTable.style.background = "url('img/results_hr.png?seed=" + new Date() + "')";
}

function bingoTabClicked()
{
	tabChosen = 5;
	resultsTable.style.background = "url('img/results_bingo.png?seed=" + new Date() + "')";
}


function checkResultsClick()
{
	if (tabChosen == 0)
	{
		window.open("http://www.maltco.com/lotto/results.php");
	}
	else if (tabChosen == 1)
	{
		window.open("http://www.maltco.com/super/results.php");
	}
	else if (tabChosen == 2)
	{
		window.open("http://www.maltco.com/keno/QuickKeno_Today_Results.php");
	}
	else if (tabChosen == 3)
	{
		window.open("http://www.maltco.com/ssecond/winners.php");
	}
	else if (tabChosen == 4)
	{
		window.open("http://www.maltco.com/ubet/Latest/results/results_longlist.pdf");
	}
	else if (tabChosen == 5)
	{
		//window.open("http://www02.atg.se/cm/english/results");
		window.open("http://www.maltco.com/bingo75/results.php");
	}
}

function showVideo()
{
	var urls = ["img/video1.swf","img/video2.swf","img/video3.swf","img/video4.swf","img/video5.swf","img/video6.swf","img/video7.swf"];

	var randNumber = Math.floor(Math.random() * urls.length);
	
	randNumber -= (randNumber == urls.length)?1:0;

	var randomFile = urls[randNumber];
	
	var fo = new FlashObject(randomFile, "video", "340", "200", "7", "#000000");
   	fo.addParam("allowScriptAccess", "sameDomain");
	fo.addParam("quality", "high");
	fo.addParam("allowFullScreen", "false");
   	//fo.addParam("wmode", "transparent");
	fo.addParam("menu", "false");
	fo.addParam("play","true");
	fo.useExpressInstall('lib/expressinstall.swf');
   	fo.write("flashcontent");
}

function showMenu()
{
	var fo = new FlashObject("lib/menu.swf", "menu", "626", "65", "7", "#0A5180");
	fo.addParam("allowScriptAccess", "sameDomain");
	fo.addParam("quality", "high");
	fo.addParam("allowFullScreen", "false");
   	fo.addParam("wmode", "transparent");
	fo.addParam("menu", "false");
	fo.useExpressInstall('lib/expressinstall.swf');
   	fo.write("menuflashcontent");
}
