$('html').addClass("js");

jQuery(document).ready(function(){

		
		
		$("a[rel^='lightbox']").fancybox({
			'zoomOpacity'	: true,
			'zoomSpeedIn'	: 500,
			'zoomSpeedOut'	: 300,
			'overlayShow'	: true,
			'overlayOpacity': 0.7
		});
		
		
		$('#bookingMask').customSelect();
			
		$('.pngFix').pukkaPNGFix();
		
		cycleOffers();
		
		
		
		initHomeNews();
		initModulePage();
});
		
	
		
function cycleOffers(){
	$('.cycleOffer').before('<div id="offersNav"></div>').cycle({ 
	    fx:     'fade', 
	    speed:   1000, 
	    timeout: 5000,
		cleartype: false,
		pager:  '#offersNav' 

	});
 }

 
 
 
 function initHomeNews(){
 	if($('#newsHome').length){
		var newsCount = $('#newsHomeCount').html();
		var newsPP = 2;
		var curNewsPage = 0;
		var newsHeight = $('.homeNews').height();
		
		checkHomeNav(curNewsPage,newsCount,newsPP);
		
		$('#newsHomeNav').css({display: 'block',opacity: 0});
		$('#rightContent').mouseenter(function(){
			$('#newsHomeNav').stop();
			$('#newsHomeNav').animate({opacity:1});
		});
		$('#rightContent').mouseleave(function(){
			$('#newsHomeNav').stop();
			$('#newsHomeNav').animate({opacity:0});
		});
		
		$('#newsHomeNext').click(function(){
			if(curNewsPage+newsPP<newsCount){
				curNewsPage++;
				updateNewsBox(newsHeight,curNewsPage,newsPP);
				checkHomeNav(curNewsPage,newsCount,newsPP);
			}
		});
		$('#newsHomePrev').click(function(){
			if(curNewsPage>0){
				curNewsPage--;
				updateNewsBox(newsHeight,curNewsPage,newsPP);
				checkHomeNav(curNewsPage,newsCount,newsPP);
			}
		});
	}
 }
 
 function checkHomeNav(curNewsPage,newsCount,newsPP){
 	if(curNewsPage>0){
		$('#newsHomePrev').css({display:'block'});
	} else {
		$('#newsHomePrev').css({display:'none'});
	}
	if(curNewsPage+newsPP<newsCount){
		$('#newsHomeNext').css({display:'block'});
	} else {
		$('#newsHomeNext').css({display:'none'});
	}
	
 }
 function updateNewsBox(newsHeight,curNewsPage){
	$('#newsHomeBox').stop();
	$('#newsHomeBox').animate({top:-(newsHeight*curNewsPage)}, { duration: 700, easing: "easeInOutBack" });
 }
 
 
 
 
 var scrollOffset = 0;
 
 function initModulePage(){
 	if($('#itemContentList').length){
		var itemHeight = $('.itemContentBox').eq(0).height();
		
		$('.itemTitleLink').each(function(i,o){
			$(o).click(function(event){
				event.preventDefault();
				$('#itemContentContainer').stop();
				$('#itemContentContainer').animate({top: (scrollOffset-(itemHeight*(i+1)))}, { duration: 700, easing: "easeInOutBack" });
			});
		});
		
		$('.itemThumbs').autoscroll(AUTOSCROLL_Y);
		
		
		moduleInitScroll();
	}
 }


 function moduleInitScroll(){
	var curElTitle = $.url.attr("anchor");
	var itemHeight = $('.itemContentBox').eq(0).height();
	
 	$('.itemPreview a.inPageAnchor').each(function(i,o){
 		if($(o).attr('name')==curElTitle){
 			scrollOffset=itemHeight*(i+1);
 		}
 	});
 	
 }