function colocaContent(obj) {
	try {
		document.getElementById("mainDiv").appendChild(this)
	} catch(e) {
		processLink(this.pajURL,true)
	}
	this.style.position="absolute";
	this.style.top="0px";
	this.style.left="0px";
	this.style.width="100%"
	this.style.height="100%"

	var duration=2000

	this.style.display="block"
	// Ponemos el try para hacerlo compatible con las páginas de error
	try {
		if (trash.length){
			lista=["B1","C1","D1","B2","C2","D2","B3","C3","D3"]
			var x=0
			var y=0
			for (var i=0;i<lista.length;i++) {
				var loElm=getElementsByClassName(this,"div",lista[i])[0];
				loElm.endX=x*190+198;
				loElm.endY=y*190+8;
				var ang=Math.random()*Math.PI*2
				loElm.style.left=(Math.cos(ang)*1000+281)+"px"
				loElm.style.top=(Math.sin(ang)*1000+281)+"px"
				Effect.playEffect({target:loElm,top:loElm.endY,left:loElm.endX,duration:duration})
				x++
				if (x==3) {
					x=0
					y++
				}
			}
		}
	} catch (e) {}
	cleanUpTrash(this,duration)
}

var onProcessLinks=[];
function processLink(whatURL,override,disableHistory) {
	//if ( (estamosEn("CONTENT"+whatURL)) && (!(override)) && (cacheable(whatURL)) ) return
	var loDiv=document.createElement("div");
	loDiv.style.display="none"
	loDiv.onLoadComplete=colocaContent
	try{
		document.getElementById("visorActividad").id="";
	} catch(e) {}
	loadPage({url:whatURL,target:loDiv});//,disableHistory:disableHistory})
	try {
		for (var i=0; i<onProcessLinks.length; i++) {
			onProcessLinks[i]();
		}
	} catch(e) {}
}

var linkParser=processLink;

var colores={
rojo:"rgb(197,16,21)",
azul:"rgb(30,90,180)",
amarillo:"rgb(232,175,23)"
}
var currBGColor="rojo"
function controlFondo() {
	var tmpColor;
	switch (currBGColor) {
		case "rojo":
			tmpColor="amarillo"
			break;
		case "amarillo":
			tmpColor="azul"
			break;
		default:
			tmpColor="rojo"
			break;
	}
	Effect.playEffect({target:document.body,backgroundColor:colores[tmpColor],duration:10000,interval:200});
	currBGColor=tmpColor;
	setCookie("color",currBGColor,100)
	setTimeout(function(){controlFondo()},70000);
}

var elms=[]
var inicios=[]
function inicio() {
	elms["loading"]=document.getElementById("loading");

	elms["content"]=document.getElementById("mainDiv")

	parseLinks(document.getElementById("menuPrincipal"),"processLink")
	parseLinks(document.getElementById("logo"),"processLink")

	var color=getCookie("color")
	if (!color) color="rojo"
	currBGColor=color
	//Effect.playEffect({target:document.body,backgroundColor:colores[currBGColor],duration:1000,interval:40});
	document.body.style.backgroundColor=colores[color]

	setTimeout(function(){controlFondo()},70000)

	for (var i=0;i<inicios.length;i++) {
		inicios[i]()
	}

	//enableHistory()

	//if (historyEnabled) {
	//	if (window.location.hash.substring(1)) {
	//		processLink(window.location.hash.substring(1),true)
	//	}
	//}

	//elms["content"].style.dispaly="block";

	processLink("portada.php")
}

function resize() {
	var loContent=document.getElementById("mainDiv");
	loHeight=window.innerHeight?window.innerHeight:document.body.clientHeight;
	var winTop=(loHeight-loContent.offsetHeight)/2;
	if (winTop<0) winTop=0;
	loContent.style.marginTop=winTop+"px"
}

var trash=[];
var appCounter=0;

function cleanUpTrash_(which) {
	try {
		which.parentNode.removeChild(which)
	} catch(e) {}
}
function cleanUpTrash(which,when) {
	var loTrash=trash.shift()
	trash.push(which)
	if ( (loTrash!=which) && (loTrash!=undefined) ) {
		setTimeout(function(){cleanUpTrash_(loTrash)},when)
		try {
			lista=["B1","C1","D1","B2","C2","D2","B3","C3","D3"]
			for (var i=0;i<lista.length;i++) {
				var loElm=getElementsByClassName(loTrash,"div",lista[i])[0];
				var ang=Math.random()*Math.PI*2
				Effect.playEffect({target:loElm,top:Math.sin(ang)*1000+281,left:Math.cos(ang)*1000+281,duration:when})
			}
		} catch(e) {}
	}
}

var posicionEnWeb;

function estamosEn(donde) {
	if (posicionEnWeb==donde) {
		return true
	} else {
		posicionEnWeb=donde;
		return false
	}
}

function overMenu(which) {
	which.src=which.alternateSrc.src;
}
function outMenu(which) {
	which.src=which.outSrc;
}
function parseMenu() {
	var imgs=getElementsByClassName(document.body,"img","menu")
	for (var i=0; i<imgs.length;i++) {
		var laImg=imgs[i];
		laImg.outSrc=laImg.src;
		laImg.alternateSrc=new Image();
		laImg.alternateSrc.src=laImg.src.substr(0,laImg.src.length-4)+"_over.png"
		laImg.onmouseover=function(){
			overMenu(this);
		}
		laImg.onmouseout=function(){
			outMenu(this);
		}
	}
}
inicios.push(parseMenu);

var intervalScrolla;
function scrolla(what,speed) {
	clearInterval(intervalScrolla)
	intervalScrolla=setInterval(function(){what.scrollTop+=speed},50)
}
function scrollaHoriz(what,speed) {
	clearInterval(intervalScrolla)
	intervalScrolla=setInterval(function(){what.scrollLeft+=speed},50)
}
function scrollaStop() {
	clearInterval(intervalScrolla)
}
function giveMe(where,className) {
	var arr=getElementsByClassName(where.parentNode,"*",className)
	return arr[0]
}

var targetForWheel,targetForHorizontalWheel

/** This is high-level function.
 * It must react to delta being more/less than zero.
 */
function handle(delta) {
	try {
		targetForWheel.scrollTop+=-20*parseFloat(delta)
	} catch(e) {}
	try {
		targetForHorizontalWheel.scrollLeft+=-20*parseFloat(delta)
	} catch(e) {}
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
	var delta = 0;
	if (!event) /* For IE. */
	event = window.event;
	if (event.wheelDelta) { /* IE/Opera. */
		delta = event.wheelDelta/120;
	/** In Opera 9, delta differs in sign as compared to IE.
	 */
	if (window.opera)
		delta = -delta;
	} else if (event.detail) { /** Mozilla case. */
		/** In Mozilla, sign of delta is different than in IE.
		 * Also, delta is multiple of 3.
		 */
		delta = -event.detail/3;
	}
	/** If delta is nonzero, handle it.
	 * Basically, delta is now positive if wheel was scrolled up,
	 * and negative, if wheel was scrolled down.
	 */
	if (delta) {
		handle(delta);
	}
	/** Prevent default actions caused by mouse wheel.
	 * That might be ugly, but we handle scrolls somehow
	 * anyway, so don't bother here..
	 */
	if (event.preventDefault)
		event.preventDefault();
	event.returnValue = false;
}

/** Initialization code.
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener)
	/** DOMMouseScroll is for mozilla. */
	window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel;

