$('html').addClass("js");

jQuery(document).ready(function(){


		
		
		$("a[rel^='lightbox']").fancybox({
			'zoomOpacity'	: true,
			'zoomSpeedIn'	: 500,
			'zoomSpeedOut'	: 300,
			'overlayShow'	: true,
			'overlayOpacity': 0.7,
			'centerOnScroll' : false
		});
		
		$('#videoLink').fancybox({
			'zoomOpacity'	: true,
			'zoomSpeedIn'	: 500,
			'zoomSpeedOut'	: 300,
			'overlayShow'	: true,
			'overlayOpacity': 0.7,
			'frameWidth' : 680,
			'frameHeight' : 520,
			'centerOnScroll' : false
		});
		$('#brochureLink').fancybox({
			'zoomOpacity'	: true,
			'zoomSpeedIn'	: 500,
			'zoomSpeedOut'	: 300,
			'overlayShow'	: true,
			'overlayOpacity': 0.7,
			'frameWidth' : 1100,
			'frameHeight' : 800,
			'centerOnScroll' : false
		});
		

		
		$(".join-email .go").click(function(){
            var a=$(this).parent();
            $('<a href="'+a.attr('action')+'?email='+$("#email-address").val()+'" class="iframe">Join Email</a>').fancybox({
                    'frameWidth':430,
                    'frameHeight':440,
                    'hideOnContentClick': false
            }).click();
            return false;
		});


		
		$('.itemPreview').each(function(i,o){
			var curHolder = $(o).children('.itemPreviewImage');
			curHolder.children('a.lightboxLink').fancybox({
				'zoomOpacity'	: true,
				'zoomSpeedIn'	: 500,
				'zoomSpeedOut'	: 300,
				'overlayShow'	: true,
				'overlayOpacity': 0.7,
				'centerOnScroll' : false
			});
		});
		
		if(!$.browser.msie){
			$('#bookingMask').customSelect();
		}
		
		$('.toPngFix').pukkaPNGFix();
		//$('#header').pukkaPNGFix();
		//$('#contentHeader').pukkaPNGFix();
		
		
		//cycleOffers();
		
		initBookingMask();
		
		initLinks();
		
		initModules();
		
		
		initJoinNewsletter();
});
		

function initJoinNewsletter(){
	$('input#email-address').inputFieldHelper();
	
}
	
		
function cycleOffers(){
	$('.cycleOffer').before('<div id="offersNav"></div>').cycle({ 
	    fx:     'fade', 
	    speed:   1000, 
	    timeout: 5000,
		cleartype: false,
		pager:  '#offersNav' 

	});
 }


var mouseOverBooking = false;
var curHeight = 0; 
var curWidth = 0; 

function initBookingMask(){
	curHeight = $('#bookingMask').height();
	curWidth = $('#bookingMask').width(); 
	$('#bookingMask').css({opacity: 0, display: 'block', height:0, width: 0});
	$('#bookingMaskButton').click(function(){
		showBookingMask();
	});
	$('#bookingMask').mouseenter(function(){
		mouseOverBooking = true;
		showBookingMask();
	});
	$('#bookingMask').mouseleave(function(){
		mouseOverBooking = false;
		setTimeout(closeBookingMask,3000);
	});
	
}

function showBookingMask(){
	$('#bookingMask').stop();
	$('#bookingMask').animate({width:curWidth,height:curHeight,opacity:1},"slow",function(){
		$('#bookingMask').css({overflow: 'visible'});
	});
}

function closeBookingMask(){
	if(!mouseOverBooking && $('div.calendar').css('display')!='block'){
		$('#bookingMask').css({overflow: 'hidden'});
		$('#bookingMask').stop();
		$('#bookingMask').animate({width:0,height:0,opacity:0},"slow");
	}
}


function initLinks(){
	$('#topBox a').each(function(i,o){
		if($(o).hasClass('offsite')){
			addFadeEffect(o,'#ffffff');
		} else {
			addFadeEffect(o,'#ff6633');
		}
	});
	
	$('#footer a').each(function(i,o){
		addFadeEffect(o,'#ffffff');
	});
	
	$('#topBox ul li.active').css({opacity: 0.5});
}


function addFadeEffect(name,finalColor){
	var startColor = $(name).css('color');
	$(name).each(function(i,o){
		$(o).mouseenter(function(){
			$(o).stop();
			$(o).animate({color: finalColor});
		});
		$(o).mouseleave(function(){
			$(o).stop();
			$(o).animate({color: startColor});
		});
	});
}



function initModules(){

	$('.moduleBody .itemsTitleList a').each(function(i,o){
		
		var startColor = $(o).css('color');
		
		$(o).click(function(e){
			e.preventDefault();
			$('.moduleBody .itemsTitleList a.active').removeClass('active').animate({color: startColor});
			$(o).addClass('active');
			var curTop = -(i*$('.moduleBody .itemHolder').height());
			$('.moduleBody .itemScroller').animate({top: curTop});
		});
		
		
		
		$(o).each(function(i2,o2){
			$(o2).mouseenter(function(){
				$(o2).stop();
				$(o2).animate({color: '#fff'});
			});
			$(o2).mouseleave(function(){
				if(!$(o2).hasClass('active')){
					$(o2).stop();
					$(o2).animate({color: startColor},"slow");
				}
			});
		});
	});

}