jQuery(function($){

//add alt classes for alternative themed areas
$('body#eating-house-page').addClass('alt');

	//controls for full screen image
	$("#full-screen-image").fullSizeImage({ 
		 overlayLine: true,
		 repositionImage : true,
		 offset : "185,0",
		 position : "fixed"
	});

	
	// TABS for CONTACT page
	$(".content-tab").click(function() {
		var div2show = $(this).attr("title");
		$(".content div").hide();
		$("#"+div2show).show();
		
		if (div2show == "text") {
			$(".content-tab").attr("src","images/job-opportunities.gif");
			$(".content-tab").attr("title","job-opportunities");
		} else {
			$(".content-tab").attr("src","images/view-text.gif");
			$(".content-tab").attr("title","text");
		}
	});
	
	// TABS for WEDDING page
	$("#brochure-tab").click(function() {
		
		if ($("#brochure").is(":visible")) {
			$(".content div").hide();
			$("#weddings-text").show();
			$("#brochure-tab").attr("src","images/brochure.gif");
		} else {
			$(".content div").hide();
			$("#brochure").show();
			$("#brochure-tab").attr("src","images/view-text.gif");
		}
	});
	
	
	//show/hide content
	var contentDisplay = 0;
	$('#main-content .text-tab').click(function () { 
		if(contentDisplay == 0) {
			 $('#main-content').animate({right: '-312' }, 750 );
			 $("#main-content .text-tab").attr("src","images/show-content.png");
			 $('#popup').fadeOut();
			 contentDisplay = 1;
		} else {
			$('#main-content').animate({right: '0' }, 750 );
			 $("#main-content .text-tab").attr("src","images/hide-content.png");
			 $('#popup').fadeIn();
			 $(".menu-containers").hide();
			 $(".menu-containers:first").show();
			contentDisplay = 0;
		}
	});
	
	$('#whatson').click(function(e) {
		e.preventDefault()
		$('#whatson-popup').fadeIn();
	});
	
	$('#special-offers').click(function(e) {
		e.preventDefault()
		//$('.menu-containers').fadeOut();
		//$('#popup').fadeOut();
		$('#popup').delay(250).fadeIn();
		$('.special-offers').delay(250).fadeIn();
	});
	
	var mybtnid
	
	$('.btnshow').click(function(e) {
		e.preventDefault()
		$('.menu-containers').fadeOut();
		$('#popup').fadeOut();
		mybtnid = $(this).attr("id")
		$('#popup').delay(350).fadeIn();
		//if (mybtnid == '') {
		//	$('.menu-containers').fadeIn();
		//} else {
		$('.'+ mybtnid).delay(350).fadeIn();
		//}
	});
	
	// //Show/Hide content for Eating House Page
	// var contentAltDisplay = 0;
	// $('.alt #main-content .text-tab').click(function () { 
	// 	if(contentAltDisplay == 0) {
	// 		 $('.alt #main-content').animate({right: '-312' }, 750 );
	// 		 $(".alt #main-content .text-tab").attr("src","images/show-content-alt.gif");
	// 		 $('#popup').fadeOut();
	// 		 contentAltDisplay = 1;
	// 	} else {
	// 		$('.alt #main-content').animate({right: '0' }, 750 );
	// 		 $(".alt #main-content .text-tab").attr("src","images/hide-content-alt.gif");
	// 		 $('#popup').fadeIn();
	// 		contentAltDisplay = 0;
	// 	}
	// });

	//Show/Hide content for Eating House Page - (sn0lan - 48847)
	var contentAltDisplay = 0;
	$('#main-content .text-tab-eating').click(function () { 
		if(contentAltDisplay == 0) {
			 $('#main-content').animate({right: '-312' }, 750 );
			 $("#main-content .text-tab-eating").attr("src","images/show-content-alt.gif");
			 contentAltDisplay = 1;
		} else {
			$('#main-content').animate({right: '0' }, 750 );
			 $("#main-content .text-tab-eating").attr("src","images/hide-content-alt.gif");
			contentAltDisplay = 0;
		}
	});
	
	//Show/hide Text Content/Menu List
	var menuDisplay = 0;
		$('.menu-tab').click(function () { 
			if(menuDisplay == 0) {
				$("img.menu-tab").attr("src","images/view-text.gif");
				$('.text').hide();
				$('.menus').show();
				if($('.sideeating').size() > 0)
				{
					$('.sideeating').hide();
				}
				menuDisplay = 1;
				
			} else {
				$("img.menu-tab").attr("src","images/view-menu.gif");
				$('.text').show();
				$('.menus').hide();
				if($('.sideeating').size() > 0)
				{
					$('.sideeating').hide();
				}
				menuDisplay = 0;
			}
		});
	
	//Show/hide Text Content/RATES
	$('.static-rates-tab').click(function () { 
		if($('.siderates').is(":visible")) {
			$("img.static-rates-tab").attr("src","images/btn-rates.gif");
			$('.kings-hotel-content').find('div:visible').hide();
			$('.sidedefault').show();
		} else if($('.sidecancellation').is(":visible")) {
			$("img.static-cancellation-tab").attr("src","images/btn-cancellation.gif");
			$("img.static-rates-tab").attr("src","images/view-text.gif");
			$('.kings-hotel-content').find('div:visible').hide();
			$('.siderates').show();
		} else {
			$("img.static-rates-tab").attr("src","images/view-text.gif");
			$('.kings-hotel-content').find('div:visible').hide();
			$('.siderates').show();
		}
	});
	
	//Show/hide Text Content/CANCELLATION
		$('.static-cancellation-tab').click(function () { 
			if($('.siderates').is(":visible")) {
				$("img.static-rates-tab").attr("src","images/btn-rates.gif");
				$("img.static-cancellation-tab").attr("src","images/view-text.gif");
				$('.kings-hotel-content').find('div:visible').hide();
				$('.sidecancellation').show();
			} else if($('.sidecancellation').is(":visible")) {
				$("img.static-cancellation-tab").attr("src","images/btn-cancellation.gif");
				$('.kings-hotel-content').find('div:visible').hide();
				$('.sidedefault').show();
			} else {
				$("img.static-cancellation-tab").attr("src","images/view-text.gif");
				$('.kings-hotel-content').find('div:visible').hide();
				$('.sidecancellation').show();
			}
		});
		
		
	// TAB for BOOKING FORM
	$(".sidebooking-tab").click(function() {
		$(".sidecancellation").hide();
		$("img.static-cancellation-tab").attr("src","images/btn-cancellation.gif");
		$(".siderates").hide();
		$("img.static-rates-tab").attr("src","images/btn-rates.gif");
		$(".sidedefault").hide();
		$(".sidebooking").show();
		location.href = location.href + "#booking";
	});
	
	//Tab for Eating house
	$(".sideeating-tab").click(function() {
		$(".sidecancellation").hide();
		$("img.static-cancellation-tab").attr("src","images/btn-cancellation.gif");
		$(".siderates").hide();
		$("img.static-rates-tab").attr("src","images/btn-rates.gif");
		$(".sidedefault").hide();
		$('.content div').not('h1,.sideeating').hide();
		$(".sideeating").show();
	});
		
	
	//show content popup
	$('.menu-item').click(function(e) {
		e.preventDefault();
		
		$('#popup').fadeIn();
		 $('#main-content').animate({right: '0' }, 750 );	
		 contentDisplay = 1;

	});	


	$('#whatson-close').click(function(e) {
		e.preventDefault();
		$('#whatson-popup').fadeOut();
	});

	$('#close').click(function(e) {
		e.preventDefault();
		
		$('#popup').fadeOut();
		$('#popup .menu-containers').hide();
		
		
		/*$('#main-content').animate({right: '-312' }, 750 );
		$(".alt #main-content .text-tab").attr("src","images/show-content-alt.gif"); 
		$("#main-content .text-tab").attr("src","images/show-content.png");
		contentAltDisplay = 1;
		contentDisplay = 1;
		*/
	});




	//image transition
$('#full-screen-image img:not(":first")').hide();
    var count=0;
    var countImages = $('#full-screen-image img').size();

    if(countImages>1){
        setInterval(nextImage,4000); //The number here dictates the length of time between the animation
    }

    function nextImage() {
        $('#full-screen-image img:eq('+count+')').fadeOut(1500); //Length of FadeOut transition
        if(count<countImages-1){
            count++;
        } else {
           	count=0;
        }
       $('#full-screen-image img:eq('+count+')').fadeIn(1500); //Length of FadeIn transition
    }	
	
	
	
	
	//select styling
	if (!$.browser.opera) {

        $('select.select').each(function(){
            var title = $(this).attr('title');
            if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
            $(this)
                .css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
                .after('<span class="select">' + title + '</span>')
                .change(function(){
                    val = $('option:selected',this).text();
                    $(this).next().text(val);
                    })
        });

    };
	
	//Fancybox magnify
	$("ul.gallery li a").append("<img src='images/magnify.jpg' class='magnify' />");
	$(".magnify").css({"opacity": 0});
	
	$("ul.gallery li a").hover(function(){
		$(this).children(".magnify").stop(true, true).animate({"opacity": 0.77});						
	}, function(){
		$(this).children(".magnify").stop(true, true).animate({"opacity": 0});	
	});

	
	//booking form
		
	//Fixed Footer for IE6(Why oh Fucking Why!)
	
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		var footerOpen=0;
		
		
		var windowHeight = $(window).height();
		var height = $(window).height() - 40;
		var top = $(document).scrollTop() + height;
		
		
		$("#footer-wrapper").css({
			"position": "absolute",
			'top': + top + "px",
			"left": 0
		});
	
		var footerTop = parseInt($('#footer-wrapper').css('top').replace('px',''));
		

		if(footerTop < windowHeight) {
			
			
			$(window).scroll(function(){
				if(footerOpen==0) {
					top = $(document).scrollTop() + height;
						$("#footer-wrapper").css({
						"position": "absolute",
						'top': + top + "px",
						"left": 0
					});	
				}
			});
		}

	}

	if ($('#booking-form form p').children().hasClass('error') || $('#booking-form p').hasClass('successText')){
		openFooter();
	}

//footer expand
	$(".expand").live('click', function(e) {
		e.preventDefault();
		
		$(this).removeClass('expand')
		$(this).addClass('close-footer').html("Close Enquiry");
		
		openFooter ();
		
		footerOpen = 1;
	});
	
	function openFooter(){
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
			
			var windowHeight = $(window).height();
			var height = $(window).height() - 40;
			var top = $(document).scrollTop() + height;
	
			$("#footer-wrapper").animate({
					"height": "245px",
					"top": top-175+"px"			
			}, {queue: false});
			
		} else{
			
			$("#footer-wrapper").animate({
				"height": "225px"
			}, {queue: false});
			
		}
			
	}
	

	$(".close-footer").live('click', function(e) {
		e.preventDefault();
		
		$(this).removeClass('close-footer');
		$(this).addClass('expand').html("Booking Enquiry");
									  
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		var windowHeight = $(window).height();
		var height = $(window).height() - 40;
		var top = $(document).scrollTop() + height;
		

		$("#footer-wrapper").animate({
				"top": top+"px",
				"height": "40px"
			}, {queue: false});
		} else{
			$("#footer-wrapper").animate({
				"height": "40px"
			}, {queue: false});
		}
		footerOpen = 0;
	});	

//Show/Hide Menus

$('.menus li a').click(function(e) {
	e.preventDefault()
	//create a variable which takes the name of the ID from the <a> link i.e. <a id="food-menu"></a> = 'food-menu' 
	var menuID = $(this).attr("id");
	//hide all the menu containers
	$('.menu-containers').hide();
	// '.'           = this is to say that this will be a class
	// '+menuID+'    = this pulls in the ID of the <a> link which is declared in the variable above
	// 	fadeIn()	 = then we do a basic fade in.
	$('#popup').fadeIn();
	$('.'+menuID+'').fadeIn();
});

//Tabs or Eating House

if ($('#booking-form form p').children().hasClass('error') || $('#booking-form p').hasClass('success')){
		$('.sideeating').show();
		$('.content div').not('h1,.sideeating').hide();
	}

});//end jquery

