window.addEventListener?window.addEventListener("load",inicio,false):window.attachEvent("onload",inicio);

var libreria= new Array();
libreria[0]="url(img/cabecera.jpg)";
libreria[1]="url(img/cabeceracopia.jpg)";
libreria[2]="url(img/cabeceratejadosc.jpg)";
libreria[3]="url(img/cabeceranubes.jpg)";
var fondog=new Array();
fondog[0]="url(img/fondocab.jpg)";
fondog[1]="url(img/fondocabcopia.jpg)";
fondog[2]="url(img/fondotejadosc.jpg)";
fondog[3]="url(img/fondonubes.jpg)";


function inicio() {
	n=Math.floor(Math.random()*2);
	document.getElementById("cabecera").style.backgroundImage=libreria[n];
	document.getElementById("cabecera").style.filter = "alpha(opacity=100)"; 
	document.getElementById("cabecera").style.opacity = "0.99"; 
	document.getElementById("cabecera").style.opacity = ".99"; 
	document.getElementById("superiorfade").style.backgroundImage=fondog[n];
	document.getElementById("superiorfade").style.filter = "alpha(opacity=100)"; 
	document.getElementById("superiorfade").style.opacity = "0.99"; 
	document.getElementById("superiorfade").style.opacity = ".99"; 
	c=100;
	a=1.00;
	e=.99;
	setTimeout(menosopacidad,15000);
}
function masopacidad() {
	if(c<100){
		c+=5;
		a+=0.05;
		e+=.05;
		document.getElementById("cabecera").style.filter = ""+"alpha(opacity="+c+")"+"";
		document.getElementById("cabecera").style.opacity =a; 
		document.getElementById("cabecera").style.opacity =e; 
		document.getElementById("superiorfade").style.filter = ""+"alpha(opacity="+c+")"+"";
		document.getElementById("superiorfade").style.opacity =a; 
		document.getElementById("superiorfade").style.opacity =e; 
		setTimeout(masopacidad,50);
		}else{
			c=100;
			a=1.00;
			e=.99;
			setTimeout(menosopacidad,15000);
		}
}

function menosopacidad() {
	if(c>30) {
		c-=5;
		a-=0.05;
		e-=.05;
		document.getElementById("cabecera").style.filter = ""+"alpha(opacity="+c+")"+""; 
		document.getElementById("cabecera").style.opacity =a; 
		document.getElementById("cabecera").style.opacity =e;
		document.getElementById("superiorfade").style.filter = ""+"alpha(opacity="+c+")"+""; 
		document.getElementById("superiorfade").style.opacity =a; 
		document.getElementById("superiorfade").style.opacity =e; 
		setTimeout(menosopacidad,50);
		c++;
	} else {
		if(n<libreria.length-1){
			n++;
		}else{
			n=0;
		}
		document.getElementById("cabecera").style.backgroundImage=libreria[n];
		document.getElementById("superiorfade").style.backgroundImage=fondog[n];
		c=20;
		a=0.20;
		e=.20;
		document.getElementById("cabecera").style.filter = ""+"alpha(opacity="+c+")"+""; 
		document.getElementById("cabecera").style.opacity =a; 
		document.getElementById("cabecera").style.opacity =e; 
		document.getElementById("superiorfade").style.filter = ""+"alpha(opacity="+c+")"+""; 
		document.getElementById("superiorfade").style.opacity =a; 
		document.getElementById("superiorfade").style.opacity =e; 
		setTimeout(masopacidad,50);
	}
	
}
