function bannerOPEC(bo) {
	this.ie = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	this.mac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
	this.versionMax = 7;
	this.tempoMax = 12;
	this.bo = bo;
	this.bo.id = 'bannerGlb_' + new Date().getTime() + Math.floor(Math.random()*100);
	if(!this.bo.version) this.bo.version = this.versionMax;
	if(!this.bo.tempo) this.bo.tempo = this.tempoMax;
	if(this.bo.version) if(this.bo.version > this.versionMax) this.bo.version = this.versionMax;
	if(this.bo.tempo) if(this.bo.tempo > this.tempoMax) this.bo.tempo = this.tempoMax;
	this.bo.flashvars = 'ie='+this.ie;
	if(this.bo.url) this.bo.flashvars+= '&lnk='+this.bo.url;
	if(this.bo.width) this.bo.flashvars+= '&width='+this.bo.width;
	if(this.bo.width) this.bo.flashvars+= '&width='+this.bo.width;
	if(this.bo.height) this.bo.flashvars+= '&height='+this.bo.height;	
	if(this.bo.minWidth) this.bo.flashvars+= '&minWidth='+this.bo.minWidth;	
	if(this.bo.minHeight) this.bo.flashvars+= '&minHeight='+this.bo.minHeight;	
	if(this.bo.id) this.bo.flashvars+= '&id='+this.bo.id;
	if(!this.bo.div) this.bo.div = 'ban_' + new Date().getTime() + Math.floor(Math.random()*100);
	this.htm = '';
	this.script = '';

	var align = '';
	if(this.bo.align == 'center') align = 'margin:0 auto;';	
	
	switch(this.bo.tipo) {
		case 'expandFlash':
			if(this.bo.img) {
				document.write('<div id="' +this.bo.div+ '" style="' + align +'width:'+this.bo.minWidth+'px;height:'+this.bo.minHeight+'px;" >');
				document.write(this.getImg(this.bo.minWidth,this.bo.minHeight));
				document.write('</div>');
			} else {
				document.write('<div id="' +this.bo.div+ '" style="' + align +'width:'+this.bo.minWidth+'px;height:'+this.bo.minHeight+'px;"></div>');
			}
			if(this.detectFlash().version >= this.bo.version) {
				this.bo.divAbs = this.bo.div + 'Abs';
				if(this.bo.divAbs) this.bo.flashvars+= '&div='+this.bo.divAbs;
				var htmTemp = '';
				if(this.bo.debug) htmTemp = 'background:red;';
				this.htm+= '<div id="'+this.bo.divAbs+'" style="'+htmTemp+'position:absolute;z-index:2000;width:'+this.bo.minWidth+'px;height:'+this.bo.minHeight+'px;">';
				this.htm+= this.getFlash(this.bo.minWidth,this.bo.minHeight,'100%','100%');
				this.htm+= '</div><div style="width:'+this.bo.minWidth+'px;height:'+this.bo.minHeight+'px;"></div>';
				this.bo.script = 'if(p1 == "abre") clipBannerGlb("'+this.bo.id+'","'+this.bo.divAbs+'",'+this.bo.width+','+this.bo.height+'); if(p1 == "fecha") clipBannerGlb("'+this.bo.id+'","'+this.bo.divAbs+'",'+this.bo.minWidth+','+this.bo.minHeight+'); if(p1 == "go") goBannerGlb(p2); ';
				this.script = this.getFlashScript();
				this.addLoadEvent(this,'write');
			}
			break;
		case 'fullFlash':
			document.write('<div id="' +this.bo.div+ '" style="' + align +'width:'+this.bo.width+'px;height:'+this.bo.height+'px;" >');
			if(this.detectFlash().version >= this.bo.version) {
				document.write(this.getFlash(this.bo.width,this.bo.height));
			} else {
				if(this.bo.img) document.write(this.getImg(this.bo.width,this.bo.width));
			}
			document.write('</div>');
			break;
		case 'fullImg':
			document.write('<div id="' +this.bo.div+ '" style="' + align +'width:'+this.bo.width+'px;height:'+this.bo.height+'px;" >');
			document.write(this.getImg(this.bo.width,this.bo.height));
			document.write('</div>');
			break;
		case 'floatFlash':
			if(this.detectFlash().version >= this.bo.version) {
				document.write('<div id="' +this.bo.div+ '"></div>');	
				this.bo.divAbs = this.bo.div + 'Abs';
				if(this.bo.divAbs) this.bo.flashvars+= '&div='+this.bo.divAbs;
				this.htm+= '<div id="'+this.bo.divAbs+'" style="margin:0 auto;width:778px;"><div style="position:absolute;z-index:2000;margin-left:'+this.bo.left+'px;margin-top:'+this.bo.top+'px;width:'+this.bo.width+'px;height:'+this.bo.height+'px;">';
				this.htm+= this.getFlash(this.bo.width,this.bo.height);
				this.htm+= '</div></div>';
				this.bo.script = 'if(p1 == "go") goBannerGlb(p2); if(p1 == "fechar") fechaBannerGlb(p2); ';
				this.script = this.getFlashScript();
				this.addLoadEvent(this,'write');
				this.addLoadEvent(this,'close');
			}
			break;
		case 'floatImg':
			this.bo.divAbs = this.bo.div + 'Abs';
			this.htm+= '<div id="'+this.bo.divAbs+'" style="margin:0 auto;width:778px;"><div style="position:absolute;z-index:2000;margin-left:'+this.bo.left+'px;margin-top:'+this.bo.top+'px;width:'+this.bo.width+'px;height:'+this.bo.height+'px;">';
			if(this.bo.img) this.htm+=this.getImg(this.bo.width,this.bo.height);
			this.htm+= '</div></div>';
			document.write(this.htm);
			this.addLoadEvent(this,'close');
			break;
	}
}

