$(function() {


 $(".yacht-details a").bigTarget();
 $(".yachts-listing a").bigTarget();


/* $('#menu').kwicks({
						min : 150,
						max: 516, 
						sticky: true
						
					});
					*/


           
      $('#menu .count-1 div').fadeIn();
/*      
     $("#menu").jKwick({min: 146, max: 512, mid: 237, speed: 200});
          
       $('#menu .count-1').hover(function() {
         	$('#menu .count-2 div').hide();
         	$('#menu .count-4 div').hide();
         });
     
        $('#menu .count-2').hover(function() {
         	$('#menu .count-1 div').hide();
         	$('#menu .count-3 div').hide();
        	 });
      	 $('#menu .count-3').hover(function() {
         	$('#menu .count-2 div').hide();
         	$('#menu .count-4 div').hide();
         });
         
      
         
      	 $('#menu .count-4').hover(function() {
         	$('#menu .count-1 div').hide();
         	$('#menu .count-3 div').hide();
         });
         

       
         
      
    	 $('#menu li').width(146);
    	$('.count-1').width(512);
    	
    	
    	
				
		  $('#nav').hover(function() {
		  	$('#menu .count-1 div').fadeIn();
    			
	  	 });
	  	 
	  	 
	  	 */
	  	 
	  	   $('#home-main').hover(function() {
	  	   	$('#menu').fadeIn();
		  	/*$('#menu .count-1 div').fadeIn();
  			$('#menu li').width(146);
    		$('#menu li.count-1').width(512);
    		*/
    			
	  	 });
	  	 
	  	 
	  	 
	  	 $('#menu li').hover(function() {
    		$(this).find('div').fadeIn();
    		$("#menu li").not(this).find('div').hide("slow");
    	},
    	function () {
    	
    		$("li:not(.active)").find('div').hide();
		});
	  	 
	  	 
	  	 
	  	 $('.side-gallery a:nth-child(even)').css('margin-right','0');
	     $('#home-mini-gallery a:nth-child(even)').css('margin-right','0');
	  	 $('#home-mini-gallery img:nth-child(even)').css('margin-right','0');
	  	 $('#photo-gallery-side-right a:nth-child(even)').css('margin-right','0');
	  	 $('#side-gallery li:nth-child(even)').css('margin-right','0');
	  	 
	  	 
	     $('#full-gallery li:nth-child(6)').css('margin-right','0');

	  	 
	  	 
	  	 $("a[rel^='prettyPhoto']").prettyPhoto({
	  	 theme: 'light_square',
	  	 overlay_gallery: true, 
	  	 default_width:1200
	  	 });
	  	 
	  	 $("#full-gallery a").prettyPhoto({
	  	 	 theme: 'light_square',
	  		 overlay_gallery: true, 
	  		 default_width:1200
	  	 });
	  	 
	  	 	 $("#side-gallery a").prettyPhoto({
	  	 	 theme: 'light_square',
	  		 overlay_gallery: true, 
	  		 default_width:1200
	  	 });
	  	 
	  	 
	  	 $(".pagination:nth-child(odd)").addClass("pagination-second");
	  	 
	  	 
	  	 
	  	if ($('#freeform').length) { 
	 
			$("#freeform").validate();
		}
		


$("a.back").click(function(event){
         if(document.referrer) {window.open(document.referrer,'_self');} else {history.go(-1);} return false;
});

  var default_values = new Array();
  $("input.default-value").focus(function() {
    if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
    }
    $(this).blur(function() {
      if (this.value == '') {
         this.value = default_values[this.id];
      }
    });
  });
  
  
  	$(function()
	{
		$("#subForm input:submit").click(function() {	
			
			// First, disable the form from submitting
			$('form#subForm').submit(function() { return false; });
			
			// Grab form action
			formAction = $("form#subForm").attr("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
			id = "pbbj";
			emailId = id + "-" + id;
			
			// Validate email address with regex
			if (!checkEmail(emailId)) 
			{
				alert("Please enter a valid email address");
				return;
			}
			
			// Serialize form values to be submitted with POST
			var str = $("form#subForm").serialize();
			
			// Add form action to end of serialized data
			final = str + "&action=" + formAction;
			
			// Submit the form via ajax
			$.ajax({
				url: "/js/proxy.php",
				type: "POST",
				data: final,
				success: function(data){
					//Check to make sure that the email was accepted
					if (data.search(/invalid/i) != -1) {
						alert('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
					}
					else
					{
						$(".side-form").hide(); // If successfully submitted hides the form
						$("<div><div><p>Thanks for subscribing to our email updates.</p></div></div>").insertAfter('.side-form');
						$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
					}
				}
			});
		});
	});
	function checkEmail(email)
	{	
		var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emailVal = $("#" + email).val();
		return pattern.test(emailVal);
	}
 
  $("a.external").attr('target','_blank');
  $("a.pdf").attr('target','_blank');
  
  
  /* gallery swap out images */

$("#yacht-detail-side a").click(function(){
    $('#yacht-full').attr('src',$(this).attr('href'));
    return false;

});

         
});
