/**
 * @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:"../images/banners/468x60-FreeBanner.gif",
		landingPage:"http://www.moonbingo.com/main.php?a=6848.0",
		trackingId:"128"
	},
	{
		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_024629 ",
		trackingId:"74"
	},
	{
		image:"http://affiliates.virtueaffiliates.com/processing/impressions.asp?btag=a_74b_618",
		landingPage:"http://affiliates.virtueaffiliates.com/processing/clickthrgh.asp?btag=a_74b_609",
		trackingId:"697"
	},
	{
		image:"../images/banners/jan25.gif",
		landingPage:"http://affiliates.virtueaffiliates.com/processing/clickthrgh.asp?btag=a_74b_251",
		trackingId:"276"
	},
	{
		image:"http://affiliate.joyofbingo.com/banners/8/wink037.gif",
		landingPage:"http://affiliate.joyofbingo.com/jobredirector.aspx?aid=537&sid=1",
		trackingId:"162"
	},
	{
		image:"../bingo-news/news-banner_468.gif",
		landingPage:"../bingo-reviews/review-of-freebingohunter-bingo.jsp",
		trackingId:"60"
	
	}
)



//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();
	//look to see if there is any other method in the page listening for the onload event named extraOnLoad
	var foundExtra = true;
	try{
		var myFunction = extraOnLoad;
	}catch(err){
		foundExtra = false;
	}
	if(foundExtra){
		extraOnLoad();
	}
}
//cycle the banner
function rotateTopBanner(){
	var myObj = banners[bannerIndex];
	var srcUrl = myObj.image;
	var theHTML = '<a 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();
}
