//variable global para los timeouts de la intro
var to = new Array();

function nuevoAjax() {
        try {
                objetus = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                        objetus= new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                        objetus= false;
                }
        }
        if (!objetus && typeof XMLHttpRequest!='undefined') {
                objetus = new XMLHttpRequest();
        }
		return objetus
}

function stopIntro(){
//borra todos los timeouts
	for (var i=0; i<=to.length; i++){
		clearTimeout(to[i]);
	}
}

function ponePagina(url,title,divContent,divTitle,divLoad){
	stopIntro();
	//creamos el objeto
    _objetus = nuevoAjax();
    _URL_ = url;
    _objetus.open("GET",_URL_,true);
    //una vez enviado los valores inmediatamente llamamos a la propiedad 
    //onreadystatechange
    _objetus.onreadystatechange=function() {
        //dentro de la funcion comprobamos el estado del proceso
        //si es 4 (terminado) pedimos lo que nos han mandado
        if (_objetus.readyState==4){
            //usamos la propiedad responseText para recibir en una cadena
            //lo que nos mandaron
            var doc = _objetus.responseText;
			document.getElementById(divContent).innerHTML = doc;
			document.getElementById(divTitle).innerHTML = title;
			new Effect.Appear(divContent, {duration: 2.0});
			new Effect.Appear(divTitle, {duration: 2.0});
			setTimeout("document.getElementById('"+divLoad+"').style.display='none'",2000);
			if (url == 'secciones/fotos.html'){
				new mainPage();
			}
        }
    }
    _objetus.send(null);
	return true;
}

function cambiaPagina(url,title,divContent,divTitle,divLoad){
	new Effect.Fade(divContent, {duration: 2.0});
	new Effect.Fade(divTitle, {duration: 2.0});
	setTimeout("ponePagina('"+url+"','"+title+"','"+divContent+"','"+divTitle+"','"+divLoad+"')", 2200);
	document.getElementById(divLoad).style.display = 'block';
}

/*function enviaFormContacto(){
	document.getElementById('enviar').innerHTML= '<img src="img/cargando.gif"/> <i>enviando...</i>';
	//cogemos los parámetros:
	var params = '';
	params+= "?nombre=" + document.getElementById('nombre').value;
	params+= "&email=" + document.getElementById('email').value;
	params+= "&grupo=" + document.getElementById('grupo').value;
	params+= "&estilo=" + document.getElementById('estilo').value;
	params+= "&grabacion=" + document.getElementById('grabacion').checked;
	params+= "&mezcla=" + document.getElementById('mezcla').checked;
	params+= "&masterizacion=" + document.getElementById('masterizacion').checked;
	params+= "&arreglos=" + document.getElementById('arreglos').checked;
	params+= "&otros=" + document.getElementById('otros').checked;
	params+= "&temas=" + document.getElementById('temas').value;
	params+= "&observaciones=" + document.getElementById('observaciones').value;
	
	var _URL_ = "php/formcontacto.php" + params;

	//peticion ajax
    _objetus = nuevoAjax();
    _objetus.open("GET",_URL_,true);
    _objetus.onreadystatechange=function() {
        //si estado 4 (terminado) vemos si todo ha ido bien
        if (_objetus.readyState==4){
            var res = _objetus.responseText;
			if (res == "1"){
				var msg = "Formulario enviado correctamente. Recibir&aacute;s una respuesta a la mayor brevedad posible."
			}else{
				var msg = "Ha ocurrido un error. Por favor, cont&aacute;ctanos por teléfono o correo electr&oacute;nico."
			}
			document.getElementById('enviar').innerHTML =  msg;
        }
    }
    _objetus.send(null);
	return true;
}*/

