$(document).ready(function(){
	
	$('ul#myRoundabout').roundabout({
        startingChild: 0 // the third box, so: 0, 1, *2*
     });
		$('#player_audio').click(function() {
			  if (this.paused == false) {
			      this.pause();
			      alert('music paused');
			  } else {
			      this.play();
			      alert('music playing');
			  }
			});
		setTimeout("movercontact()",1000);
		
		setTimeout("showRayo1()",10000);
		setTimeout("showRayo2()",15000);
		setTimeout("showRayo3and4()",25500);
		setTimeout('fantasma1()',5000);
		setTimeout('fantasma3()',10000);
		setTimeout('changeHouse1()',2000);
		setTimeout('mueveojos()',1000);
		$('.logo').click(function() {
			  window.location.href='index.php';
		});

		$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  
		  
	    $("ul.topnav li.espectaculos").mouseover(function() { //When trigger is clicked...  
	  
	        //Following events are applied to the subnav itself (moving subnav up and down)  
	        $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click  
	  
	        $(this).parent().hover(function() {  
	        }, function(){  
	            $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up  
	        });  
	  
	        //Following events are applied to the trigger (Hover events for the trigger)  
	        }).hover(function() {  
	            $(this).addClass("subhover"); //On hover over, add class "subhover"  
	        }, function(){  //On Hover Out  
	            $(this).removeClass("subhover"); //On hover out, remove class "subhover"  
	    });  
	    

	    
		$('#neblina').pan({fps: 30, speed: 1, dir: 'left', depth:5});
		$('#cinta').pan({fps: 30, speed: 1, dir: 'left', depth:5});
		$('#mujer').pan({fps: 30, speed: 1, dir: 'left', depth:5});
		$('#plato').pan({fps: 30, speed: 1, dir: 'left', depth:5});
		$('#humo').pan({fps: 30, speed: 0.3, dir: 'up', depth:5});
		$('#luna').animate({'top': -'40', 'left': '405'}, 50000, function(){})
		
		$(".logo").rotate({animateTo:45});
		$(".logo").rotate({ 
			   bind: 
			     { 
			        mouseover : function() { 
			            $(this).rotate({animateTo:45});
			        },
			        mouseout : function() { 
			            $(this).rotate({animateTo:0})
			        }
			     } 
			   
			});
});


	function mueveojos(){
	    $('.ojos').animate({'margin-top': '-=5', 'margin-left': '+=10'}, 5000, function() {
	    	$('.ojos').animate({'margin-top': '+=5', 'margin-left': '-=10'}, 5000, function() {
		    	$('.ojos').animate({'margin-left': '+=10'}, 5000, function() {
			    	$('.ojos').animate({'margin-left': '-=5'}, 5000, function(){
			    		$('.ojos').animate({'margin-left': '-=5'}, 5000, function(){
			    			setTimeout('mueveojos()',3000);
			    		});
			    	});
			    });
		    });
	    });
	    
    }

	function movercontact(){
		$('#contactable_inner').animate({'margin-top': '+=10'}, 100, function(){
    		$('#contactable_inner').animate({'margin-top': '-=10'}, 100, function(){
    			setTimeout("movercontact()",5000)});
    		});
	}
	
	function changeHouse1(){
		$('#house').addClass('house2');
		$('#house').removeClass('house');
		setTimeout('changeHouse2()',6000);
	}
	
	function changeHouse2(){
		$('#house').addClass('house3');
		$('#house').removeClass('house2');
		setTimeout('changeHouse3()',3000);
	}
	
	function changeHouse3(){
		$('#house').addClass('house4');
		$('#house').removeClass('house3');
		setTimeout('changeHouse4()',5000);
	}
	
	function changeHouse4(){
		$('#house').addClass('house');
		$('#house').removeClass('house4');
		setTimeout('changeHouse1()',2000);
	}

	
	function sangrar(){
		$('.gota-sangre').animate({
		    marginTop: "200",
		    opacity: 0.0,
		    marginLeft: "20px"
			}, 1500, 'linear', function() {
				$('.gota-sangre').css('margin-left','20px');
                $('.gota-sangre').css('margin-top','50px');
                $('.gota-sangre').css('opacity','1');
			  });

	}
	
	function fantasma1(){
		$('.fantasma1').animate({
			opacity: 1,
		    marginTop: '-100px',
		    marginLeft: '450px'
		}, 5000, 'linear', function() {
			$('.fantasma1').css('opacity','0');
		    $('.fantasma1').css('margin-top','247px');
		    $('.fantasma1').css('margin-left','330px');
		    setTimeout('fantasma2()',10000);
		  });
	}
	
	function fantasma2(){
		$('.fantasma1').animate({
			opacity: 1,
		    marginTop: '-100px',
		    marginLeft: '200px'
		}, 5000, 'linear', function() {
			$('.fantasma1').css('opacity','0');
		    $('.fantasma1').css('margin-top','247px');
		    $('.fantasma1').css('margin-left','330px');
		    setTimeout('fantasma1()',10000);
		  });
	}
	
	function fantasma3(){
		$('.fantasma2').animate({
			opacity: 1,
		    marginTop: '-100px',
		    marginLeft: '100px'
		}, 5000, 'linear', function() {
			$('.fantasma2').css('opacity','0');
		    $('.fantasma2').css('margin-top','247px');
		    $('.fantasma2').css('margin-left','380px');
		    setTimeout('fantasma4()',10000);
		  });
	}
	
	function fantasma4(){
		$('.fantasma2').animate({
			opacity: 1,
		    marginTop: '-100px',
		    marginLeft: '400px'
		}, 5000, 'linear', function() {
			$('.fantasma2').css('opacity','0');
		    $('.fantasma2').css('margin-top','247px');
		    $('.fantasma2').css('margin-left','380px');
		    setTimeout('fantasma3()',10000);
		  });
	}
	
	$(document).ready(function(){
		makeSynd();
	});

	function makeSynd(){
		$(".guestbookSynd").jCarouselLite({  
	        vertical: true,  
	        visible: 3,  
	        auto:7000,  
	        mouseWheel: true,
	        speed:1000  
	    }); 
	}

	function validateform(){
            var name = $('#guestbookName').val();
            var email = $('#guestbookMail').val();
            var mensaje = $('#guestbookMsg').val();
            var ck = false;
            var error = '';
            
            $('#guestbookName').css('border','none');
            $('#guestbookMail').css('border','none');
            $('#guestbookMsg').css('border','none');

            if(name.length < 4){
                error = '<br>-Nombre muy corto';
                $('#guestbookName').css('border','solid 2px #f00');
                ck = true;
            }
            if(!validarEmail(email)){
                error += '<br>-Mail invalido';
                $('#guestbookMail').css('border','solid 2px #f00');
                ck = true;
            }
            if(mensaje.length < 20){
                error += '<br>-Mensaje muy corto';
                $('#guestbookMsg').css('border','solid 2px #f00');
                ck = true;
            }
            
            if(mensaje.length > 1024){
                error += '<br>-Mensaje muy largo';
                $('#guestbookMsg').css('border','solid 2px #f00');
                ck = true;
            }

            if(!ck){
                $('#guestbookName').css('border','none');
                $('#guestbookMail').css('border','none');
                $('#guestbookMsg').css('border','none');
                $('.printErrors').html('');
                return true;
            }   
            else{
                $('.printErrors').html('Por favor, verifique los siguientes errores: '+error);
                return false;
            }
                
        }   

	function validateReserva(){
        var titular = $('#nombre').val();
        var cantidad = $('#cantidad').val();
        var telefono = $('#telefono').val();
        var reservamail = $('#mail').val();
        var detalle = $('#detalles').val();
        var datepicker = $('#datepicker').val();
        
        var rk = false;
        var reservaerror = '';
        $('#datepicker').css('border','none');
        $('#nombre').css('border','none');
        $('#cantidad').css('border','none');
        $('#telefono').css('border','none');
        $('#mail').css('border','none');
        $('#detalles').css('border','none');
        
        if(datepicker.length < 10){
            error = '<br>-Fecha de reserva incorrecta';
            $('#datepicker').css('border','solid 2px #f00');
            rk = true;
        }
        if(titular.length < 4){
            error = '<br>-Nombre de Titular muy corto';
            $('#nombre').css('border','solid 2px #f00');
            rk = true;
        }
        if(cantidad.length < 1){
            error = '<br>-Cantidad incorrecta de Personas ';
            $('#cantidad').css('border','solid 2px #f00');
            rk = true;
        }
        if(telefono.length < 6){
            error = '<br>-Telefono muy corto ';
            $('#telefono').css('border','solid 2px #f00');
            rk = true;
        }
        if(!validarEmail(reservamail)){
            error += '<br>-Mail invalido';
            $('#mail').css('border','solid 2px #f00');
            rk = true;
        }
        if(detalle.length < 20){
            error += '<br>-Detalles de reserva muy corto';
            $('#detalles').css('border','solid 2px #f00');
            rk = true;
        }
        
        if(detalle.length > 1024){
            error += '<br>-Detalles de reserva muy largo';
            $('#detalles').css('border','solid 2px #f00');
            ck = true;
        }

        if(!rk){
        	 $('#datepicker').css('border','none');
        	 $('#nombre').css('border','none');
             $('#cantidad').css('border','none');
             $('#telefono').css('border','none');
             $('#mail').css('border','none');
             $('#detalles').css('border','none');
            $('.printErrorsReserva').html('');
            return true;
        }   
        else{
            $('.printErrorsReserva').html('Por favor, verifique los siguientes errores: '+error);
            return false;
        }
            
    }  
	
	
        function validarEmail(valor) {
            if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test(valor)){
                return (true);
            } else {
                return (false);
            }
        }
        
        function showRayo1(){
        	jQuery('#rayo1').show()
        	setTimeout("jQuery('#rayo1').hide()",50);
        	setTimeout("jQuery('#rayo1').show()",200);
        	setTimeout("jQuery('#rayo1').hide()",600);
        	setTimeout("showRayo1()",10000);
        }
        
        function showRayo2(){
        	jQuery('#rayo2').show()
        	setTimeout("jQuery('#rayo2').hide()",50);
        	setTimeout("jQuery('#rayo2').show()",200);
        	setTimeout("jQuery('#rayo2').hide()",600);
        	setTimeout("showRayo2()",10000);
        }
        
        function showRayo3and4(){
        	jQuery('#rayo3').show()
        	setTimeout("jQuery('#rayo3').hide()",50);
        	setTimeout("jQuery('#rayo3').show()",200);
        	setTimeout("jQuery('#rayo3').hide()",600);
        	jQuery('#rayo4').show()
        	setTimeout("jQuery('#rayo4').hide()",50);
        	setTimeout("jQuery('#rayo4').show()",200);
        	setTimeout("jQuery('#rayo4').hide()",600);
        	setTimeout("showRayo3and4()",10000);
        }
