var adsoom_topMargin = 10;
var adsoom_slideTime = 1000;
var adsoom_ns6 = (!document.all && document.getElementById);
var adsoom_ie = (document.all);
var adsoom_ns4 = (document.layers);
var adsoom_url_filtro="";

if(adsoom_ad_tipo.substr(0,2)=="BN"){
	adsoom_ad_tipopubli="BLOQUE";
}else{
	adsoom_ad_tipopubli=adsoom_ad_tipo;
}

switch (adsoom_ad_tipopubli){
case "BLOQUE":
	document.write("<div id='adsoom-"+adsoom_ad_cliente+"' style='height:"+adsoom_ad_height+"px; width:"+adsoom_ad_width+"px;'></div>");
break;
default:
	document.write("<div id=\"adsoom-"+adsoom_ad_cliente+"\"></div>");
break;
}

if ( typeof( window[ 'adsoom_ad_idc' ] ) != "undefined" ) {
	 adsoom_url_filtro=adsoom_url_filtro+"&idc="+adsoom_ad_idc;
}
if ( typeof( window[ 'adsoom_ad_rotar' ] ) != "undefined" ) {
	 adsoom_url_filtro=adsoom_url_filtro+"&idrot="+adsoom_ad_rotar;
}
if ( typeof( window[ 'adsoom_ad_grupo' ] ) != "undefined" ) {
	 adsoom_url_filtro=adsoom_url_filtro+"&idg="+adsoom_ad_grupo;
}

function adsoom_include(file_path){
        var j = document.createElement("script");
        j.type = "text/javascript";
        j.src = file_path;
	document.getElementsByTagName("head")[0].appendChild(j); 
}

function adsoom_layerSetup() {
	window.setInterval("adsoom_main()", 10);
}

function adsoom_layerObject(id,left) {
	if (adsoom_ns6) {
		this.obj = document.getElementById(id).style;
		this.obj.left = left;
		return this.obj;
	}
	else if(adsoom_ie) {
		this.obj = document.getElementById(id).style;
		this.obj.left = left;
		return this.obj;
	}
	else if(adsoom_ns4) {
		this.obj = document.layers[id];
		this.obj.left = left;
		return this.obj;
	}
}

function adsoom_animator() {
	var now = new Date();
	var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
	newY = Math.round(newY);
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
	if ( adsoom_ie ) document.getElementById('adsoom_layer').style.top = newY+ "px";
	if ( adsoom_ns4 ) document.layers["adsoom_layer"].top = newY+ "px";
	if ( adsoom_ns6 ) document.getElementById('adsoom_layer').style.top = newY + "px";
	   }
}

function adsoom_main() {
	if (adsoom_ns4) {
		this.currentY = document.layers["adsoom_layer"].top;
		this.scrollTop = window.pageYOffset;
		adsoom_mainTrigger();
	}else if(adsoom_ns6) {
		this.currentY = parseInt(document.getElementById('adsoom_layer').style.top);
		if(document.documentElement.scrollTop>0){
    		    this.scrollTop=document.documentElement.scrollTop;
		}else if(scrollY>0){
		    this.scrollTop=scrollY;
		}else{
    		    this.scrollTop=0;
		}
		adsoom_mainTrigger();
	} else if(adsoom_ie) {
		this.currentY = adsoom_layer.style.pixelTop;
		if(document.documentElement.scrollTop>0){
		    this.scrollTop=document.documentElement.scrollTop; 
		}else if(document.body.scrollTop>0){
    		    this.scrollTop=document.body.scrollTop;
		}else{
		    this.scrollTop=0;
		}
		adsoom_mainTrigger();
	}
}

function adsoom_mainTrigger() {
	var newTargetY = this.scrollTop + this.adsoom_topMargin;
	if ( this.currentY != newTargetY ) {
		if ( newTargetY != this.targetY ) {
			this.targetY = newTargetY;
			adsoom_floatStart();
		}
		adsoom_animator();
	}
}

