/////////////////////////////////
// File Name: mBanner.js       //
// By: Manish Kumar Namdeo     //
/////////////////////////////////

// BANNER OBJECT
function Banner(objName){
	this.obj = objName;
	this.aNodes = [];
	this.currentBanner = 0;
	
};

// ADD NEW BANNER
Banner.prototype.add = function(bannerPath, bannerDuration) {
	this.aNodes[this.aNodes.length] = new Node(this.obj +"_"+ this.aNodes.length, bannerPath, bannerDuration);
};

// Node object
function Node(name, bannerPath, bannerDuration) {
	this.name = name;
	this.bannerPath = bannerPath;
	this.bannerDuration = bannerDuration;
	//alert (name +" >>>>>>>>>>>> " + bannerPath +" >>>>>>>>>>>>>>>> " + bannerDuration);
};

// 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="m_banner_hide" ';
		str = str + 'bgcolor="#F3F9F5" ';	// carregue a cor do banner aqui.
		str = str + 'align="center" ';
		str = str + 'valign="top" >\n';
		
			
		str = str + '<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="310" ALIGN="center">'
		str = str + '	<param name="movie" value="'+ this.aNodes[iCtr].bannerPath + '" />'
		str = str + '	<param name="quality" value="high" />'
		str = str + '	<param name="wmode" value="opaque" />'
		str = str + '	<param name="swfversion" value="6.0.65.0" />'
		str = str + '	<param name="expressinstall" value="Scripts/expressInstall.swf" />'
		str = str + '	'
		str = str + '	<!--[if !IE]>-->'
		str = str + '	<object type="application/x-shockwave-flash" data="'+ this.aNodes[iCtr].bannerPath + '" width="1280" height="310" id="bnr_'+this.aNodes[iCtr].name+'" ALIGN="center">'
		str = str + '		<!--<![endif]-->'
		str = str + '		<param name="quality" value="high" />'
		str = str + '		<param name="wmode" value="opaque" />'
		str = str + '		<param name="swfversion" value="6.0.65.0" />'
		str = str + '		<param name="expressinstall" value="Scripts/expressInstall.swf" />'
		str = str + '		<div>'
		str = str + '		<h4> Conteúdo desta página requer uma versão atualizada do Adobe Flash Player. </h4>'
		str = str + '		<p><a href="http://www.adobe.com/go/getflashplayer"> <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Baixe o Flash Player" width="112" height="33" /> </a></p>'
		str = str + '		</div>'
		str = str + '		<!--[if !IE]>-->'
		str = str + '	</object>'
		str = str + '	<!--<![endif]-->'
		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
	setTimeout(thisBannerObj+".start()", this.aNodes[this.currentBanner].bannerDuration * 1000);
}

// CHANGE BANNER
Banner.prototype.changeBanner = function(){
	var thisBanner;
	var 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 (prevBanner >= 0){
		document.getElementById(this.aNodes[prevBanner].name).className = "m_banner_hide";
	}
	document.getElementById(this.aNodes[thisBanner].name).className = "m_banner_show";
}


