$(document).ready(function() {
	
	// GLOBAL
	
		/*global hide_explore, hide_reservations, clearTimeout, setTimeout, show_reservations, close_guestx, show_explore*/
	
		// TIMERS
			var t_explore;
			var t_reservations;
			var t_guestx_special;
			var t_secondary;
			var t_tooltip;
		
			
		// IE specific
		
		var reservation_width = "155px";
		var explore_width = "354px";
		
		/*
		jQuery.each(jQuery.browser, function(i) {
		  if($.browser.msie){
		    reservation_width = "210px";
				guestx_width_closed = "280px";
				explore_width = "440px";
			}
		});
		*/
		
		if($.browser.safari){
			$('#navigation_secondary li .tooltip').css("top", "-6px");
		}
			
		// HIDE AND PREP ELEMENTS FOR ANIMATION
		
		//$('#navigation_secondary').hide();
		$('#navigation_secondary .tooltip').hide();
		$('#navigation_reservations li').hide();
		$("#navigation_reservations").css({
			width: "1px",
			height: "1px",
			opacity: 0.0
		});
		$('#navigation_explore li').hide();
		$("#navigation_explore").css({
				width: "1px",
				height: "1px"
			});
		
		// ANIMATIONS
		
		show_explore = function() {
			$('#trigger_explore').addClass('hover');
			$("#navigation_explore").animate({
					width: explore_width,
					height: "88px",
					opacity: 1.0
				}, 200);
			$('#navigation_explore li').show();
		};
			
		hide_explore = function() {
			$('#navigation_explore li').hide();
			$('#trigger_explore').removeClass('hover');
			$("#navigation_explore").animate({
					width: "1px",
					height: "1px",
					opacity: 0.0
				}, 200);
		};
		
		show_reservations = function() {
			$('#trigger_reservations').addClass('hover');
			$('#navigation_reservations').animate({
					width: reservation_width,
					height: "36px",
					opacity: 1.0
				}, 200);
			$('#navigation_reservations li').show();
		};
		
		hide_reservations = function() {
			$('#trigger_reservations').removeClass('hover');
			$('#navigation_reservations li').hide();
			$("#navigation_reservations").animate({
					width: "1px",
					height: "1px",
					opacity: 0.0
				}, 200);
		};
		
		hide_secondary =  function() {
			$("#navigation_secondary").fadeOut();
		};

		// EXPLORE MENU
	
		/*$('#trigger_explore').mouseenter(
			function () {
				clearTimeout(t_explore);
				show_explore();
			}
		);
		
		$('#navigation_explore').mouseenter(
			function () {
				clearTimeout(t_explore);
			}
		);
		
		$('#trigger_explore, #navigation_explore').mouseleave(
			function () {
				t_explore = setTimeout('hide_explore();', 600);
			}
		);*/

		// RESERVATION MENU
	
		/*$('#trigger_reservations').mouseenter(
			function () {
				clearTimeout(t_reservations);
				show_reservations();
			}
		);
		
		$('#navigation_reservations').mouseenter(
			function () {
				clearTimeout(t_reservations);
			}
		);
		
		$('#trigger_reservations, #navigation_reservations').mouseleave(
			function () {
				t_reservations = setTimeout('hide_reservations();', 600);
			}
		);*/

		// GUEST X + SPECIAL OFFERS MENU
		
		var guestx_width_closed = "312px";
		var guestx_width_open = "654px";
		var guestx_height = "84px";
		var guestx_speed = 400;
		
		// Open Menu
		open_guestx = function() {
			$("#navigation_guestx-specialoff").animate({
					width: guestx_width_open,
					height: guestx_height
			}, guestx_speed);
			$("#trigger_special").animate({
				left: "288px"
			});
		};
		
		// Close Menu
		close_guestx = function() {
			$("#trigger_guestx a, #trigger_giftcards a").css("color", "#CCCCCC");
			$("#navigation_guestx-specialoff").animate({
					width: guestx_width_closed,
					height: "36px"
				}, 400);
				$("#trigger_special").animate({
					left: "132px"
				});
			$("#details_guestx, #details_special, #details_giftcards").fadeOut();
		};
		
		
		$("#trigger_guestx a").mouseenter(
      function () {
				clearTimeout(t_guestx_special);
				$(this).css("color", "#CCCCCC");
        open_guestx();
				$("#details_guestx").fadeIn();
				$("#details_special, #details_giftcards").fadeOut();
				$("#trigger_giftcards a").css("color", "#E6E6E6");
      }
		);
		
		$("#trigger_special a").mouseenter(
      function () {
				clearTimeout(t_guestx_special);
				$(this).css("color", "#9CBAC9");
        open_guestx();
				$("#details_guestx, #details_giftcards").fadeOut();
				$("#details_special").fadeIn();
				$("#trigger_guestx a, #trigger_giftcards a").css("color", "#E6E6E6");
      }
		);
		
		$("#trigger_giftcards a").mouseenter(
      function () {
				clearTimeout(t_guestx_special);
				$(this).css("color", "#CCCCCC");
        open_guestx();
				$("#details_guestx, #details_special").fadeOut();
				$("#details_giftcards").fadeIn();
				$("#trigger_guestx a").css("color", "#E6E6E6");
      }
		);
		
		$('#navigation_guestx-specialoff').mouseleave(
			function () {
				t_guestx_special = setTimeout('close_guestx();', 600);
			}
		);
		
		// CHILDREN MENU
		
		$('#navigation_children > li:last').addClass('last');
		
		
		// SECONDARY MENU
		
		$("#menu").mouseenter(
      function () {
				clearTimeout(t_secondary);
				$("#navigation_secondary").fadeIn();
      }
		);
		
		$("#navigation_secondary").mouseenter(
      function () {
				clearTimeout(t_secondary);
      }
		);
		
		$('#menu, #navigation_secondary').mouseleave(
			function () {
				t_secondary = setTimeout('hide_secondary();', 600);
			}
		);
		
		function tooltip(x) {
			t_tooltip = setTimeout(function(){
				$(x).find('.tooltip').fadeIn();
			}, 100);
		}
		
		$('#navigation_secondary li').hover(function() {
			tooltip(this);
		}, function() {
			clearTimeout(t_tooltip);
			$(this).find('.tooltip').fadeOut(200);
		});
		
		// OPEN EXTERNAL SITES IN NEW WINDOW
		
		$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");
		
		// INDEX SLIDESHOW
		
		function onBefore() {
			$('.rc h3').animate({
				color: "#FFFFFF"
			}, 1000);
		}
		
		function onAfter() { 
	    $('.rc h3')
				.html(this.alt)
				.animate({
					color: "#717073"
				}, 400);
		}
		
		$('#slideshow').cycle({
			fx: 'fade',
			before: onBefore,
			after: onAfter
		}); 
	
});
