
// BANNER OBJECT
function Cbn(objName){
	this.obj = objName;
	this.aNodes = [];
	this.currentCbn = 0;
	
};

// ADD NEW BANNER
Cbn.prototype.add = function(cbnType, cbnPath, cbnDuration, height, width, hyperlink, html) {
	this.aNodes[this.aNodes.length] = new Node(this.obj +"_"+ this.aNodes.length, cbnType, cbnPath, cbnDuration, height, width, hyperlink, html);
};

// Node object
function Node(name, cbnType, cbnPath, cbnDuration, height, width, hyperlink, html) {
	this.name = name;
	this.cbnType = cbnType;
	this.cbnPath = cbnPath;
	this.cbnDuration = cbnDuration;
	this.height = height
	this.width = width;
	this.hyperlink= hyperlink;
	this.html= html;
//	alert (name +"|" + cbnType +"|" + cbnPath +"|" + cbnDuration +"|" + height +"|" + width + "|" + hyperlink);
};

// Outputs the cbn to the page
Cbn.prototype.toString = function() {
	var str = ""
	for (var iCtr=0; iCtr < this.aNodes.length; iCtr++){
		str = str + '<div style="border:1px solid #C9C9C7; width:'+this.aNodes[iCtr].width+'px" class="center2_cbn" name="'+this.aNodes[iCtr].name+'" '
		str = str + 'id="'+this.aNodes[iCtr].name+'" ';
		str = str + 'class="m_cbn_hide" ';
		str = str + 'bgcolor="#FFFFFF" ';	// CHANGE BANNER COLOR HERE
		str = str + 'align="left" ';
		str = str + 'valign="top" >\n';
		if (this.aNodes[iCtr].hyperlink != ""){
			str = str + '<a href="'+this.aNodes[iCtr].hyperlink+'">';
		}
			
		if ( this.aNodes[iCtr].cbnType == "FLASH" ){
			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 + 'ALIGN="" '
			str = str + 'VIEWASTEXT>'
			str = str + '<PARAM NAME=movie VALUE="'+ this.aNodes[iCtr].cbnPath + '">'
			str = str + '<PARAM NAME=quality VALUE=high>'
			str = str + '<PARAM NAME=bgcolor VALUE=#FFFFFF>'
			str = str + '<EMBED ';
			str = str + 'src="'+this.aNodes[iCtr].cbnPath+'" '
			str = str + 'quality=high '
//			str = str + 'bgcolor=#FFFCDA '
			str = str + 'WIDTH="'+this.aNodes[iCtr].width+'" '
			str = str + 'HEIGHT="'+this.aNodes[iCtr].height+'" '
			str = str + 'NAME="bnr_'+this.aNodes[iCtr].name+'" '
			str = str + 'ALIGN="center" '
			str = str + 'TYPE="application/x-shockwave-flash" '
			str = str + 'PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'
			str = str + '</EMBED>'
			str = str + '</OBJECT>'
		}else if ( this.aNodes[iCtr].cbnType == "IMAGE" ){
			str = str + '<img src="'+this.aNodes[iCtr].cbnPath+'" ';
			str = str + 'border="0" ';
			str = str + 'height="'+this.aNodes[iCtr].height+'" ';
			str = str + 'width="'+this.aNodes[iCtr].width+'">';
		}

		if (this.aNodes[iCtr].hyperlink != ""){
			str = str + '</a>';
		}

		str += this.aNodes[iCtr].html;
		str += '</div>';
	}
	return str;
};

// START THE BANNER ROTATION
Cbn.prototype.start = function(){
	this.changeCbn();
	var thisCbnObj = this.obj;
	// CURRENT BANNER IS ALREADY INCREMENTED IN cahngeCbn() FUNCTION
	setTimeout(thisCbnObj+".start()", this.aNodes[this.currentCbn].cbnDuration * 1000);
}

// CHANGE BANNER
Cbn.prototype.changeCbn = function(){
	var thisCbn;
	var prevCbn = -1;
	if (this.currentCbn < this.aNodes.length ){
		thisCbn = this.currentCbn;
		if (this.aNodes.length > 1){
			if ( thisCbn > 0 ){
				prevCbn = thisCbn - 1;
			}else{
				prevCbn = this.aNodes.length-1;
			}
		}
		if (this.currentCbn < this.aNodes.length - 1){
			this.currentCbn = this.currentCbn + 1;
		}else{
			this.currentCbn = 0;
		}
	}
	

	if (prevCbn >= 0){
		document.getElementById(this.aNodes[prevCbn].name).className = "m_cbn_hide";
	}
	document.getElementById(this.aNodes[thisCbn].name).className = "m_cbn_show";
}


