$(document).ready(
	function () {
		
	
		//Cycle
		$('#main-banner-cycle img').preload({
	        onFinish: startBigCycle
	    });
	    $('#cycle-gallery-imagas img').preload({
	        onFinish: startSmallCycle
	    });

		
		function startBigCycle() {
	        $('#main-banner-cycle').cycle({
	            fx: 'fade',
	            timeout: 6000,
	            speed: 1200,
	            next: '#next-slide',
	            prev: '#prev-slide'
	        });
	    };
		function startSmallCycle() {
	        $('#cycle-gallery-imagas').cycle({
	            fx: 'scrollHorz',
	            timeout: 0,
	            speed: 800,
	            next: '#gallery-next',
	            prev: '#gallery-prev',
	            onPrevNextEvent: function(nxt, ind, elem) {
	                var descConteiner, descConteinerHeight, imgTitle, imgDescr, nextElem;
	                nextElem = $('img', elem);

	                imgTitle = nextElem.attr('title');
					imgTitleLink = $(elem).attr('href');
	                imgDescr = nextElem.attr('alt');

	                descConteiner = $('#cycle-gallery-description');
	                descConteinerHeight = descConteiner.innerHeight();
	                descConteiner.animate({
	                    bottom: -descConteinerHeight
	                }, 400, function() {
	                    descConteiner.removeAttr('class').addClass('bg-color-' + ind);
	                    descConteiner.find('h3 > a').attr('href', imgTitleLink).html(imgTitle);
	                    descConteiner.find('p').html(imgDescr);
	                    Cufon.replace('#cycle-gallery-description h3',
			                {
			                    fontFamily: 'Interstate'
			                });
	                    descConteinerHeight = descConteiner.innerHeight();
	                    descConteiner.css('bottom', -descConteinerHeight);
	                    descConteiner.animate({
	                        bottom: '0'
	                    }, 400)
	                })

	            }
	        });
	    }
//-------------------------------------------------------
		
	function showHidden(thisBlock) { $('.' + thisBlock + ' .drop-block').show()};
	function hideHidden(thisBlock) { $('.' + thisBlock + ' .drop-block').hide()};
    
    var reservationsClass = 'reservations-block';
    var reservationsTimer = null;
    var isFocused = false;
    var isHovered = false;
    
	$('.' + reservationsClass).hover( 
		function(){
			isHovered = true;
			clearTimeout(reservationsTimer);
			reservationsTimer = setTimeout( "$('." + reservationsClass + " .drop-block').show()", 3000 );
		},
		function(){
        	isHovered = false;
	        clearTimeout(reservationsTimer);
    	    if(!isFocused) {
			hideHidden(reservationsClass);
		}
	});
    
	$('input, select', '.' + reservationsClass).focusin(
		function() {
			isFocused = true;
			clearTimeout(reservationsTimer);
			showHidden(reservationsClass);
		});
    
	$('input, select', '.' + reservationsClass).focusout(
		function() {
			isFocused = false;
			clearTimeout(reservationsTimer);
			if(!isHovered) {
				hideHidden(reservationsClass);
			}
	});
	
	var hover_on_menu = false;
	var lastLI;
	var timeShow;
	var timeHide;

	function hideMenu()
	{	
		if(lastLI != undefined) {
			$('.drop-block', lastLI).hide();
			lastLI.removeClass('hover');
			menuReplace();
		}
	}

	function makeTall(){  $('.drop-block', this).show(); $(this).addClass('hover');}

	function makeShort(){ $('.drop-block', this).hide(); $(this).removeClass('hover'); menuReplace()}
	
	var configMenu = {    
	     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
    	 interval: 150, // number = milliseconds for onMouseOver polling interval    
	     over: makeTall, // function = onMouseOver callback (REQUIRED)    
	     timeout: 400, // number = milliseconds delay before onMouseOut    
    	 out: makeShort // function = onMouseOut callback (REQUIRED)    
	};
	$("ul.mainMenu > li.menuItem").hoverIntent( configMenu );
	menuReplace();
	});

