function f_posicao_objeto_publicidade(obj){
	var total_left = 0;
	var total_top = 0;
	while(obj!=null){
		total_left += obj["offsetLeft"];
		total_top += obj["offsetTop"];
		try {
			obj=obj.offsetParent;
		} catch(e) { 
			obj=obj.parentNode;
		}
	}
	v_get_scroll_element = document.getElementById('content');
	f_get_scroll();
	return { left: total_left-scrOfX, top: total_top, toString: function() { return "("+total_top+","+total_left+")" } } ;
}

function Publicidade(config) {
	this.config = config;
	this.container = document.getElementById(this.config.object_id);
	this.container.pubObj = this;
	this.type = this.config.type;
	this.shieldDiv = document.createElement("iframe");
	this.shieldDiv.pubObj = this;
	this.shieldDiv.frameborder = 0;
	//this.shieldDiv.style.backgroundColor ='none';
	this.shieldDiv.style.position = 'absolute';
	this.shieldDiv.style.left = 'auto';
	this.shieldDiv.style.top = 'auto';
	
	this.shieldDiv.style.display = 'none';
	this.shieldDiv.style.opacity = 0;
	this.shieldDiv.style.filter = "alpha(opacity=0)";
	

	
	this.outerDiv = document.createElement("div");
	this.outerDiv.pubObj = this;
	
	this.shieldDiv.onmouseover = function() {
//		this.pubObj.explode();
	}
	this.shieldDiv.onmouseout = function() {
//		this.pubObj.implode();
	}
	

	this.container.appendChild(this.outerDiv);
//	this.container.appendChild(this.shieldDiv);
	this.innerDiv = document.createElement("div");
	this.innerDiv.pubObj = this;
	this.innerDivEx = document.createElement("div");
	this.innerDivEx.pubObj = this;
	this.container.onmouseover = function() {
//		this.pubObj.explode();
	}
	this.container.onmouseout = function() {
//		this.pubObj.implode();
	}

	this.outerDiv.onmouseout = function() {
//		this.pubObj.implode();
	}

 	this.outerDiv.appendChild(this.innerDivEx);
 	this.innerDivEx.appendChild(this.innerDiv);
	this.setFile = function(type,file) {
		if(String(file).indexOf('?') != -1)
			v_conn = '&';
		else
			v_conn = '?';
		if(String(file).indexOf('youtube') != -1) {
			v_conn = '&';
		}
		switch(String(type).toUpperCase()) {
			case 'SWF':
				v_result = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+this.widthex+'" height="'+this.heightex+'">';
       			v_result += '	<param name="movie" value="'+file+v_conn+'md5='+this.config.md5+'&clickTAG='+escape('/portal/publico/click_counter.php?p='+this.config.publicidade_id+'&c='+this.config.criterio_id+'&h='+this.config.horario_id)+'&cod='+this.config.layout_objeto_id+'" />';
        		v_result += '	<param name="quality" value="high" />';
				v_result += '	<param name="wmode" value="transparent" />';
				if(this.config.bgcolor != '')
					v_result += '	<param name="bgcolor" value="'+this.config.bgcolor+'" />';
        		v_result += '	<embed src="'+file+v_conn+'md5='+this.config.md5+'&clickTAG='+escape('/portal/publico/click_counter.php?p='+this.config.publicidade_id+'&c='+this.config.criterio_id+'&h='+this.config.horario_id)+'&cod='+this.config.layout_objeto_id+'" quality="high" wmode="transparent" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+this.widthex+'" height="'+this.heightex+'"></embed>';
      			v_result += '</object>';
				this.innerDiv.innerHTML = v_result;
//				alert(v_result);
				this.innerDiv.childNodes[0].pubObj = this;
				this.innerDiv.childNodes[0].onmouseover = function(event) {
//					this.pubObj.explode();
				}
				this.innerDiv.childNodes[0].onmouseout = function(event) {
//					this.pubObj.implode();
					(window.event?window.event:event).cancelBubble = true;
				}
				break;
			case 'JPEG':				
			case 'GIF':
				v_result = '<img style="cursor:pointer" width="'+this.widthex+'" height="'+this.heightex+'" src="'+file+'" ';
				if(this.target == "_blank")
					v_result += ' onclick="window.open(\'/portal/publico/click_counter.php?p='+this.config.publicidade_id+'&c='+this.config.criterio_id+'&h='+this.config.horario_id+'\')">';
				else
					v_result += ' onclick="window.location = \'/portal/publico/click_counter.php?p='+this.config.publicidade_id+'&c='+this.config.criterio_id+'&h='+this.config.horario_id+'\'">';
	  			this.innerDiv.innerHTML = v_result;
				break;
		}
	}
	this.setSize = function(width,height) {
		this.width = width;
		this.height = height;
	}
	this.getSize = function() {
		return {
				width: this.width,
				height: this.height,
				toString: function() {
					return "("+this.width+","+this.height+")";
				}
			}
	}
	this.setSizeEx = function(top,left,width,height) {
		this.topex = top;
		this.leftex = left;
		this.widthex = width;
		this.heightex = height;
	}
	this.explode = function() {
		if(document.loaded) {
			if(this.topex == 0 && this.leftex == 0 && this.widthex == this.width && this.heightex == this.height) {
			} else {
				if(!this.exploded) {
					if(window.event)
						this.shieldDiv.style.display = '';
					
					var v_posicao = f_posicao_objeto_publicidade(this.container);
					this.outerDiv.style.top = 'auto';
					this.outerDiv.style.left = 'auto';
					this.outerDiv.style.clip = 'rect(0px '+this.widthex+'px '+this.heightex+'px 0px)';
					this.shieldDiv.style.top = (v_posicao.top-Math.abs(this.topex))+'px';
					this.shieldDiv.style.left = (v_posicao.left-Math.abs(this.leftex))+'px';
					if(this.shieldDiv.parentNode.id != 'content')
						document.getElementById('content').appendChild(this.shieldDiv);
					this.shieldDiv.style.zIndex = 100;
					this.outerDiv.style.top = (v_posicao.top-Math.abs(this.topex))+'px';
					this.outerDiv.style.left = (v_posicao.left-Math.abs(this.leftex))+'px';
					//this.outerDiv.parentNode.appendChild(this.outerDiv);
					if(this.outerDiv.parentNode.id != 'content') {
						document.getElementById('content').appendChild(this.outerDiv);
//						this.outerDiv.style.position = 'absolute';
//						this.innerDiv.style.position = 'relative';
					}
					
					this.outerDiv.style.zIndex = 101;
					
					this.innerDivEx.style.top = '0px'; 
					
					this.innerDivEx.style.left = '0px';
					
					this.innerDivEx.style.height = this.heightex;
					
					this.innerDivEx.style.width = this.widthex;
					this.innerDiv.style.height = this.heightex+17;
					this.innerDiv.style.width = this.widthex+17;
					this.shieldDiv.style.height = this.heightex;
					
					this.shieldDiv.style.width = this.widthex;
					
					this.exploded = true;
				}
			}
		}
		return;
	}
	this.exploded = false;
	this.implode = function(v_force) {
		this.shieldDiv.style.display = 'none';
		if(v_force || (document.loaded && this.exploded)) {
			
			this.exploded = false;
			if(!(this.topex == 0 && this.leftex == 0 && this.widthex == this.width && this.heightex == this.height)) {
				if(this.outerDiv.parentNode.id != 'content')
					this.container.appendChild(this.outerDiv);
				if(this.outerDiv.parentNode.id != 'content')
					this.container.appendChild(this.shieldDiv);
				this.outerDiv.style.position = 'absolute';
				this.outerDiv.style.clip = 'rect(0px '+this.width+'px '+this.height+'px 0px)';
			
				this.innerDivEx.style.position = 'relative';
				this.innerDivEx.style.top = (Math.abs(this.topex)*(-1))+'px'; 
				this.innerDivEx.style.left = (Math.abs(this.leftex)*(-1))+'px';
//				this.outerDiv.style.top = 'auto';
//				this.outerDiv.style.left = 'auto';
//				this.shieldDiv.style.top = 'auto';
//				this.shieldDiv.style.left = 'auto';
				this.shieldDiv.style.height = this.height;
				if(!window.event) {
					this.outerDiv.style.overflow = 'auto';
					this.innerDiv.style.overflow = 'auto';
				}
				this.outerDiv.height = this.height;
				this.innerDivEx.style.height = this.height;
				this.innerDivEx.style.width = this.width;
				this.innerDiv.style.height = this.height+17;
				this.innerDiv.style.width = this.width+17;
				this.outerDiv.style.zIndex = 1;
				this.container.style.zIndex = 1;
				this.shieldDiv.style.height = this.height;
				this.shieldDiv.style.width = this.width;
//				this.innerDiv.childNodes[0].style.position = 'absolute';
//				this.outerDiv.style.position = 'absolute';
			}
		}
		return;
	}
	this.width = this.config.width;	
	this.height = this.config.height;
	this.target = this.config.target;
	this.setSize(this.config.width,this.config.height);
	this.setSizeEx(this.config.topex,this.config.leftex,this.config.widthex,this.config.heightex);
	this.setFile(this.config.type,this.config.file) 
	this.exploded = true;
	this.teste = true;
	this.implode(true);
}

function f_inner_flash(object,inner) {
	object.innerHTML = inner;
}

