/////////////////////////////////
// File Name: rdisplay.js       //
// By: Manish Kumar Namdeo     //
/////////////////////////////////

// DISPLAY OBJECT
function Rdisplay(objName){
	this.obj = objName;
	this.aNodes = [];
	this.currentRdisplay = 0;

};

// ADD NEW DISPLAY
Rdisplay.prototype.add = function(rdisplayType, rdisplayPath, rdisplayDuration, height, width, hyperlink) {
	this.aNodes[this.aNodes.length] = new Node(this.obj +"_"+ this.aNodes.length, rdisplayType, rdisplayPath, rdisplayDuration, height, width, hyperlink);
};

// Node object
function Node(name, rdisplayType, rdisplayPath, rdisplayDuration, height, width, hyperlink) {
	this.name = name;
	this.rdisplayType = rdisplayType;
	this.rdisplayPath = rdisplayPath;
	this.rdisplayDuration = rdisplayDuration;
	this.height = height
	this.width = width;
	this.hyperlink= hyperlink;
//	alert (name +"|" + rdisplayType +"|" + rdisplayPath +"|" + rdisplayDuration +"|" + height +"|" + width + "|" + hyperlink);
};

// Outputs the display to the page
Rdisplay.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="rdisplay_hide" ';
		str = str + 'bgcolor="#FFFFFF" ';	// CHANGE DISPLAY COLOR HERE
		str = str + 'align="center" ';
		str = str + 'valign="top" >\n';
		if (this.aNodes[iCtr].hyperlink != ""){
			str = str + '<a href="'+this.aNodes[iCtr].hyperlink+'">';
		}

		if ( this.aNodes[iCtr].rdisplayType == "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].rdisplayPath + '">'
			str = str + '<PARAM NAME=quality VALUE=high>'
			str = str + '<PARAM NAME=bgcolor VALUE=#FFFCDA>'
			str = str + '<EMBED ';
			str = str + 'src="'+this.aNodes[iCtr].rdisplayPath+'" '
			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].rdisplayType == "IMAGE" ){
			str = str + '<img src="'+this.aNodes[iCtr].rdisplayPath+'" ';
			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 += '</span>';
	}
	return str;
};

// START THE DISPLAY ROTATION
Rdisplay.prototype.start = function(){
	this.changeRdisplay();
	var thisRdisplayObj = this.obj;
	// CURRENT DISPLAY IS ALREADY INCREMENTED IN changeRdisplay() FUNCTION
	setTimeout(thisRdisplayObj+".start()", this.aNodes[this.currentRdisplay].rdisplayDuration * 1000);
}

// CHANGE DISPLAY
Rdisplay.prototype.changeRdisplay = function(){
	var thisRdisplay;
	var prevRdisplay = -1;
	if (this.currentRdisplay < this.aNodes.length ){
		thisRdisplay = this.currentRdisplay;
		if (this.aNodes.length > 1){
			if ( thisRdisplay > 0 ){
				prevRdisplay = thisRdisplay - 1;
			}else{
				prevRdisplay = this.aNodes.length-1;
			}
		}
		if (this.currentRdisplay < this.aNodes.length - 1){
			this.currentRdisplay = this.currentRdisplay + 1;
		}else{
			this.currentRdisplay = 0;
		}
	}


	if (prevRdisplay >= 0){
		document.getElementById(this.aNodes[prevRdisplay].name).className = "rdisplay_hide";
	}
	document.getElementById(this.aNodes[thisRdisplay].name).className = "rdisplay_show";
}

