/**
 * @author tomgooding
 */
//the frequency (in ms) of how often the top banner is rotated

var topBannerRotationFrequency = 10000;
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://www.polobingo.com/skin/_affiliatebanners/POL/gif/468X60/01.gif",
		landingPage:"http://affiliates.unitedbingo.co.uk/processing/clickthrgh.asp?btag=a_563b_15",
		trackingId:"799"
	},
	{
		image:"http://affiliates.unitedbingo.co.uk/processing/impressions.asp?btag=a_563b_348",
		landingPage:"http://affiliates.unitedbingo.co.uk/processing/clickthrgh.asp?btag=a_563b_290",
		trackingId:"1035"
	},
	{
		image:"../images/banners/top-banner/sing_10free_468x60.gif",
		landingPage:"http://ads.ignitegambling.com/linkadverts/1474/7a930fad-dd08-43cd-8136-6d5165c79b5e",
		trackingId:"829"
	},
	{
		image:"../images/banners/top-banner/hippo_5free_468x60.gif",
		landingPage:"http://www.hippobingo.com/specialoffer.php?a=10855.0",
		trackingId:"918"
	},
	{
		image:"../images/banners/top-banner/fancy_5free_468x60.gif",
		landingPage:"http://ads.ignitegambling.com/linkadverts/3300/7a930fad-dd08-43cd-8136-6d5165c79b5e",
		trackingId:"888"
	},
	{
		image:"../images/banners/top-banner/gossip_spin_468x60.gif",
		landingPage:"http://affiliates.unitedbingo.co.uk/processing/clickthrgh.asp?btag=a_563b_16",
		trackingId:"836"
	},
	{
		image:"../images/banners/top-banner/fabulous_5free_468x60.gif",
		landingPage:"http://affiliates.market-ace.com/processing/clickthrgh.asp?btag=a_17835b_9779",
		trackingId:"1015"
	},
	{
		image:"../images/banners/top-banner/city_300_468x60.gif",
		landingPage:"http://ads.ignitegambling.com/click/TyZBYdigRBHtgV4hXe8kjkBT3d2Lcpo5wwu5WpBVL8o%3d",
		trackingId:"852"
	},
	{
		image:"../images/banners/top-banner/bet365_468x60.gif",
		landingPage:"http://bingo.bet365.com?affiliate=365_024629",
		trackingId:"74"
	},
	{
		image:"http://affiliates.galacoral.com/processing/impressions.asp?btag=a_589b_67",
		landingPage:"http://affiliates.galacoral.com/processing/clickthrgh.asp?btag=a_589b_1552",
		trackingId:"90"
	},
	{
		image:"http://www.moonbingo.com/skin/_affiliatebanners/MBI/gif/468X60/MBI01.gif",
		landingPage:"http://affiliates.unitedbingo.co.uk/processing/clickthrgh.asp?btag=a_563b_14",
		trackingId:"128"
	},
	{
		image:"../images/banners/top-banner/xbingo_spin_468x60.gif",
		landingPage:"http://www.xbingo.com/?tid=b39710a4-2587-4deb-8dbb-160e1c5a93cf",
		trackingId:"1020"
	},
	{
		image:"../images/banners/wonder-bingo/wonder300_468x60.gif",
		landingPage:"http://afs.wonderaffiliates.com/afs/come.php?id=81&cid=1064&ctgid=4&atype=1",
		trackingId:"1020"
	},
	{
		image:"../images/banners/paddy-power/paddy25_468x60.gif",
		landingPage:"http://bingo.paddypower.com/exclusive25?AFF_ID=10064317",
		trackingId:"1020"
	}
	
	
	
	
)



//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();
}

