/** jQuery.ScrollTo - Easy element scrolling using jQuery.**/
;(function(h){var m=h.scrollTo=function(b,c,g){h(window).scrollTo(b,c,g)};m.defaults={axis:'y',duration:1};m.window=function(b){return h(window).scrollable()};h.fn.scrollable=function(){return this.map(function(){var b=this.parentWindow||this.defaultView,c=this.nodeName=='#document'?b.frameElement||b:this,g=c.contentDocument||(c.contentWindow||c).document,i=c.setInterval;return c.nodeName=='IFRAME'||i&&h.browser.safari?g.body:i?g.documentElement:this})};h.fn.scrollTo=function(r,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};a=h.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=h(k),d=r,l,e={},p=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(d)){d=n(d);break}d=h(d,this);case'object':if(d.is||d.style)l=(d=h(d)).offset()}h.each(a.axis.split(''),function(b,c){var g=c=='x'?'Left':'Top',i=g.toLowerCase(),f='scroll'+g,s=k[f],t=c=='x'?'Width':'Height',v=t.toLowerCase();if(l){e[f]=l[i]+(p?0:s-o.offset()[i]);if(a.margin){e[f]-=parseInt(d.css('margin'+g))||0;e[f]-=parseInt(d.css('border'+g+'Width'))||0}e[f]+=a.offset[i]||0;if(a.over[i])e[f]+=d[v]()*a.over[i]}else e[f]=d[i];if(/^\d+$/.test(e[f]))e[f]=e[f]<=0?0:Math.min(e[f],u(t));if(!b&&a.queue){if(s!=e[f])q(a.onAfterFirst);delete e[f]}});q(a.onAfter);function q(b){o.animate(e,j,a.easing,b&&function(){b.call(this,r,a)})};function u(b){var c='scroll'+b,g=k.ownerDocument;return p?Math.max(g.documentElement[c],g.body[c]):k[c]}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);


