﻿var thisBanner;
var prevBanner = -1;
// BANNER OBJECT
function Banner(objName)
{
    this.obj = objName;
    this.aNodes = [];
    this.currentBanner = 0;
};

// ADD NEW BANNER
Banner.prototype.add = function(bannerPath, bannerDuration, height, width, band) 
{
    this.aNodes[this.aNodes.length] = new Node(this.obj + "_" + this.aNodes.length, bannerPath, bannerDuration, height, width, band);
};

// Node object
function Node(name, bannerPath, bannerDuration, height, width, band)
{
    this.name = name;
    this.bannerPath = bannerPath;
    this.bannerDuration = bannerDuration;
    this.height = height
    this.width = width;
    this.band = band;
    //	alert (name + bannerPath +"|" + bannerDuration +"|" + height +"|" + width);
};

// Outputs the banner to the page
Banner.prototype.toString = function() {
    var str = ""
    for (var iCtr = 0; iCtr < this.aNodes.length; iCtr++) {
        str = str + '<span name="' + this.aNodes[iCtr].name + '" '
        str = str + 'id="' + this.aNodes[iCtr].name + '" ';
        str = str + 'class="BannerHide" ';
       
        str = str + 'align="center" ';
        str = str + 'valign="top" >\n';

        str = str + '<OBJECT '
        str = str + 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
        str = str + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '
        str = str + 'WIDTH="' + this.aNodes[iCtr].width + '" '
        str = str + 'HEIGHT="' + this.aNodes[iCtr].height + '" '
        str = str + 'id="bnr_' + this.aNodes[iCtr].name + '" '
        str = str + '>'
        str = str + '<PARAM NAME=movie VALUE="' + this.aNodes[iCtr].bannerPath + '">'
        str = str + '<PARAM NAME="wmode" VALUE="opaque" />'

        str = str + '<PARAM NAME=\"PLAY\" VALUE=\"true\">';
        if (this.aNodes[iCtr].band != 'True') 
        {
            str = str + '<PARAM NAME=\"LOOP\" VALUE=\"false\">';
        }
        str = str + '<PARAM NAME=\"QUALITY\" VALUE=\"high\">';
        str = str + '<PARAM NAME=\"PAUSE\" VALUE=\"false\">';

        str = str + '<EMBED ';
        str = str + 'WMODE="opaque" ';
        str = str + 'src="' + this.aNodes[iCtr].bannerPath + '" '

        str = str + 'PLAY=\"true\" ';
        if (this.aNodes[iCtr].band != 'True') 
        {
            str = str + 'LOOP=\"false\" ';
        }
        str = str + 'QUALITY=\"high\" PAUSE=\"false\" '

        str = str + 'WIDTH="' + this.aNodes[iCtr].width + '" '
        str = str + 'HEIGHT="' + this.aNodes[iCtr].height + '" '
        str = str + 'NAME="bnr_' + this.aNodes[iCtr].name + '" '
        str = str + 'TYPE="application/x-shockwave-flash" '
        str = str + 'PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'
        str = str + '</EMBED>'
        str = str + '</OBJECT>'

        str += '</span>';
    }
    return str;
};

// START THE BANNER ROTATION
Banner.prototype.start = function() 
{
    this.changeBanner();
    var thisBannerObj = this.obj;
    // CURRENT BANNER IS ALREADY INCREMENTED IN cahngeBanner() FUNCTION
    var count = 0;
    if (this.aNodes.length > 1) 
    {
        if (this.currentBanner == this.aNodes.length) 
        {
            count == 0;
        }
        if (this.currentBanner == 0) 
        {
            count = this.aNodes.length - 1;
        }
        else 
        {
            count--;
        }
    }
    setTimeout(thisBannerObj + ".start()", this.aNodes[this.currentBanner + count].bannerDuration * 1000);
}

// CHANGE BANNER
Banner.prototype.changeBanner = function() 
{
    thisBanner;
    prevBanner = -1;
    if (this.currentBanner < this.aNodes.length) 
    {
        thisBanner = this.currentBanner;
        if (this.aNodes.length > 1) 
        {
            if (thisBanner > 0) 
            {
                prevBanner = thisBanner - 1;
            }
            else 
            {
                prevBanner = this.aNodes.length - 1;
            }
        }
        if (this.currentBanner < this.aNodes.length - 1) 
        {
            this.currentBanner = this.currentBanner + 1;
        }
        else 
        {
            this.currentBanner = 0;
        }
    }

    if (navigator.appName == "Microsoft Internet Explorer") 
    {
        var ban = document.getElementById("bnr_" + this.aNodes[thisBanner].name);
        ban.Rewind();
        ban.Play();
    }
    document.getElementById(this.aNodes[thisBanner].name).className = "BannerShow";

    if (prevBanner >= 0) 
    {
        document.getElementById(this.aNodes[prevBanner].name).className = "BannerHide";
    }
}

