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

Banner.prototype.add = function(bannerType, bannerPath, bannerDuration, height, width, titulo, hyperlink) {
	this.aNodes[this.aNodes.length] = new Node(this.obj +"_"+ this.aNodes.length, bannerType, bannerPath, bannerDuration, height, width, titulo, hyperlink);
};

function Node(name, bannerType, bannerPath, bannerDuration, height, width, titulo, hyperlink) {
	this.name = name;
	this.bannerType = bannerType;
	this.bannerPath = bannerPath;
	this.bannerDuration = bannerDuration;
	this.height = height
	this.width = width;
	this.hyperlink= hyperlink;
	this.titulo = titulo;
};

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 + 'style=\'display=none\'';
		str = str + 'bgcolor="#8d1414" ';
		str = str + 'alt="'+ this.aNodes[iCtr].titulo +'" ';
		str = str + 'title="'+ this.aNodes[iCtr].titulo +'" ';
		str = str + 'align="center" ';
		str = str + 'height="0" ';
		str = str + 'width="0" ';
		str = str + 'valign="top" >\n';
		if (this.aNodes[iCtr].hyperlink != ""){
			str = str + '<a href="'+this.aNodes[iCtr].hyperlink+'">';
		}
			
		if ( this.aNodes[iCtr].bannerType == "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].bannerPath + '">'
			str = str + '<PARAM NAME=quality VALUE=high>'
			str = str + '<PARAM NAME=bgcolor VALUE=#FFFCDA>'
			str = str + '<EMBED ';
			str = str + 'src="'+this.aNodes[iCtr].bannerPath+'" '
			str = str + 'quality=high '
			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].bannerType == "IMAGE" ){
			str = str + '<img id="img' + this.aNodes[iCtr].name + '" src="'+this.aNodes[iCtr].bannerPath+'" ';
			str = str + 'border="0" ';
			str = str + 'height="0" ';
			str = str + 'width="0">';
		}

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

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

Banner.prototype.start = function(){
	this.changeBanner();
	var thisBannerObj = this.obj;
	setTimeout(thisBannerObj+".start()", this.aNodes[this.currentBanner].bannerDuration * 4000);
}

Banner.prototype.changeBanner = function(){
	var oldBanner=this.currentBanner
	do{
		this.currentBanner=Math.round((this.aNodes.length-1)*Math.random())
	}while(this.currentBanner==oldBanner)
    if (document.getElementById(this.aNodes[oldBanner].name).style.display!='none'){
     document.getElementById(this.aNodes[oldBanner].name).style.display="none";
    }
    document.getElementById(this.aNodes[this.currentBanner].name).style.display="";
    var xImg = document.getElementById("img" + this.aNodes[this.currentBanner].name);
    xImg.height=this.aNodes[this.currentBanner].height;
    xImg.width=this.aNodes[this.currentBanner].width;

}