bannerOPEC.prototype.getImg = function(w,h) {
	var htm = '';
	htm+='<a href="' + this.bo.url + '" target="_blank"><img src="' +this.bo.img+ '" border="0" width="'+w+'" height="'+h+'" alt="'+this.bo.url+'" /></a>';
	return htm;
}

bannerOPEC.prototype.getFlash = function(wo,ho,we,he) {
	if(!we) we = wo;
	if(!he) he = ho;
	var flagT = '';
	var flgN = '';
	if(this.bo.wmode) flagT = ' wmode="' +this.bo.wmode+ '" ';
	if(this.bo.id) flgN = ' name="'+this.bo.id+'" id="'+this.bo.id+'" ';
	var htm = '';
	htm+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownloadocument.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.bo.version+',0,0,0" width="'+ wo +'" height="'+ ho +'" ' + flgN + '>';
	htm+='<param name="movie" value="' + this.bo.movie + '" /><param name="quality" value="high" /><param name="flashvars" value="' + this.bo.flashvars + '" />';
	if(this.bo.wmode) htm += '<param name="wmode" value="' + this.bo.wmode + '" />';
	htm+='<embed ' + flagT + flgN + ' src="' + this.bo.movie + '" flashvars="' + this.bo.flashvars + '" quality="high" width="'+we+'" height="'+he+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	return htm;
}

bannerOPEC.prototype.getFlashScript = function() {
	var script = document.createElement('script');
	script.language='javascript';
	script.type='text/javascript';
	if(this.ie && !this.mac) {
		script.event ='FSCommand(p1,p2)';
		script.htmlFor = this.bo.id;
		script.text = this.bo.script;
	}
	return script;
}

bannerOPEC.prototype.addLoadEvent = function(obj,str) {
	if (window.addEventListener) {
		window.addEventListener("load", function () { obj[str](); } , false);
	} else if (document.addEventListener) {
		document.addEventListener("load", function () { obj[str](); } , false);
	} else if (window.attachEvent) {
		window.attachEvent("onload", function () { obj[str](); } );
	} else if (typeof window.onload == "function") {
		var fnOld = window.onload;
		window.onload = function(){
			fnOld();
			obj[str]();
		}
	} else {
		window.onload = function () { obj[str](); }
	}
}

bannerOPEC.prototype.close = function() {
	var self = this;
	setTimeout(function(){fechaBannerGlb(self.bo.divAbs)}, self.bo.tempo*1000);
}

bannerOPEC.prototype.write = function() {
	document.getElementById(this.bo.div).innerHTML = this.htm;
	document.getElementById(this.bo.div).appendChild(this.script);
}

bannerOPEC.prototype.detectFlash = function() {
	// objeto de retorno da deteccaoo
	var flashInfo = {};
	flashInfo.version = 0;
	flashInfo.installed = false;
	// se embed
	if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
		var desc = navigator.plugins["Shockwave Flash"].description;
		// descobre a versao
		if (desc) {
			flashInfo.installed = true;
			var versionStr = desc.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
			var major = parseInt(versionStr.replace(/^(.*)\..*$/, "$1"));
			var flashVersion = parseInt(major);
		}
	} else if (window.ActiveXObject) {
		// se object, tenta criar os objetos flash e descobrir a versao
		try {
			var flashObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			var desc = flashObj.GetVariable("$version");
			if(desc) {
				flashInfo.installed = true;
				var versionArr = desc.replace(/^\S+\s+(.*)$/, "$1").split(",");
				var major = parseInt(versionArr[0]);
				var flashVersion = parseInt(major);
			}
		} catch(e) {}
	}
	flashInfo.version = flashVersion;
	return flashInfo;
}

function clip(id,div,w,h) {
	clipBannerGlb(id,div,w,h); // banner bradesco
}

function clipBannerGlb(id,div,w,h) {
	var mac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
	var ie  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	if(!mac && ie) {
		document.getElementById(id).style.height = h + 'px';
		document.getElementById(id).style.width = w + 'px';
	} else {
		document.getElementById(div).style.height = h + 'px';
		document.getElementById(div).style.width = w + 'px';
	}
}

function fechaBannerGlb(obj) {
	try {
		document.getElementById(obj).style.display = 'none';
		document.getElementById(obj).parentNode.style.display = 'none';
	} catch (e) {}
}

function goBannerGlb(url) {
	window.open(url);
}