function adsoom_floatStart() {
	var now = new Date();
	this.A = this.targetY - this.currentY;
	this.B = Math.PI / ( 1 * this.adsoom_slideTime );
	this.C = now.getTime();
	if (Math.abs(this.A) > this.findHt) {
		this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
		this.A = this.A > 0 ? this.findHt : -this.findHt;
	}else {
		this.D = this.currentY;
	}
}

function adsoom_floatObject() {
	if (adsoom_ns4 || adsoom_ns6) {
		findHt = window.innerHeight;
	} else if(adsoom_ie) {
		findHt = document.body.clientHeight;
	   }
}

function adsoom_start() {
	if(screen.width>2000){
		adsoom_layerObject('adsoom_layer',(1280-750)/2);	
	}else{
		adsoom_layerObject('adsoom_layer',(screen.width-750)/2);
	}
	if(adsoom_ns6||adsoom_ns4) {
		pageWidth = innerWidth;
		pageHeight = innerHeight;
		adsoom_layerSetup();
		adsoom_floatObject();
	}else if(adsoom_ie) {
		pageWidth = document.body.clientWidth;
		pageHeight = document.body.clientHeight;
		adsoom_layerSetup();
		adsoom_floatObject();
		WCH.Apply('adsoom_layer');
	}
}

function adsoom_getidlayer(id) {
	return document.getElementById(id);
}

function adsoom_showlayer(id) {
	var e=adsoom_getidlayer(id);
	if (e) {
		e.style.display = 'block';
	}
}
function adsoom_hidelayer(id) {
	WCH.Discard('adsoom_layer');
	var e=adsoom_getidlayer(id);
	if (e) {
		e.style.display = 'none';
	}
}

function adsoom_popin_load(){
	adsoom_include("http://adsoom.com/pub/mostrar_codigo.js?idt="+adsoom_ad_tipo+"&idclte="+adsoom_ad_cliente+adsoom_url_filtro);
}

function adsoom_popout_load(){
	adsoom_include("http://adsoom.com/pub/mostrar_codigo.js?idt="+adsoom_ad_tipo+"&idclte="+adsoom_ad_cliente+adsoom_url_filtro);
}

function adsoom_adlayer_load(){
	adsoom_include("http://adsoom.com/pub/wch.js");
	adsoom_include("http://adsoom.com/pub/mostrar_codigo.js?idt="+adsoom_ad_tipo+"&idclte="+adsoom_ad_cliente+adsoom_url_filtro);
}

switch (adsoom_ad_tipopubli){
case "LAYER":
	 adsoom_adlayer_load();
break;
case "POPIN":
	window.onload=function(){
	 adsoom_popin_load();
	}
break;
case "POPOUT":
	window.onunload=function(){
	 adsoom_popout_load();
	}
break;
case "BLOQUE":
	if(adsoom_ad_format=="IMAGEN"){
		document.getElementById("adsoom-"+adsoom_ad_cliente).innerHTML='<iframe name="adsoom_ad_frame" width='+(adsoom_ad_width+2)+' height='+(adsoom_ad_height+2)+' frameborder=0 src="http://adsoom.com/pub/mostrar_bloque.php?w='+adsoom_ad_width+'&h='+adsoom_ad_height+'&idc='+adsoom_ad_idc+'&idclte='+adsoom_ad_cliente+'&idf='+adsoom_ad_format+'" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no">';
	}else{
		document.getElementById("adsoom-"+adsoom_ad_cliente).innerHTML='<iframe name="adsoom_ad_frame" width='+(adsoom_ad_width+2)+' height='+(adsoom_ad_height+2)+' frameborder=0 src="http://adsoom.com/pub/mostrar_bloque.php?cb='+adsoom_color_borde+'&ctit='+adsoom_color_titulo+'&cf='+adsoom_color_fondo+'&ctxt='+adsoom_color_texto+'&cu='+adsoom_color_url+'&w='+adsoom_ad_width+'&h='+adsoom_ad_height+'&idc='+adsoom_ad_idc+'&idclte='+adsoom_ad_cliente+'&idf='+adsoom_ad_format+'" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no">';
	}
break;
}
