/**
 * @author tomgooding
 */
//the frequency (in ms) of how often the top banner is rotated

var topBannerRotationFrequency = 25000;
function getLottoImgUrl(){
	return  'http://impgb.tradedoubler.com/imp?type(img)g(16798578)a(1573575)' + new String (Math.random()).substring (2, 11);
}

// details of all the banners to be shown in rotation on every page
var banners = new Array(
	{
		image:"http://ads.meccabingo.com/media/201011081116_x-468x60.gif",
		landingPage:"http://ads.meccabingo.com/redirect.aspx?pid=90511&bid=1302",
		trackingId:"871"
	},
	{
		image:"http://imstore.bet365affiliates.com/?AffiliateCode=365_028940&CID=149&DID=5&TID=1&PID=136&LNG=1",
		landingPage:"http://bingo.bet365.com?affiliate=365_065835",
		trackingId:"863"
	},
	{
		image:"http://affiliates.market-ace.com/processing/impressions.asp?btag=a_20942b_8545",
		landingPage:"http://affiliates.market-ace.com/processing/clickthrgh.asp?btag=a_20942b_8458",
		trackingId:"867"
	},
	{
		image:"http://affiliates.market-ace.com/processing/impressions.asp?btag=a_20942b_8063",
		landingPage:"http://affiliates.market-ace.com/processing/clickthrgh.asp?btag=a_20942b_7993",
		trackingId:"868"
	},
	{
		image:"http://media.paddypower.com/media/468x60_bingosignup.gif",
		landingPage:"http://media.paddypower.com/redirect.aspx?pid=10061090&bid=2325",
		trackingId:"872"
	}
)



//randomise the list of banners
shuffleArray(banners);
//set the initial index of the banner to choose
var bannerIndex = 0;
//method for randomisation of list of banners
function shuffleArray ( myArray ) {
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}
//when the window is ready - start the rotation
window.onload = function(){
	startRotateBanner();
}
//cycle the banner
function rotateTopBanner(){
	var myObj = banners[bannerIndex];
	var srcUrl = myObj.image;
	//<a href="#" id="banner1" ><img src="/images/temp/banner1.png" alt="" /></a>
	var theHTML = '<a id="banner1" href="' + myObj.landingPage + '" target="_blank" onclick="topBannerClicked(' + bannerIndex  + ')" > <img src="' + srcUrl +'" /> </a>';
	 document.getElementById("topbanner").innerHTML = theHTML;
	 bannerIndex ++;
	 if(bannerIndex == banners.length){
	 	bannerIndex = 0;
	 }
	 setTimeout("rotateTopBanner()",topBannerRotationFrequency);
}
//handle the tracking for the click
function topBannerClicked(arg) {
	//alert("topBannerClicked(" + arg + ")");
	var linkTrackingId = banners[arg].trackingId;
	var siteId = topBannerReportingSiteId;
	var serviceUrl = topBannerReportingUrl; 
	linkVisited(linkTrackingId,serviceUrl,siteId);
}
//start the rotation
function startRotateBanner(){
	rotateTopBanner();
}

