/*
Hola! 
puedes configurar aqui donde se encuentran las imagenes de fondo y la lista de los fondos. 
La lista de los fondos no debe tener nombres de imagen con accentos o ņ, esto puede dar errores.
Los nombres de archivo tienen que separarse con punto y comma ( ; ).
860 y 660 son los tamaņos de los gif de fondo: 860 x 660. 
*/		
		
		/* configuracion */
		var carpetaFondos 	= 'images/';			//carpeta relativa desde index.html, puede ser con http:// si cambias de directorio
		var listaFondos 		= 'listaFondos.txt';		//archivo con la lista de imagenes de fondo, relativo desde index.html	
		var elementoFondos	= 'elementoFondo';
		var ventanaAncho 	= 860;				//px del tamaņo de los fondos
		var ventanaAlto 		= 660;
		var cambiarVentana 	= true;				//true:activado , false:deshabilita el cambio de tamaņo de ventana
		/*fin de configuracion*/
			
			function changeBackgroundImage () {
				lista = l(listaFondos);
				lista_arr = lista.split(";");
				max = random(lista_arr.length);
				body = document.getElementById(elementoFondos);
				document.body.style.backgroundImage = 'url('+carpetaFondos+lista_arr[max]+')';
				if(getCookie('lastImage') == max+''){
					changeBackgroundImage();
				}
				setCookie('lastImage',max+'',1);
			}
			
			function random (max){if(max==undefined){max=100;}return Math.floor(Math.random()*max);}
			
			function l(url) {var req = false;  if (window.XMLHttpRequest) {try {req = new XMLHttpRequest();} catch (e) {req = false;}} else if (window.ActiveXObject) {  try {req = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {try {req = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {req = false;}}}if (req) {req.open('GET', url, false);req.send(null);return(req.responseText);} else { alert("Javascript no esta activado!"); }}
			
			function resize_window(xto,yto) {
				window.moveTo(0,0);
				window.resizeTo(xto, yto);
				wless = xto - pageWidth();
				hless = yto - pageHeight();
				window.resizeTo(xto+wless, yto+hless);
			}
			
			function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} 
			function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 
			
			function setCookie(c_name,value,expiredays){
				var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
				document.cookie=c_name+ "=" +escape(value)+
				((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
			}
			function getCookie(c_name){
				if (document.cookie.length>0){
				  var c_start=document.cookie.indexOf(c_name + "=");
				  if (c_start!=-1){
				    c_start=c_start + c_name.length+1;
				    var c_end=document.cookie.indexOf(";",c_start);
				    if (c_end==-1) c_end=document.cookie.length;
				    return unescape(document.cookie.substring(c_start,c_end));
				    }
				  }
				return "";
			}
			
			
			function boot(){
				changeBackgroundImage();
				if(cambiarVentana){
					resize_window(ventanaAncho,ventanaAlto);
				}
			}
		
		boot();