// JavaScript Document

$(document).ready(function(){
	
	// Para la carga de las imágenes del menú.	
	var itemImg = $(".itemMenu > a > img");
	itemImg.each( function(i) { 
		$.elementReady(this.id, function(){
			this.src = 'Img/' + this.id + 'Menu.jpg'; // Nombre del fichero = id + Menu.jpg
		});
	});
	

	
	// Para la carga de las páginas
	var emi = "#menu a";							//Emisor
	var rec = "#contenidos";						//Receptor
	var src = "iconoPrecarga.gif";					//Imagen de precarga
	var iid = "loading";							//Id de la precarga
	var pre = "<img src='ImgInt/" + src + "' id='" + iid + "'" + " style='display:block; width:25px; height:25px;' />";	//Objeto precarga
	var spe = "slow";								//Velocidad del efecto
	$(emi).each(function(){
		var href = $(this).attr("href");			//Guardamos el valor de href de cada enlace.
		$(this).click(function(){					//Cargamos en rec el contenido de cada href y le damos efectos.
			//$(rec).hide().prepend(pre).load(href, function() {$("#"+iid).remove();$(this).fadeIn(spe)});
			$(rec).prepend(pre).load(href, function() {$("#"+iid).remove();$(this).fadeIn(spe)});
			return false;							//Para que no se redireccione.
		});
		$("#clipMenu .itemMenu > a[href=" + "'" + href + "']").bind("mouseover", function(e) {
			$("#clipMenu .itemMenu > a[href=" + "'" + href + "']" + " > img").animate({"opacity":1}, 250);
		});
		$("#clipMenu .itemMenu > a[href=" + "'" + href + "']").bind("mouseout", function(e) {
			$("#clipMenu .itemMenu > a[href=" + "'" + href + "']" + " > img").animate({"opacity":.6}, 1000);
		});
	});
	
	
	// Para recargar la pag principal.
	
	var logo = "#logo";
	
	$(logo).bind("click", function(e) {
		window.location="index.php";
		//return false;//Para que no se redireccione.
	});
	
	$(logo).bind("mouseover", function(e) {
		$(this).css({"cursor":"pointer"});
		$(this).css({"background-color":"#ff0000"});
	});
	
	$(logo).bind("mouseout", function(e) {
		$(this).css({"cursor":"default"});
		$(this).css({"background-color":"#000"});
	});
	
	
	
	// Para el menú principal desplegable
	
	var menu = "#menu";
	var estadoMenu = false;
	var logoImg = "#logo > img";
	var menuBoton = "#menuBoton";
	var contenidos = "#contenidos";
	
	$(menuBoton).bind("click", function(e) {
		if(estadoMenu == false) {
			$(menu).animate({"top":"0px"}, 200, "easeOutSine");
			$(logoImg).animate({"left":"0px"}, 400, "easeOutSine");
			$(this).css({"background-image":"url(ImgInt/botonMenuSubirAni.gif)", "background-repeat":"no-repeat"});
			$(this).animate({"top":"225px"}, 200, "easeOutSine");
			$(this).animate({"height":"25px"}, 200, "easeOutSine");
			$(contenidos).animate({"top":"275px"}, 200, "easeOutSine");
			estadoMenu = true;
		} else {
			$(menu).animate({"top":"-225px"}, 100, "easeOutSine");
			$(logoImg).animate({"left":"25px"}, 200, "easeOutSine");
			$(this).css({"background-image":"url(ImgInt/botonMenuBajarAni.gif)", "background-repeat":"no-repeat"});
			$(this).animate({"top":"250px"}, 100, "easeOutSine");
			$(this).animate({"height":"75px"}, 200, "easeOutSine");
			$(contenidos).animate({"top":"125px"}, 100, "easeOutSine");
			estadoMenu = false;
		}
	});
	
	$(menuBoton).bind("mouseover", function(e) {
		$(this).css({"cursor":"pointer"});
		/*
		if (estadoMenu == false) {
			$(this).css({"background-position":"0 -6px"});
		} else {
			$(this).css({"background-position":"0 6px"});
		}
		*/
	});
	
	$(menuBoton).bind("mouseout", function(e) {
		$(this).css({"cursor":"default"});
		//$(this).css({"background-position":"0 0"});
	});
	
	
	// Para el menú deslizable
	
	var clipMenu = "#clipMenu";
	var retroceder ="#retroceder";
	var avanzar ="#avanzar";

	$(avanzar).bind("click", function(e) {
		$(clipMenu).scrollTo('+=175px', {axis:'y', easing:'easeOutSine', duration:250});
	});
	$(retroceder).bind("click", function(e) {
		$(clipMenu).scrollTo('-=175px', {axis:'y', easing:'easeOutSine', duration:250});
	});
	
	$(avanzar).bind("mouseover", function(e) {
		$(this).css({"cursor":"pointer"});
		$(this).css({"background-color":"#666"});
		if (estadoMenu == false) {
			$(this).css({"background-position":"0 3px"});
		} else {
			$(this).css({"background-position":"0 -3px"});
		}
	});
	
	$(avanzar).bind("mouseout", function(e) {
		$(this).css({"cursor":"default"});
		$(this).css({"background-color":"#999"});
		$(this).css({"background-position":"0 0"});
	});
	
	$(retroceder).bind("mouseover", function(e) {
		$(this).css({"cursor":"pointer"});
		$(this).css({"background-color":"#666"});
		if (estadoMenu == false) {
			$(this).css({"background-position":"0 -3px"});
		} else {
			$(this).css({"background-position":"0 3px"});
		}
	});
	
	$(retroceder).bind("mouseout", function(e) {
		$(this).css({"cursor":"default"});
		$(this).css({"background-color":"#999"});
		$(this).css({"background-position":"0 0"});
	});
	
	
	// Para los botones de sección.
	
	var disenyo = "#botonDisenyo";
	var pintura = "#botonPintura";
	var foto = "#botonFoto";
	var contacto = "#botonContacto";
	
	$(disenyo).bind("click", function(e) {
		$(clipMenu).scrollTo('#seccionDisenyo', {axis:'y', easing:'easeOutSine', duration:250});
	});
	
	$(pintura).bind("click", function(e) {
		$(clipMenu).scrollTo('#seccionPintura', {axis:'y', easing:'easeOutSine', duration:250});
	});
	
	$(foto).bind("click", function(e) {
		$(clipMenu).scrollTo('#seccionFoto', {axis:'y', easing:'easeOutSine', duration:250});
	});
	
	$(contacto).bind("click", function(e) {
		$(rec).prepend(pre).load("contacto.html", function() {$("#"+iid).remove();$(this).fadeIn(spe)});
			return false;//Para que no se redireccione.
	});
	$(disenyo).bind("mouseover", function(e) {
		$(this).css({cursor:"pointer", color:"#000", backgroundColor:"#FFFF00"});
		//$(this).animate({color:"#000", backgroundColor:"#FFFF00"}, 500);
	});
	
	$(disenyo).bind("mouseout", function(e) {
		$(this).css({cursor:"default", color:"#FFFF00", backgroundColor:"#000"});
		//$(this).animate({color:"#FFFF00", backgroundColor:"#000"}, 1000);
	});
	
	$(pintura).bind("mouseover", function(e) {
		$(this).css({cursor:"pointer", color:"#000", backgroundColor:"#FF3399"});
	});
	
	$(pintura).bind("mouseout", function(e) {
		$(this).css({cursor:"default", color:"#FF3399", backgroundColor:"#000"});
	});

	$(foto).bind("mouseover", function(e) {
		$(this).css({cursor:"pointer", color:"#000", backgroundColor:"#66CCFF"});
	});
	
	$(foto).bind("mouseout", function(e) {
		$(this).css({cursor:"default", color:"#66CCFF", backgroundColor:"#000"});
	});
	$(contacto).bind("mouseover", function(e) {
		$(this).css({cursor:"pointer", color:"#000", backgroundColor:"#99CC00"});
	});
	
	$(contacto).bind("mouseout", function(e) {
		$(this).css({cursor:"default", color:"#99CC00", backgroundColor:"#000"});
	});
});