// JavaScript Document

$(function(){
	
	if ($.browser.webkit) {
		$('#cottagesDropdown').css('left', '-240px');	
	}

	$('.slow_cycle').cycle(
	{
		speed: 1000, 
		timeout: 8500
	}						 
	)
	
	
	$('.medium_cycle').cycle(
	{
		speed: 1000, 
		timeout: 6500
	}						 
	)
		
		
	$('.fast_cycle').cycle(
	{
		speed: 1000, 
		timeout: 3500
	}						 
	)
	
	//Fix IE7 Z-Index bug
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
	
	
	
	function show_menu() {
		$('#cottagesDropdown').fadeIn(250); 	
	}
	
	function hide_menu() {
		$('#cottagesDropdown').fadeOut(250);
	}
	
	var config = {    
	     over: show_menu,  
	     interval: 100,  
	     out: hide_menu   
	};
	
	$('#nav_cottage').hoverIntent(config);
	//$('#nav_cottage').hover(function(){show_menu () }, function(){hide_menu() });
	
	$('#read_more').click(function(){
		/*$('#footer_box_text').slideToggle(
			'slow',
			function(){
		        $.scrollTo('#footer_bottom_placeholder', "slow");
		    });
	    */
		
		$('#footer_box_text').slideToggle("slow", function(){
	        $.scrollTo('#footer_box_text', "slow");
	    });
		
		
		return false;
	});
	
	//Only run this code on the cottage page !
	if ( $('#body_cottages').size() == 1 ) {
			
		$('body').css('position','relative');
		$('body').append('<div id="booking_overlay" style="display: none; z-index: 1500;" ></div>')
		$('#booking_overlay').click(function(){$('#booking_panel').fadeOut('slow'); $('#booking_overlay').hide(); });
		
		$('.booking_link').click(function(){	
			$('#booking_overlay').css("zIndex", 1500);
			$('#booking_panel').css("zIndex", 1600);
			$('#booking_panel').css("top", ( $(window).height() - $('#booking_panel').height() ) / 2+$(window).scrollTop() + "px");
	    	$('#booking_panel').css("left", ( $(window).width() - $('#booking_panel').width() ) / 2+$(window).scrollLeft() + "px");
				
			$('#booking_panel').html('<p style="text-align: center; margin-top: 30px; height: 100px;">Loading - Please wait...<br /><img src="/img/ajax_loader.gif" alt="Loading" /></p>');	
			$('#booking_panel').load('/p/'+$(this).attr('href'), function(){
				$('.booking_panel_close').click(function(){$('#booking_panel').fadeOut('slow'); $('#booking_overlay').hide(); });
				$('.booking_panel_submit').click(function(){
				
					var arrival_date = $('#booking_form').find(':checked').attr('rel');
					if ( arrival_date !== undefined && arrival_date != '' ) {
						$('#arrival_date').val(arrival_date);
					}
						
					$('#booking_form').submit(); 
				});
			});
			
							
			$('#booking_overlay').show();
			
			$('#booking_panel').fadeIn('slow');
			return;	
		});
		
		//Check if we have a date from the availability page!
		if(window.location.hash) { 			
			var date = window.location.hash.substr(1, window.location.hash.length-1);
			var href = $('#row_' + date).find('a:first').attr('href');
			href += '&full';
			$('#row_' + date).find('a:first').attr('href', href);
			$('#row_' + date).find('a:first').click();
		}
		
	}

});



