//------------------------------------
//	MENUS.JS
//	Author: 	Engage Interactive
//	Requires:	jquery 1.3.2
//				global.js
//				cufon.js
//				gazz.js
//------------------------------------

$(function(){
//BEGIN jQuery

	//MENU ITEM HOVER THINGS
	$('#menu_items .menu_item h3').each(function(){
		y = '-' + $(this).innerHeight() + 'px';
		if($(this).parent().parent().hasClass('show_title')){
			$(this).css({bottom:0}).data('ypos',y);
		}else{
			$(this).css({bottom:y});
		}
	});

	$('#menu_items .menu_item')
		.mouseenter(function(){
			if($(this).parent().hasClass('active') != true && $(this).parent().hasClass('show_title') != true){
				$(this).children('h3').stop([]).animate({bottom:0},300,'easeInOutExpo');
			}else if($(this).parent().hasClass('active') != true){
				$(this).children('h3').stop([]).animate({bottom:$(this).children('h3').data('ypos')},300,'easeInOutExpo');
			}
		})
		.mouseleave(function(){
			if($(this).parent().hasClass('active') != true && $(this).parent().hasClass('show_title') != true){
				h3 = $(this).children('h3');
				y = '-' + h3.innerHeight() + 'px';
				$(this).children('h3').stop([]).animate({bottom:y},300,'easeInOutExpo');
			}else if($(this).parent().hasClass('active') != true){
				$(this).children('h3').stop([]).animate({bottom:0},300,'easeInOutExpo');
			}
		});
	
	//CLICK 'N' SCROLL
	$('#menu_items .menu_item').click(function(){
		if($(this).parent().hasClass('show_title')==false){
			scrollMenu();
		}
	});
	
	
	//MENU ITEM MORE CLICK
	$('#menu_items a.more_info').click(function(){
		
		p = $(this).prev('.menu_item').children('p');
		
		if($(this).parent().hasClass('active') != true){
			$(this).children('span.bg').stop([]).animate({left:-59},400,'easeInOutExpo');
			$('.active span.bg').stop([]).animate({left:0},400,'easeInOutExpo');
			
			$(this).parent().addClass('active').siblings('.active').removeClass('active').children('.menu_item').children('p').stop([]).animate({top:'-161px'},500,'easeInOutExpo');
			p.stop([]).animate({top:0},500,'easeInOutExpo');
		}else{
			$(this).children('span.bg').stop([]).animate({left:0},400,'easeInOutExpo');
			
			$(this).parent().removeClass('active');
			p.stop([]).animate({top:'-161px'},500,'easeInOutExpo');
		}
		
		return false;
	});
	
	
	//IMAGE POPUP TOOLTIP
	
	//SETTINGS
	xOffset = -93;
	yOffset = 210;
	title = '';
	ttActive = false;
	
	//ADD IN HTML
	$('body').append(
		'<div id="tooltip">'
			+'<span class="loading"></span>'
		+'</div>'
	);
	
	//MOUSE OVER
	$("#menu_list dl[title]")
		.mouseenter(function(e){
			ttActive = true;
			$('#tooltip').children('img').remove();
			$('#tooltip').children('span').css({display:'block'});
			$('#tooltip').show().css({top:(e.pageY - yOffset) + 'px', left:(e.pageX + xOffset) + 'px'});
			loadImage(title = $(this).attr('title'));
			$(this).attr('title','');
		})
		.mouseleave(function(){
			ttActive = false;
			$('#tooltip').hide();
			$(this).attr('title',title);
		});
	
	//MOUSE MOVE
	$("#menu_list dl").mousemove(function(e){
		$("#tooltip").css({top:(e.pageY - yOffset) + 'px', left:(e.pageX + xOffset) + 'px'});
	});
	
	//IMAGE LOADING
	function loadImage(src){
		var img = new Image();
		$(img).load(function(){
			$(this).hide();
			$('#tooltip span.loading').hide();
			$('#tooltip').append(this);
			$(this).fadeIn();
		}).attr('src', src);
	}
	
	
	//LIMITED POPUP TOOLTIP
	
	//SETTINGS
	errxOffset = -87;
	erryOffset = 118;
	errMsg = '';
	
	//ADD HTML
	$('body').append(
		'<div id="msg_tooltip"></div>'
	);
	
	//MOUSE OVER
	$("#menu_list dl dd.limited")
		.mouseenter(function(e){
			errMsg = $(this).children('span').attr('title')
			$('#msg_tooltip').text(errMsg).show().css({top:(e.pageY - erryOffset) + 'px', left:(e.pageX + errxOffset) + 'px'});
			$(this).children('span').attr('title','');
		})
		.mouseleave(function(){
			if(ttActive == true) $('#tooltip').show();
			$('#msg_tooltip').hide();
			$(this).children('span').attr('title',errMsg);
		});
	
	//MOUSE MOVE
	$("#menu_list dl dd.limited").mousemove(function(e){
		$('#tooltip').hide();
		$("#msg_tooltip").css({top:(e.pageY - erryOffset) + 'px', left:(e.pageX + errxOffset) + 'px'});
	});
	
	
	//SCROLL TO TOP LINK
	
	firstLoad = true;
	scrollActive = true;
	
	pageY = $(window).scrollTop();
	pageH = $(window).height();
	
	if(pageY > 533){
		$('#backtotop').css({display:'block'}).stop([]).animate({top:(pageY+pageH)-260});
	}
	
	$(window).scroll(function () {
		pageY = $(window).scrollTop();
		pageH = $(window).height();
		if(pageY > 533 && scrollActive == true){
			if(firstLoad == true){
				$('#backtotop').css({display:'block'});
				firstLoad = false;
			}
			$('#backtotop').stop([]).animate({top:(pageY+pageH)-260});
		}
	});	
	
	//SCROLL TO TOP
	$('a[href=#header]').click(function(){
		scrollActive = false;
        $('html, body').animate({scrollTop:0}, 'slow', 'easeInOutExpo',function(){
			scrollActive = true;
		});
        return false;
    });
	
	//SCROLL TO FULL MENU
	
	function scrollMenu(){
		scrollActive = false;
        $('html, body').animate({scrollTop:532}, 'slow', 'easeInOutExpo',function(){
			scrollActive = true;
		});
        return false;
	}
	
	
	//OPEN TIMES NOW
	if($('#available_time').hasClass('now')){
		$('#available_time').animate({height:152},600,'easeInOutExpo');
	}


//END jQuery
});