﻿//************************************
// Ed Klopfenstein
// Visual String, LLC
//
// Ad Rotator script
// September 10, 2005
//*************************************

var LADS = 4;
var LADTA = 10;





//*******************************************************
// 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 = 0; 
    this.RotateSeconds = RotateSpeed * 500;


    //Main call for the object.
    this.BuildAds = CallBuildAds;
    this.RotateImages = CallChangeImage;
}

function Ad(ImageSource, ImageLink, AdType) {
    this.Dim = new Dimension(AdType);
    this.Image = new Image(this.Dim.W, this.Dim.H);
    this.Image.src = ImageSource;
    this.Link = ImageLink;
}

//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("UserFiles/Image/FrontPage/SuccessStories1.jpg", "/SuccessStories.aspx", this.AdType);
            AdArray[1] = new Ad("UserFiles/Image/FrontPage/SuccessStories2.jpg", "/AdvisoryServices.aspx", this.AdType);
            AdArray[2] = new Ad("UserFiles/Image/FrontPage/SuccessStories3.jpg", "/Marketing.aspx", this.AdType);
            AdArray[3] = new Ad("UserFiles/Image/FrontPage/SuccessStories4.jpg", "/InvestmentServices.aspx", this.AdType);
			AdArray[4] = new Ad("UserFiles/Image/FrontPage/SuccessStories5.jpg", "/EconomicPlanning.aspx", this.AdType);
			AdArray[5] = new Ad("UserFiles/Image/FrontPage/SuccessStories6.jpg", "/SuccessStories.aspx#2", this.AdType);
            AdArray[6] = new Ad("UserFiles/Image/FrontPage/SuccessStories7.jpg", "/AdvisoryServices.aspx#2", this.AdType);
            AdArray[7] = new Ad("UserFiles/Image/FrontPage/SuccessStories8.jpg", "/Marketing.aspx#2", this.AdType);
            AdArray[8] = new Ad("UserFiles/Image/FrontPage/SuccessStories9.jpg", "/InvestmentServices.aspx#2", this.AdType);
			AdArray[9] = new Ad("UserFiles/Image/FrontPage/SuccessStories10.jpg", "/EconomicPlanning.aspx#2", this.AdType);

            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;
       
        default:
            Height = 87;
            Width = 177;
            break;
    }

    this.H = Height;
    this.W = Width;

}

//Switches the image in the object. 
function CallChangeImage() {
    this.CurrentAd = (this.CurrentAd == null) ? 0 : CallRotateCounter(this.CurrentAd, this.Count);
    document.images[this.ID].src = this.AdsCollection[this.CurrentAd].Image.src;
    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) {
    switch (Type) {
        case 0: document.location.href = AdLeft.AdsCollection[AdLeft.CurrentAd].Link; break;
       
    }
}


function ReplaceImage(Type) {
    switch (Type) {
        case 0: return AdLeft.RotateImages();
       
    }
}

var AdLeft = new Ads(1, "LeftAd", LADTA, LADS);


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();

       
    }
}