jQuery(document).ready(function()
{	
	
	
	// INITIALIZE DROPDOWN MENU
	jQuery('.dd-menu li:has(ul) > a').addClass('dd-submenu-title').append('<span class="dd-arrow"></span>');	
	jQuery('.dd-menu li').hover(function(){	
			// HOVER IN HANDLER
	
			jQuery('ul:first', this).css({visibility: "visible",display: "none"}).slideDown(250);									
			var path_set = jQuery(this).parents('.dd-menu li').find('a:first');
			jQuery(path_set).addClass('dd-path');						
			jQuery('.dd-menu li a.dd-path').not(path_set).removeClass('dd-path');
			
		},function(){			
			// HOVER OUT HANDLER
		
			jQuery('ul:first', this).css({visibility: "hidden"});			
	});
	jQuery('.dd-menu').hover(function() {
			// HOVER IN HANDLER
			
		}, function() {			
			// HOVER OUT HANDLER
		
			jQuery('a.dd-path', this).removeClass('dd-path');			
	});
	
	
		
	// REPLACE SUBMIT BUTTONS WITH SOMETHING EASIER TO STYLE:)
	jQuery('input[type=submit]').each(function() {		
	
		var val = jQuery(this).val();
		var a = jQuery('<a class="button dark"><span>' + val + '</span></a>');
		var input = jQuery(this);
		
		input.after(a);
		input.hide();
		
		a.click(function() {			
			input.trigger('click');
		});
	});
	
	jQuery('input[type=reset]').each(function() {		
	
		var val = jQuery(this).val();
		var a = jQuery('<a class="button red"><span>' + val + '</span></a>');
		var input = jQuery(this);
		
		input.after(a);
		input.hide();
		
		a.click(function() {			
			input.trigger('click');
		});
	});
	
	//ENVIO EMAIL

	jQuery("#contactar").click(function() {

		// validate and process form
		// first hide any error messages
		//$('.error').hide();
		var enviar=true;
		var error="";

			
		var name = $("input#name").val();
		if (name == "") {
		  enviar=false;
		  error=error+'El campo nombre debe rellenarse\n';
		  $("input#realname").focus();
		  alert(error);
		  return false;
		}
		
		var email = $("input#email").val();
		if (email == "") {
		  enviar=false;
		  error=error+'El campo email debe rellenarse\n';
		  $("input#email").focus();
		  alert(error);
		  return false;
		}
		
		var message = $("textarea#message").val();
		if (message == "") {
		  enviar=false;
		  error=error+'El campo mensaje debe rellenarse\n';
		  $("input#comments").focus();
		  alert(error);
		  return false;
		}
		
		var dataString = 'name='+ name + '&email=' + email + '&message=' + message;
		//alert (dataString);return false;
		
		// Enviamos el formulario usando AJAX
		$.ajax({
			type: "POST",
			url: "../php/mail.php",
			data: dataString,
			// Mostramos un mensaje con la respuesta de PHP
			success:function(msj){
				if ( msj == 1 ){
					$('#result1').html("<h3>Formulario Enviado<br/>Correctamente</h3><p>En breve nos pondremos en Contacto con Usted.</p>");		
				}
				else{
					$('#result1').html("<h3>Se ha producido un error: "+msj+"</h3><p>Intente contactar con nosotros en otro momento.</p>");
				}
			}
     	});
    	return false;
	});
	
	//ENVIO EMAIL

	jQuery("#contactar1").click(function() {

		// validate and process form
		// first hide any error messages
		//$('.error').hide();
		var enviar=true;
		var error="";

			
		var name = $("input#name1").val();
		if (name == "") {
		  enviar=false;
		  error=error+'El campo nombre debe rellenarse\n';
		  $("input#realname").focus();
		  alert(error);
		  return false;
		}
		
		var email = $("input#email1").val();
		if (email == "") {
		  enviar=false;
		  error=error+'El campo email debe rellenarse\n';
		  $("input#email").focus();
		  alert(error);
		  return false;
		}
		
		var website = $("input#website1").val();
		if (website == "") {
		  enviar=false;
		  error=error+'El campo teléfono debe rellenarse\n';
		  $("input#phone").focus();
		  alert(error);
		  return false;
		}
		
		var message = $("textarea#message1").val();
		if (message == "") {
		  enviar=false;
		  error=error+'El campo mensaje debe rellenarse\n';
		  $("input#comments").focus();
		  alert(error);
		  return false;
		}
		
		var dataString = 'name='+ name + '&email=' + email + '&website='+ website + '&message=' + message;
		//alert (dataString);return false;
		
		// Enviamos el formulario usando AJAX
		$.ajax({
			type: "POST",
			url: "../php/mail.php",
			data: dataString,
			// Mostramos un mensaje con la respuesta de PHP
			success:function(msj){
				if ( msj == 1 ){
					$('#result').html("<h2>Formulario Enviado<br/>Correctamente</h2><p>En breve nos pondremos en Contacto con Usted.</p>");		
				}
				else{
					$('#result').html("<h2>Se ha producido un error: "+msj+"</h2><p>Intente contactar con nosotros en otro momento.</p>");
				}
			}
     	});
    	return false;
	});

	
	// INITIALIZE HOME SLIDER
	$("#big-slider").jCarouselLite({
		btnNext: "#next",
		btnPrev: "#prev",
		easing: "backin",
		visible: 1,
		vertical: true,
		auto: 4000,
		speed: 500
	});
	
	$("#small-slider").jCarouselLite({
		btnNext: "#next",
		btnPrev: "#prev",
		easing: "backin",
		visible: 1,
		auto: 4000,
		speed: 500
	});
	
	$("#menu-slider").jCarouselLite({
		btnNext: "#next-menu-slider",
		btnPrev: "#prev-menu-slider",
		visible: 4,
		auto: 0,
		speed: 500
	});
	
	
	// BOOK A TABLE DATE PICKER
	$(function() {
	$("#datepicker").datepicker({
		showOn: 'button',
		buttonImage: 'js/jquery-ui-1.8.2.datepicker/smoothness/images/calendar.gif',
		buttonImageOnly: true
	});
	
	});
	
	// BOOK A TABLE UNIFORM
	$(function(){
        $("select").uniform();
      });

	
	//fancy box
	$(function() {
		$("a.lightbox").fancybox({
			'titleShow'		: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});	
	});
	   
});

