$(document).ready(function(){

	// Setup fancybox galleries
	$('.fancybox').click(function(){
		var images = [];
		
		// Get all fancybox links that have the same rel tag
		$('.fancybox[rel=' + $(this).attr('rel') + ']').each(function(){
			images.push({
				'href': $(this).attr('href'),
				'title': '<strong>' + $(this).find('.title').val() + '</strong>' + $(this).find('.description').val()
			});
		});
		
		// Load fancybox with all the images
		$.fancybox(images, {
			'overlayColor': '#ffffff',
			'titlePosition': 'inside',
			'padding': 45,
			'index': $('.fancybox[rel=' + $(this).attr('rel') + ']').index($(this)),
			'onComplete': function(){
				$('.fancybox-close').fadeIn(400);
			},
			'onClosed': function(){
				$('.fancybox-close').fadeOut(400);
			}
		});
		
		return false;
	});
	
	// Add fancybox close button functionality
	/*$('body').append('<a class="fancybox-close" style="display:none;" />');
	$('.fancybox-close').click($.fancybox.close); */
	
	// Get booking popup default left position
	var bp_default = $('.booking_popup').css('left');
	
	// Add booking popup click functionality
	$('.booking_popup .toggle').click(function(){
		// If booking popup isn't animated, toggle booking popup
		if(!$('.booking_popup').is(':animated')){
			// If booking popup is in its closed position, animate open
			if(parseFloat($('.booking_popup').css('left')) != 0){
				$('.booking_popup').animate({'left': 0}, 400);
				$(this).addClass('toggle-close');
			}else{ // If booking popup is in its open position, animate close
				$('.booking_popup').animate({'left': bp_default}, 400);
				$(this).removeClass('toggle-close');
			}
		}
	});
	
});
