var intervalBg;
		var active_bck = false;
		var dsp = '';
		var zi = 0;
		var next = 0;
		var i = 0;
		var lng;
		var gal = new Array(
							'01',
							'02',
							'03',
							'04',
							'05',
							'06',
							'eat',
							'stay',
							'indulge'
							);
		lng = $(gal).size();
		var img = new Image();
		
		$(window).load(function(){
			
			/*
			$(img)
			.load(
				function(){
					$(this).hide();
					$('#animated-background')
						.append(this)
						.removeClass('loading');
					$(this).fadeIn(800,'easeInOutCubic');
				}	
			)
			.attr('src','images/background/slideshow/01.jpg');
			*/
			
			/*
			$.each(gal,function(index,val){
				zi = 0;
				if(index != 0) dsp = 'none'; zi = 1; 
				var html = '<div id="'+index+'" class="background-image img_'+ val +'" style="display:none; z-index:'+ zi +';" ></div>';
				$('#animated-background').append(html);
			});
			*/
			$('#animated-background div').css({'visibility':'visible','display':'none'});
			$('#animated-background').removeClass('loading');
			$('#animated-background #0').fadeIn();
		});
		
		/*
		$.each(gal,function(index,val){
				zi = 0;
				if(index != 0) dsp = 'none'; zi = 1; 
				var html = '<div id="'+index+'" style="background:url('+val+') center top no-repeat; display:'+dsp+'; z-index:'+ zi +';" class="background-image" ></div>';
				$('#animated-background').append(html);
		});
		*/		
		$(document).ready(function(){
			$.preloadCssImages();

			$('.stay-cta').unbind('mouseenter');
			$('.eat-cta').unbind('mouseenter');
			$('.indulge-cta').unbind('mouseenter');
			
			createNextImg();

		
			function chgBack()
			{
				$('#animated-background').find('#'+next).fadeIn(800,'easeInOutCubic',function(){
					$('#animated-background').find('#'+i).hide();
					//$('#animated-background').find('#'+i).css('z-index','0');
					i = next;
					createNextImg();
				});
			}
			
			function createNextImg()
			{
				$('#animated-background').find('#'+next).css('z-index','0');
				next = i+1;
				if(next >= lng)
				{
					next=0;
				}
				$('#animated-background').find('#'+next).css('z-index','50');
			}
					

		//*** STAY ***//
		        $(".stay-cta").mouseenter(function() {
		        	active_bck = true;
		        	clearInterval(intervalBg);
		        	
		        // BACKGROUND
		        	$('#fixed-stay').stop(true,true).css({'z-index':'0'}).delay(100).fadeIn(500,'easeInOutCubic');
		        	
		        // BUTTONS
					$('.stay-cta-out').stop(true,true).fadeOut('fast');
					$(".stay-cta-over").stop(true,true).fadeIn(400,'easeInOutCubic');
		        });
		        $(".stay-cta").stop(true,true).mouseleave(function() {
			        active_bck = false;
			        startInterval();
			        
			      // BACKGROUND
			        $('#fixed-stay').stop(true,true).css({'z-index':'0'}).delay(300).fadeOut(500,'easeInOutCubic');
					
				// BUTTONS
					$('.stay-cta-over').stop(true,true).fadeOut('fast');
					$(".stay-cta-out").stop(true,true).fadeIn(400,'easeInOutCubic');
		        });
		//*** EAT ***//
		        $(".eat-cta").mouseenter(function() {
		        	active_bck = true;
		        	clearInterval(intervalBg);
		        	
		        // BACKGROUND
		        	$('#fixed-eat').stop(true,true).css({'z-index':'0'}).delay(100).fadeIn(500,'easeInOutCubic');
		        	
		        // BUTTONS
					$('.eat-cta-out').stop(true,true).fadeOut('fast');
					$(".eat-cta-over").stop(true,true).fadeIn(400,'easeInOutCubic');
		        });
		        $(".eat-cta").stop(true,true).mouseleave(function() {
		        	active_bck = false;
		        	startInterval();
		        	
		        // BACKGROUND
		        	$('#fixed-eat').stop(true,true).css({'z-index':'0'}).delay(300).fadeOut(500,'easeInOutCubic');
		        	
		        // BUTTONS	
					$('.eat-cta-over').stop(true,true).fadeOut('fast');
					$(".eat-cta-out").stop(true,true).fadeIn(400,'easeInOutCubic');
		        });
		//*** INDULGE ***//
				$(".indulge-cta").mouseenter(function() {
					active_bck = true;
					clearInterval(intervalBg);
					
				// BACKGROUND
					$('#fixed-indulge').stop(true,true).css({'z-index':'0'}).delay(100).fadeIn(500,'easeInOutCubic');
					
				// BUTTONS
					$('.indulge-cta-out').stop(true,true).fadeOut('fast');
					$(".indulge-cta-over").stop(true,true).fadeIn(400,'easeInOutCubic');
		        });
		        $(".indulge-cta").stop(true,true).mouseleave(function() {
		        	active_bck = false;
		        	startInterval();
					
				// BACKGROUND
					$('#fixed-indulge').stop(true,true).css({'z-index':'0'}).delay(300).fadeOut(500,'easeInOutCubic');
					
				// BUTTONS
					$('.indulge-cta-over').stop(true,true).fadeOut('fast');
					$(".indulge-cta-out").stop(true,true).fadeIn(400,'easeInOutCubic');
		        });
		        
		        startInterval();
		       
		        function startInterval()
				{
					intervalBg = window.setInterval(chgBack,8000);
				}
				
		//*** MAIN MENU ***//

		   	});
		   
		   	window.onload = loadTitles;
		   
		   	function loadTitles()
		   	{
		   		$('#mainnav-container').delay(1500).animate({'top':'0px'},800,'easeOutExpo');
			}
			$('.mainnav_container_gallery_display').hide();

			setTimeout(function(){ 
				if(!$('.wrapper').hasClass('over')){ 
					$('#mainnav-container').stop(true,true).animate({'top':'-129'},1000,'easeOutCubic',function(){
						$('.mainnav_container_gallery_display').fadeIn('normal');
					});
				}
			},8000);



$(document).ready(function(){
/** ANIMATION MENU **/
$('.wrapper').mouseenter(function(){
	$(this).addClass('over');
		$('.mainnav_container_gallery_display').hide();
		$('#mainnav-container').stop(true,false).animate({'top':'0'},1000,'easeOutCubic');
});

$('.wrapper').mouseleave(function(){
	$(this).removeClass('over');
	setTimeout(function(){ if(!$('.wrapper').hasClass('over')){ 
		$('#mainnav-container').stop(true,false).animate({'top':'-129'},1000,'easeOutCubic',function(){
			$('.mainnav_container_gallery_display').fadeIn('normal');
		});
		}},2000);
	
});
});