function precargaThumbnails(){
  var thumbnails = {
		"item" :  [
			{ "id" : "img1" , "img" : "fotos/control_thumb.jpg" },
			{ "id" : "img2" , "img" : "fotos/panoramica_thumb.jpg" },
			{ "id" : "img3" , "img" : "fotos/control2_thumb.jpg" },
			{ "id" : "img4" , "img" : "fotos/primerplano_thumb.jpg" },
			{ "id" : "img5" , "img" : "fotos/monitor_thumb.jpg" },
			{ "id" : "img6" , "img" : "fotos/dentropecera_thumb.jpg" },
			{ "id" : "img7" , "img" : "fotos/pecera_thumb.jpg" },
			{ "id" : "img8" , "img" : "fotos/amplibajo_thumb.jpg" },
			{ "id" : "img9" , "img" : "fotos/sinte_thumb.jpg" },
			{ "id" : "img10" , "img" : "fotos/analogico_thumb.jpg" }
		]
	};
	thumbnails.item.each(function(item, i) {
		var image = document.createElement("img");
		image.src = item.img;
		image.style.display = 'none';
		document.getElementById("preload").appendChild(image);
	});
}


/************************ FUNCIONES PARA LA INTRO *****************************/


function introPonImagen(idCapa,src){
	document.getElementById(idCapa).innerHTML = '<img src="'+src+'" border="0"/>';
}
function introPonTexto(idCapa,txt){
	document.getElementById(idCapa).innerHTML = '<span class="textointro">'+txt+'</span>';
}

function introPonElEstudio(){
    _objetus = nuevoAjax();
    _objetus.open("GET","secciones/elestudio.html",true);
    _objetus.onreadystatechange=function() {
        if (_objetus.readyState==4){
            var doc = _objetus.responseText;
			document.getElementById("contenido").innerHTML = doc;
			document.getElementById("tituloseccion").innerHTML = "el estudio";
			new Effect.Appear("tituloseccion", {duration: 2.0});
			new Effect.BlindDown("contenido", {duration:3});
        }
    }
    _objetus.send(null);
	return true;
}

function intro(){
	stopIntro();
	var estruct = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>';
		estruct+= '<td width="60%" height="250px" align="center"><div id="intro1" style="display:none"></div></td>';
		estruct+= '<td align="center" width="40%"><div id="intro2" style="display:none"></div></td></tr></table>';
	document.getElementById('contenido').innerHTML = estruct;
	document.getElementById('tituloseccion').style.display = 'none';
	//document.getElementById('contenido').style.display = 'block';
	new Effect.Appear('contenido',{duration:0.5});
	introPonImagen('intro1','img/portada1.jpg');
	introPonTexto('intro2','arte');
	new Effect.Appear('intro1',{duration:5.0});
	// TimeOuts ('to' es un array de timeouts; será global para poder cancelarlos desde cualquier parte del ámbito global)
	to[0]  = setTimeout('new Effect.Appear("intro2",{duration:5.0})',3000);
	to[1]  = setTimeout('new Effect.Fade("intro1",{duration:3.0})',5500);
	to[2]  = setTimeout('new Effect.Fade("intro2",{duration:3.5})',8000);
	to[3]  = setTimeout('introPonTexto("intro1","y tecnolog&iacute;a")',9000);
	to[4]  = setTimeout('new Effect.Appear("intro1",{duration:5.0})',9500);
	to[5]  = setTimeout('introPonImagen("intro2","img/portada2.jpg")',12000);
	to[6]  = setTimeout('new Effect.Appear("intro2",{duration:5.0})',12500);
	to[7]  = setTimeout('new Effect.Fade("intro1",{duration:3.0})',18000);
	to[8]  = setTimeout('new Effect.Fade("intro2",{duration:3.0})',18000);
	to[9]  = setTimeout('introPonImagen("intro1","img/portada3.jpg")',21500);
	to[10] = setTimeout('introPonTexto("intro2","al servicio de tu m&uacute;sica")',21500);
	to[11] = setTimeout('new Effect.Appear("intro1",{duration:6.0})',22000);
	to[12] = setTimeout('new Effect.Appear("intro2",{duration:6.0})',22000);
	to[13] = setTimeout('new Effect.SwitchOff("contenido")',28000);
	to[14] = setTimeout('new introPonElEstudio()',29000);
}