$(document).ready(function(){

  
  //Navigation Drop Down Functions
	$('nav li:has(ul)').hover(
	 function(){
	   $(this).find('ul').fadeIn('fast');
	 },
	 function(){
	   $(this).find('ul').hide();
	 }
	);
  
		
	//Email Sign Up Form on right side of home page 
	$('#emailsignupform').submit(function(){
			
		var email = $('[name=email]').val();
		var email_2 = $('[name=email_2]').val();
		
		if(email_2 != ''){alert('You are spam, go away.');return false;}
				
		if(email == ''){
			alert('Email address is required.');
			return false;
		}else{
			return true;
		}
	});	
	
	
	//Email form on right side of golf pages 
	$('#golfqcform').submit(function(){
			
		var email = $('[name=email]').val();
		var email2 = $('[name=email2]').val();
		
		if(email2 != ''){alert('You are spam, go away.');return false;}
				
		if(email == '' || email == 'Enter Email Address'){
			alert('Email address is required.');
		}else{
			
			$.post('/submit/submitgolfqc', $(this).serialize(),function(){
				$('#golfqcform').hide();
				$('#golfqcformmessage').html('Thanks! Your email has been sent.');
			});	
		}
		
		return false;
	});	
	
	
	
	//Quick Contact Form on right side of home page 
	$('#quickcontactform').submit(function(){
			
		var name = $('#quickcontactform [name=name]').val();
		var email = $('#quickcontactform [name=email]').val();
		var email_2 = $('#quickcontactform [name=email_2]').val();
		var comments = $('#quickcontactform [name=comments]').val();
		
		if(email_2 != ''){alert('You are spam, go away.');return false;}
				
		if(email == '' || name == '' || comments == ''){
			alert('Name, Email and Comments are required fields.');
			return false;
		}else{
			return true;
		}		
		
	});	
	
	
	//golf course review form
	$('#reviewform').submit(function(){
			
		var name = $('#reviewform [name=name]').val();
		var email2 = $('#reviewform [name=email2]').val();
		var review = $('#reviewform [name=review]').val();
		
		if(email2 != ''){alert('You are spam, go away.');return false;}
				
		if(name == '' || review == ''){
			alert('Name and Review are required fields.');
		}else{
		  
      $.post('/submit/submitgolfcoursereviewform', $('#reviewform').serialize(),function(){
	  		$('#reviewform').hide();
		    $('#reviewformmessage').html('Thanks! Your review has been submitted for approval.');
	  	});	  				
		  	
		}	
		
		return false;	
		
	});	
	
			
  //Property detail page jquery calendar filter
  function detailFilter(date){
  	
  		var type = $("input[name='propertyhiddentype']").val();
  		var location = $("input[name='propertyhiddenlocation']").val();
  		
  		if(location == 'Ocean Front' && type != 'House'){ 
  			
  			//June 18th
		   	if( date.getMonth() == 5 && date.getDate() >= 18 ){    		
		   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
		   	}
		   	
		   	//July
		   	if( date.getMonth() == 6){ 		   		
		   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
		   	}
		   	
		   	//August 6th
		   	if( date.getMonth() == 7 && date.getDate() <= 6 ){ 		   		
		   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
		   	}
		   	
		   	//Thanksgiving Day 
       	if( date.getMonth() == 10 && date.getDate() == 24 ){    		
       		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
       	}
       	
       	//Day after thanskgiving
       	if( date.getMonth() == 10 && date.getDate() == 25 ){    		
       		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
       	}
       	
       	//Christmas Eve
   	if( date.getMonth() == 11 && date.getDate() == 24 ){    		
   		return (date.getDay() != 5) ? [false, ''] : [true, ''];   		
   	}
   	
   	//Christmas Day
   	if( date.getMonth() == 11 && date.getDate() == 25 ){    		
   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
   	}
   	
   	//The day after Christmas
   	if( date.getMonth() == 11 && date.getDate() == 26 ){    		
   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
   	}
		   	
		   	return [true,'']; 
  		
  		}else if(type == 'House'){
  		
  			 
				
				//Thanksgiving Day 
       	if( date.getMonth() == 10 && date.getDate() == 24 ){    		
       		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
       	}
       	
       	//Day after thanskgiving
       	if( date.getMonth() == 10 && date.getDate() == 25 ){    		
       		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
       	}  
       	
       	//Christmas Eve
       	if( date.getMonth() == 11 && date.getDate() == 24 ){    		
       		return (date.getDay() != 5) ? [false, ''] : [true, ''];   		
       	}
       	
       	//Christmas Day
       	if( date.getMonth() == 11 && date.getDate() == 25 ){    		
       		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
       	}
       	
       	//The day after Christmas
       	if( date.getMonth() == 11 && date.getDate() == 26 ){    		
       		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
       	}
       	
       	if( date.getMonth() == 5 || date.getMonth() == 6 || date.getMonth() == 7){ 		   		
				return (date.getDay() != 6) ? [false, ''] : [true, ''];
						
			}else{  	      	
				return [true,''];    		
			}
  			
  		}else{
  			return [true,''];
  		}  		
  	
  }
   
   
   //Ocean Front filter, June 18 - Aug. 6 for Location = Ocean Front
   function oceanFrontFilter(date){   	
	
	  //June 18th
   	if( date.getMonth() == 5 && date.getDate() >= 18 ){    		
   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
   	}
   	
   	//July
   	if( date.getMonth() == 6){ 		   		
   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
   	}
   	
   	//August 6th
   	if( date.getMonth() == 7 && date.getDate() <= 6 ){ 		   		
   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
   	}
   	
   	return [true,'']; 
   	   
   }
   
   
   function blackOutDates(date){
    
    //Thanksgiving Day 
   	if( date.getMonth() == 10 && date.getDate() == 24 ){    		
   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
   	}
   	
   	//Day after thanskgiving
   	if( date.getMonth() == 10 && date.getDate() == 25 ){    		
   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
   	}
   	
   	//Christmas Eve
   	if( date.getMonth() == 11 && date.getDate() == 24 ){    		
   		return (date.getDay() != 5) ? [false, ''] : [true, ''];   		
   	}
   	
   	//Christmas Day
   	if( date.getMonth() == 11 && date.getDate() == 25 ){    		
   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
   	}
   	
   	//The day after Christmas
   	if( date.getMonth() == 11 && date.getDate() == 26 ){    		
   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
   	}
   	
   	return [true,''];
    
   }
   
   
   //House filter, June 1 - Aug. 31 for Type = House
   function houseFilter(date){   	
	
   	if( date.getMonth() == 5 || date.getMonth() == 6 || date.getMonth() == 7){ 		   		
   		return (date.getDay() != 6) ? [false, ''] : [true, ''];   		
   	}else{  	      	
   		return [true,''];    		
   	}
   	   
   }
   
   
   //If Location drop down is changed
   $("select[name='location']").change(function(){
   		
   		var selectedLocation = $(this).val();
   		var selectedType = $("select[name='type']").val();
   		   		   		
   		if(selectedLocation == 'Ocean Front' && selectedType != 'House'){
   					
   			//Run peakSeasonFilter and make June 18 - Aug. 6 only Sat to Sat
			$('.mycal').datepicker('option',{beforeShowDay: oceanFrontFilter});   			
   		
   		}
   	
   });
   
   
   //If Type dropdown is changed
   $("select[name='type']").change(function(){
   		
   		var selectedType = $(this).val();
   		var selectedLocation = $("select[name='location']").val();
   		
   		if(selectedType == 'House'){
   			
   			//Run houseFilter and make June 1 - Aug. 31 only Sat to Sat
			$('.mycal').datepicker('option',{beforeShowDay: houseFilter});   			
   		
   		}else if(selectedType != 'House' && selectedLocation == 'Ocean Front'){
   			
   			//Run oceanFrontFilter and make June 18 - Aug. 6 only Sat to Sat
			$('.mycal').datepicker('option',{beforeShowDay: oceanFrontFilter});	
   		
   		}else{
   			
   			$('.mycal').datepicker('option',{beforeShowDay: noFilter});
   		
   		}
   	
   });

 	  
   //No filter on jquery calendar
   function noFilter(date) {
      return [true, ''];
   }	
	
	
	//jquery calendars used on Advanced Search, Search Results and Home page
	$('.mycal').datepicker({
      showOn: 'button',
      buttonImage: '/images/booking/cal.png',
      buttonImageOnly: true,     
      maxDate: "+1Y",
      minDate: '+2D',
      beforeShowDay: blackOutDates,
      numberOfMonths: 2
   });
   
   
   //jquery calendar used on the property detail page
   $('.mycaldetails').datepicker({
      showOn: 'button',
      buttonImage: '/images/booking/cal.png',
      buttonImageOnly: true,     
      maxDate: "+1Y",
      minDate: '+2D',
      beforeShowDay: detailFilter,
      numberOfMonths: 2
   });
   
   $('#pdetailcheckin, input[name="nights"]').change(function(){
    
      $('#pdetailtopbooknowbutton').hide();
      $('#pdetailcheckavail').show();
   
   });
   
   //used on the resort pages on the horizontal image scroller
   if($('#mycarousel').length != 0){    
	jQuery('#mycarousel').jcarousel();
	}
	
		
		
});





