var count = 0;
var index1 = 0;
var index2 = 0;
var tabClick = false;
var tabChosen, noticeImage, noticeLink;
var resultsTable;
var currentLottoImg = "url('img/results_lotto.png?seed=" + new Date() + "')";
var currentSuperImg = "url('img/results_super5.png?seed=" + new Date() + "')";
var currentKenoImg = "url('img/results_keno.png?seed=" + new Date() + "')";
var currentScratchersImg = "url('img/results_second.png?seed=" + new Date() + "')";
var currentBingoImg = "url('img/results_bingo.png?seed=" + new Date() + "')";
var currentUbetImg;
var currentHRImg;

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

function incrementCounter()
{
	count++;
	if (count > 60)
	{
		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/ubet.png";
		noticeLink.href = "http://www.maltco.com/ubet/";
	}
	else (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()
{
	var now = new Date();
	var day = now.getDay();
	var month = now.getMonth() + 1;
	var hours = now.getHours();
	var minutes = Math.floor(now.getMinutes() / 5) * 5;
	var nowStr = now.getDate() + "-" + month + "-" + now.getFullYear() + "_" + hours + minutes;

	if (index1 == 0)
	{
		if ((day == 6) && (hours == 19))
			noticeImage.src = "img/qjackpot.png?seed=" + nowStr;
		else noticeImage.src = "img/qjackpot.png";
			noticeLink.href =  "http://www.maltco.com/lotto/";
	}
	else if (index1 == 1)
	{
		if ((hours >= 7) && (hours < 23))
			noticeImage.src = "img/bingo_new_edition.png?seed=" + nowStr;
		else noticeImage.src = "img/bingo_new_edition.png";
			noticeLink.href =  "http://www.maltco.com/bingo75/";
	}
	else if (index1 == 2)
	{
		if ((day == 3) && (hours == 19))
			noticeImage.src = "img/jackpot_red.png?seed=" + nowStr;
		else noticeImage.src = "img/jackpot_red.png";
			noticeLink.href =  "http://www.maltco.com/super/";
	}
	else if (index1 == 3)
	{
		noticeImage.src = "img/gbi_hr.png";
		noticeLink.href =  "http://www.maltco.com/ubet_gb_ir_hr/";
	}
	else if (index1 == 4)
	{
		if ((day == 3) && (hours == 19))
			noticeImage.src = "img/jackpot_blue.png?seed=" + nowStr;
		else noticeImage.src = "img/jackpot_blue.png";
		noticeLink.href =  "http://www.maltco.com/super/";
	}
	else if (index1 == 5)
	{
		noticeImage.src = "img/arani.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/s5sixnumbers.png";
		noticeLink.href =  "http://www.maltco.com/super/";
	}
	else if (index1 == 8)
	{
		noticeImage.src = "img/pinball.png";
		noticeLink.href =  "http://www.maltco.com/scratchers/choose.htm";
	}
	else if (index1 == 9)
	{
		//noticeImage.src = "img/gbi_hr.png";
		//noticeLink.href = "http://www.maltco.com/ubet_gb_ir_hr/";
		noticeImage.src = "img/ubet.png";
		noticeLink.href = "http://www.maltco.com/ubet/";
	}
	else if (index1 == 10)
	{
		noticeImage.src = "img/keno_comp.png";
		noticeLink.href =  "http://www.maltco.com/keno/terms.htm";
	}
	else if (index1 == 11)
	{
		noticeImage.src = "img/crazy_dice.png";
		noticeLink.href =  "http://www.maltco.com/scratchers/choose.htm";
	}

}

function chooseRandomBanner()
{
	var randNum = Math.floor(Math.random()*40);
	if (randNum < 5) index1 = 0; //QUATERNO
	else if (randNum < 8) index1 = 1; //BINGO75
	else if (randNum < 10) index1 = 4; //SUPER 5 JACKPOT BLUE
	else if (randNum < 15) index1 = 8; //U*BET BIG MATCH OR BINGO75
	else if (randNum < 20) index1 = 2; //SUPER 5 JACKPOT RED
	else if (randNum == 20) index1 = 3; //KENO COMPETITION
	else if (randNum == 21) index1 = 5; //KENO COMPETITION
	else if (randNum == 22) index1 = 6; //KENO COMPETITION
	else if (randNum == 23) index1 = 7; //KENO COMPETITION
	else if (randNum == 24) index1 = 9; //KENO COMPETITION
	else if (randNum < 30) index1 = 10; //BINGO75
	else if (randNum < 35) index1 = 11; //SUPER 5 SIX NUMBERS	
	
	setBanner();
}

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

	if (!tabClick)
	{
		if ((count % 15) == 0)
		{
			var now = new Date();
			var day = now.getDay();
			var hours = now.getHours();
			var minutes = now.getMinutes();

			if (index2 > 3)
				index2 = 0;
				
			if (index2 == 0)
			{
				if ((day == 6) && (hours == 19) && (minutes > 30)) //after lotto draw
					lottoTabClicked(true);
				else lottoTabClicked(false);
			}
			else if (index2 == 1)
			{
				if ((day == 3) && (hours == 19) && (minutes > 30)) //after super5 draw
					super5TabClicked(true);
				else super5TabClicked(false);
			}
			else if (index2 == 2)
			{
				if ((hours >= 7) && (hours < 23))
					kenoTabClicked(true);
				else kenoTabClicked(false);
			}
			else
			{
				if ((hours == 18) && (minutes > 30))
					bingoTabClicked(true);
				else bingoTabClicked(false);
			}
	
			index2++;
		}
	}
	else
	{
		if ((count % 60) == 0)
		{
			var now = new Date();
			var day = now.getDay();
			var hours = now.getHours();
			var minutes = now.getMinutes();

			if (tabChosen == 0)
			{
				if ((day == 6) && (hours == 19) && (minutes > 30)) //after lotto draw
					lottoTabClicked(true);
				else lottoTabClicked(false);
			}
			else if (tabChosen == 1)
			{
				if ((day == 3) && (hours == 19) && (minutes > 30))//after super5 draw
					super5TabClicked(true);
				else super5TabClicked(false);
			}
			else if (tabChosen == 2)
			{
				if ((hours >= 7) && (hours < 23))
					kenoTabClicked(true);
				else kenoTabClicked(false);
			}
			else if (tabChosen == 3)
			{
				if (((day == 4) || (day == 5)) && (hours > 10) && (hours < 12))
					scratchersTabClicked(true);
				else scratchersTabClicked(false);
			}
			else if (tabChosen == 4)
			{
				ubetTabClicked(false);
			}
			else if (tabChosen == 5)
			{
				if ((hours == 18) && (minutes > 30))
					bingoTabClicked(true);
				else bingoTabClicked(false);
			}
		}
	}
	
	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(true);
		}
		else lottoTabClicked(true);
	}
	else //Thu to Sat
	{
		if ((day == 6) && (hours >= 20)) //Sat after 8pm
		{
			lottoTabClicked(true);
		}
		else super5TabClicked(true);
	}
}

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


}

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

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

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

function ubetTabClicked(refreshed)
{
	/* Doesn't need to be refreshed
	tabChosen = 4;
	if (refreshed)
	{
		currentUbetImg = "url('img/results_ubet.png?seed=" + new Date() + "')";
	}
	resultsTable.style.background = currentUbetImg;
	*/
	resultsTable.style.background = "url('img/results_ubet.png')";
}

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

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

}


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","img/video8.swf","img/video9.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");
}
