//************************************
// Ed Klopfenstein
// Visual String, LLC
//
// Ad Rotator script
// September 10, 2005
//*************************************

var LADS = 3;
var LADTA = 2; 

var MADS = 3; 
var MADTA = 3;

var RADS = 3; 
var RADTA = 3; 

//*******************************************************
// OBJECT: Ads
// PURPOSE: Collection of Ads for a specific image; 
// PARAMETERS: 
//  AdTypeRef is the AdType integer that determines what that ad is. 
//  Identifier is the Ad ID within the HTML Page collection.
//  TotalAds is the total number of ads to be inserted 
//*******************************************************

function Ads(AdTypeRef, Identifier, TotalAds, RotateSpeed)
{
	this.AdsCollection = new Array(TotalAds);  
	
	//Parameters for the object. 
	this.AdType = AdTypeRef - 1; 
	this.ID = Identifier; 
	this.Count = TotalAds; 
	this.CurrentAd = null;
	this.RotateSeconds = RotateSpeed * 1000; 
	
	
	//Main call for the object.
	this.BuildAds = CallBuildAds; 
	this.RotateImages = CallChangeImage; 
}

function Ad(ImageSource, ImageLink, AdType, Alt, AdID)
{
	this.Dim = new Dimension(AdType); 
	this.Image = new Image(this.Dim.W, this.Dim.H);
	this.Image.src = ImageSource; 
	this.Image.alt = Alt;
	this.Link = ImageLink; 
	this.AdID = AdID;
}

//These values are switched out during the document write operation.
function CallBuildAds()
{
	var AdArray = new Array(this.Count);  
	
	switch(this.AdType)
	{
		case 0: 
					AdArray[0] = new Ad("Images/front/121007_Gambling_L.jpg", "/sections/ResponsibleGaming/Default.aspx?Page=Whatyoushouldknow", this.AdType, "Internet Gambling", 234);
		AdArray[1] = new Ad("Images/front/122807_Alert_L.jpg", "/sections/ResponsibleGaming/Default.aspx?Page=ConsumerProtection", this.AdType, "Consumer Alert", 245);

			break;
		case 1: 
					AdArray[0] = new Ad("Images/front/11.10.09_tile.jpg", "http://72.233.102.132:82/sections/LotteryGames/Scratch.aspx?Page=Numbers", this.AdType, "11.10.09 Scratch Update", 415);
		AdArray[1] = new Ad("Images/front/145x88H5Bigger.jpg", "/sections/WinnersGallery/WinnersGallery.aspx?Page=Profile&MetaGame=41&WinnersGalleryID=33590", this.AdType, "William Bigger", 416);
		AdArray[2] = new Ad("Images/front/145x88MMEzra.jpg", "/sections/WinnersGallery/WinnersGallery.aspx?Page=Profile&MetaGame=39&WinnersGalleryID=33615", this.AdType, "Debra Ezra", 417);

			break;
		case 2: 
					AdArray[0] = new Ad("Images/front/145x88SWspot.jpg", "/sections/Events/Default.aspx#Safeway", this.AdType, "Safeway Free Groceries!", 414);
		AdArray[1] = new Ad("Images/front/145x88ZIPCorrectionTile.jpg", "/docs/pdfs/Seahawks%20Miami%20Rules.pdf", this.AdType, "ATTENTION: ZIP CODE CORRECTION!", 393);
		AdArray[2] = new Ad("Images/front/145x88dog.jpg", "/sections/PressRoom/Default.aspx?Page=Advertising", this.AdType, "View \"Dog\" T.V. Spot Here!", 380);

			break;
	}
	this.AdsCollection = AdArray;  
}


//*******************************************************
//
// OBJECT: Dimension
// Param: H, W
//
//*******************************************************
function Dimension(AdType)
{
	var Height = 0; 
	var Width = 0; 
	
	switch (AdType)
	{
		case 1: 
			Height = 88;
			Width = 145; 
			break;
		case 2: 
			Height = 87; 
			Width = 177;
			break; 
		case 3: 
			Height = 87; 
			Width = 177;
			break; 
		default: 
			Height = 87; 
			Width = 177;
			break; 
	}
	
	this.H = Height; 
	this.W = Width;
	
}

//Switches the image in the object. 
function CallChangeImage()
{
	if (document.images[this.ID])
	{
		this.CurrentAd = (this.CurrentAd == null)?0:CallRotateCounter(this.CurrentAd, this.Count); 
		document.images[this.ID].src = this.AdsCollection[this.CurrentAd].Image.src; 
		document.getElementById(this.ID).alt = this.AdsCollection[this.CurrentAd].Image.alt;
		thisTimer = setTimeout("ReplaceImage(" + this.AdType + ")", this.RotateSeconds);; 
	}
}

//Handles the counter change.
function CallRotateCounter(Counter, MaxCount)
{
	Counter++; 
	if (Counter == (MaxCount )) 
		Counter = 0; 
	
	return Counter; 
}


//Handles the URL switch
function Jump(Type)
{
	var adRedirect = 'AdRedirect.aspx?AdID=';

	switch(Type)
	{
		case 0: document.location.href = adRedirect + AdLeft.AdsCollection[AdLeft.CurrentAd].AdID; break;
		case 1: document.location.href = adRedirect + AdMiddle.AdsCollection[AdMiddle.CurrentAd].AdID; break;
		case 2: document.location.href = adRedirect + AdRight.AdsCollection[AdRight.CurrentAd].AdID; break;
	}
}


function ReplaceImage(Type)
{
	switch(Type)
	{
		case 0: return AdLeft.RotateImages(); 
		case 1: return AdMiddle.RotateImages(); 
		case 2: return AdRight.RotateImages();
	}
}

var AdLeft = new Ads(1, "AdLeft", LADTA, LADS); 
var AdMiddle = new Ads(2, "AdMiddle", MADTA, MADS);
var AdRight = new Ads(3, "AdRight", RADTA, RADS);  

function loadpage() {

	browver= parseInt(navigator.appVersion);
	browtype = navigator.appName;
	
	browsertype = (browtype == "Netscape" && !(browver < 3) 
					|| browtype == "Microsoft Internet Explorer" && !(browver < 4)) ? "new" : "old"; 

	if (browsertype == "new") 
	{
		//Load the left object list; 
		AdLeft.BuildAds(); 
		AdLeft.RotateImages(); 
		
		if (document.images.AdMiddle != null)
		{
			AdMiddle.BuildAds(); 
			AdMiddle.RotateImages();  
		}
		
		AdRight.BuildAds(); 
		AdRight.RotateImages(); 
	}
}