
	window.addEvent("domready", function() {

		initWeb();
		slideIndex();
		preparaSlideTop();
		preparaSlideCuerpo();
		reservas();
		fadeTabla();
		fadePromos();
		$$("#noticias li:last-child").setStyle("margin-right", "-3px");
		$$("#secciones li:first-child").setStyle("border", "none");
		
	});
	
	function fadePromos()
	{
		if($("listaAvisos")) 
		{
			$$("#listaAvisos li").each(function(li) {
				if(!li.getElements("h2").length) li.dispose();
			});
			
			jQuery('#listaAvisos').innerfade({
				animationtype: 'fade',
				speed: 5000,
				timeout: 6500,
				height: 27,
				containerheight: 27
			});
		}
	}
	
	function initWeb()
	{
		$$(".intro").fade("hide");
		$$("#bodyIndex #wrapper").fade("hide");
		animation = function() { $$(".intro").fade("out"); $$('#imagen1').fade('in'); };
		animation.delay(2000, animation);
		
		animation = function() { $$(".intro").fade("out"); $$('#imagen2').fade('in'); };
		animation.delay(5000, animation);
		
		animation = function() { $$(".intro").fade("out"); $$('#imagen3').fade('in'); };
		animation.delay(8000, animation);
		
		animation2 = function() { $$(".intro").fade("out"); $$("#bodyIndex #wrapper").fade('in'); };
		animation2.delay(11000, animation2);
		$$(".reservas #contacto").fade("hide");
	}
	
	function reservas()
	{
		
		$$("#paso2").addEvent("click", function() {
			//event.preventDefault();
			
			form2 = this.getParent().getParent().getParent("form");
			var fecha = form2.fecha.value;
			var hora = form2.hora.value;
			var personas = form2.personas.value;
			var fumador = form2.fumador.value;
			var nombre = form2.nombre.value;
			
			$$("#contacto #fecha").set("text", fecha);
			$$("#contacto #hora").set("text", hora);
			$$("#contacto #comensales").set("text", personas);
			$$("#contacto #fumador").set("text", fumador);
			$$("#contacto #nombre").set("text", nombre);
			
			$$(".reservas #contacto").fade("in");
		});
		
	}
	
	function slideIndex()
	{
		if($("transicion")) 
		{
			$$("#transicion li").each(function(li) {
				if(!li.getElements("img").length) li.dispose();
			});
	
			jQuery('#transicion').innerfade({
				animationtype: 'fade',
				speed: 5000,
				timeout: 5000
			});
		}
	}
	
	function preparaSlideTop()
	{
		$$("#imagenesSeccion li img").fade(.7);
		$$("#imagenesSeccion li:last-child").fade(1);
		$$("#imagenesSeccion li:last-child").setStyle("border", "none");
			
		$$("#imagenesSeccion li img").addEvent("mouseover", function(event) {
			this.setStyle("border-bottom","4px solid red");
		});
		
		$$("#imagenesSeccion #galeria").addEvent("mouseover", function(event) {
			this.setStyle("border-bottom","none");
		});
		
		$$("#imagenesSeccion li img").addEvent("mouseleave", function(event) {
			this.setStyle("border-bottom","none");
		});
		
		
		$$("#imagenesSeccion li img").addEvent("click", function(event) {
			var clase = this.getParent("li").className;
			$$("#foto li").fade("out");
			$$("#foto ." + clase).fade("in");
			$$("#imagenesSeccion li img").fade(.7);
			this.fade(1);
			
		});
	}
	
	function fadeTabla()
	{
		$$("table th").addEvent("click", function() {
			var clase = this.className;
			$$("#imagenesCuerpo li").fade("out");
			$$("#imagenesCuerpo li." + clase).fade("in");
		});
	}
	
	function preparaSlideCuerpo()
	{
		window.currentImage = 0;
		
		$$("#imagenesCuerpo li").fade("out");
		$$("#imagenesCuerpo li:last-child").fade("in");
		
		$$("#anterior").addEvent("click", function(event) {
			if(window.currentImage < $$("#imagenesCuerpo li").length -1 )
				window.currentImage++;
			$$("#imagenesCuerpo li").fade("out");
			$$("#imagenesCuerpo li")[window.currentImage].fade("in");
		});
		
		$$("#siguiente").addEvent("click", function(event) {
			if(window.currentImage > 0)
				window.currentImage--;
			$$("#imagenesCuerpo li").fade("out");
			$$("#imagenesCuerpo li")[window.currentImage].fade("in");
		});
	}