// BANNER OBJECT
function mBanner (objName) {
    //alert("new object");
    this.objName = objName;
	this.aNodes = [];
	this.currentBanner = 0;
	this.order = null;
};

// ADD NEW BANNER
mBanner.prototype.add = function(bannerType, bannerPath, bannerDuration, height, width, hyperlink) {
	this.aNodes[this.aNodes.length] = new mNode(this.objName +"_"+ this.aNodes.length, bannerType, bannerPath, bannerDuration, height, width, hyperlink);
};

// Node object
function mNode(name, bannerType, bannerPath, bannerDuration, height, width, hyperlink) {
	this.name = name;
	this.bannerType = bannerType;
	this.bannerPath = bannerPath;
	this.bannerDuration = bannerDuration;
	this.height = height
	this.width = width;
	this.hyperlink= hyperlink;
	//alert (name +"|" + bannerType +"|" + bannerPath +"|" + bannerDuration +"|" + height +"|" + width + "|" + hyperlink);
};

// Outputs the banner to the page
mBanner.prototype.toString = function() {
	var str = "";
	for (var iCtr=0; iCtr < this.aNodes.length; iCtr++){
		str += '<span name="'+this.aNodes[iCtr].name+'" '
		+  'id="'+this.aNodes[iCtr].name+'" '
		+  'class="m_banner_hide" '
		+  'bgcolor="#FFFCDA" '	// CHANGE BANNER COLOR HERE
		+  'align="center" '
		+  'valign="top" >\n';
		if (this.aNodes[iCtr].hyperlink != ""){
			str +=  '<a href="'+this.aNodes[iCtr].hyperlink+'">';
		}

		if ( this.aNodes[iCtr].bannerType == "FLASH" ){
			str +=  '<OBJECT '
			+  'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
			+  'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '
			+  'WIDTH="'+this.aNodes[iCtr].width+'" '
			+  'HEIGHT="'+this.aNodes[iCtr].height+'" '
			+  'id="bnr_'+this.aNodes[iCtr].name+'" '
			+  'ALIGN="" '
			+  'VIEWASTEXT>'
			+  '<PARAM NAME=movie VALUE="'+ this.aNodes[iCtr].bannerPath + '">'
			+  '<PARAM NAME=quality VALUE=high>'
			+  '<PARAM NAME=bgcolor VALUE=#FFFCDA>'
			+  '<EMBED ';
			+  'src="'+this.aNodes[iCtr].bannerPath+'" '
			+  'quality=high '
//			+  'bgcolor=#FFFCDA '
			+  'WIDTH="'+this.aNodes[iCtr].width+'" '
			+  'HEIGHT="'+this.aNodes[iCtr].height+'" '
			+  'NAME="bnr_'+this.aNodes[iCtr].name+'" '
			+  'ALIGN="center" '
			+  'TYPE="application/x-shockwave-flash" '
			+  'PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'
			+  '</EMBED>'
			+  '</OBJECT>'
		}else if ( this.aNodes[iCtr].bannerType == "IMAGE" ){
			str +=  '<img src="'+this.aNodes[iCtr].bannerPath+'" '
			+  'border="0" '
			+  'height="'+this.aNodes[iCtr].height+'" '
			+  'width="'+this.aNodes[iCtr].width+'">';
		}

		if (this.aNodes[iCtr].hyperlink != ""){
			str +=  '</a>';
		}

		str +=  '</span>';
	}
	return str;
};

// START THE BANNER ROTATION
mBanner.prototype.start = function () {
	this.changeBanner();
	var thisBannerObj = this.objName;
	// CURRENT BANNER IS ALREADY INCREMENTED IN cahngeBanner() FUNCTION
	setTimeout(thisBannerObj+".start()", this.aNodes[this.currentBanner].bannerDuration * 1000);
}


// CHANGE BANNER
mBanner.prototype.changeBanner = function(){
	var oldBanner=this.currentBanner
	if (!this.order) {
        this.order = new Array();
        var temp = 0;
        var orders = new Array();
        for (var i = 0; i < this.aNodes.length; i++) {
            do {
                temp = Math.round((this.aNodes.length-1)*Math.random())
            } while (orders[temp]);
            orders[temp] = true;
            this.order[i] = temp;
        }
        //alert(this.order);
    }
    if (this.currentBanner < this.order.length - 1) {
		this.currentBanner = this.currentBanner + 1;
	} else{
		this.currentBanner = 0;
	}
	document.getElementById(this.aNodes[this.order[oldBanner]].name).className = "m_banner_hide";
	document.getElementById(this.aNodes[this.order[this.currentBanner]].name).className = "m_banner_show";
}
