$(document).ready(function(){

/* ------------------------------------------ Footer Newsletter signup ------------------------------------------ */

  $(function() {
    $('#footer_subForm').submit(function(e) {
      e.preventDefault();
            
      // Grab form action
      var formAction = this.action;
      
      // Hacking together id for email field
      // Replace the xxxxx below:
      // If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
      var id = "xxxxx";
      var emailId = id + "-" + id;
      
      // Serialize form values to be submitted with POST
      var str = $(this).serialize();
      
      // Add form action to end of serialized data
      // CDATA is used to avoid validation errors
      //<![CDATA[
      var serialized = str + "&action=" + formAction;
      // ]]>
      
      // Submit the form via ajax
      $.ajax({
        url: "proxy.php",
        type: "POST",
        data: serialized,
        dataType: 'html',
        success: function(data){
          // Server-side validation
          if (data.search(/invalid/i) != -1) {
            return false;
          }
          else
          {
			 $('#footer_newsletter_active').fadeOut();
			 $('#footer_newsletter_success').fadeIn();
			 _gaq.push(['_trackPageview','/newsletter_success']);
          }
        }
      });
    });
  });
  
  	$('#qhtllh-qhtllh').focus(function() {
		if($(this).val() == this.defaultValue)
		$(this).val("");
	});

	$('#qhtllh-qhtllh').blur(function() {
		if($(this).val() == "")
		$(this).val(this.defaultValue);
	});

	$("#footer_subForm").validate();


/* ------------------------------------------ Home Gallery ------------------------------------------ */

	$('#home_gallery').cycle({
		fx: 'fade'
	});
	
/* ------------------------------------------ Leftbar ------------------------------------------ */

	$('#leftbarbook_wrapper').hover(function() {
		$('#leftbar_bookinfo').fadeIn(150);	
	}, function() {
		$('#leftbar_bookinfo').fadeOut(100);	
	});

  	$('#leftbar_nights').focus(function() {
		if($(this).val() == this.defaultValue)
		$(this).val("");
	});

	$('#leftbar_nights').blur(function() {
		if($(this).val() == "")
		$(this).val(this.defaultValue);
	});


	$("#leftbar_date").datepicker({
		showButtonPanel: true,
		currentText: '',
		closeText: 'Close',
		minDate: 0,
		dateFormat: 'dd/mm/yy',
		//onClose: function(date) { 
		//	$("#bookbar").validate().element( "#bookbar_NEW" ) 
		//},
		onSelect: function(dateText,picker) {
		   $('#bookDay').val( dateText.split(/\//)[0] );
		   $('#bookMonth').val( dateText.split(/\//)[1] );
		   $('#bookYear').val( dateText.split(/\//)[2] );
		}   
	});

	

/* ------------------------------------------ Suites ------------------------------------------ */

	$('#gallery_left').cycle({
		fx: 'fade',
		timeout: 10000
	});
	$('#gallery_right').cycle({
		fx: 'fade',
		timeout: 5000
	});


/* ------------------------------------------ Fancybox ------------------------------------------ */


	$(".package_popup_link").fancybox({
		showCloseButton: false,
		overlayColor: '#000',
		overlayOpacity: 0.6,
		padding: 0	
	});
	
	$(".image_popup_link").fancybox({
		overlayColor: '#000',
		overlayOpacity: 0.6,
		padding: 0	
	});
	
/* ------------------------------------------ Contact Form ------------------------------------------ */

	$("#contact_form").validate({
		rules: {
			contact_name: "required",
			contact_email: {
				required:true,
				email:true
			},
			contact_msg: "required"
		}
	});

	$('#contact_form').ajaxForm(function() { 
    	$('#contact_success').fadeIn(500, function(){
			
			if ( $('#contact_subscribe').attr('checked') ) { 
			_gaq.push(['_trackPageview','/newsletter_success']);
			};
			
			$('#contact_name, #contact_email, #contact_tel, #contact_msg').val();
			_gaq.push(['_trackPageview','/contact_success']);
		});
    });

	

});
