jQuery(function($) {

//logo reveal
$('#logo img').hide();
$('#logo img').ready(function(){
	$('#logo img').fadeIn(3000);
});


//Nav Animation
$('nav ul li a').mouseenter(function(){
		$(this).stop().animate({'left':'3px'},100).animate({'left':'0px'},100).animate({'left':'3px'},100).animate({'left':'0px'},100);
		$(this).next().stop().animate({'left':'-3px'},100).animate({'left':'0px'},100).animate({'left':'-3px'},100).animate({'left':'0px'},100);
	}).mouseleave(function(){
		$(this).stop(true,true).animate({'left':'0px'},100);
		$(this).next().stop(true,true).animate({'left':'0px'},100);
	});

//Image Transition
if($('#image-trans img').size()>1){
		$('#image-trans').jqFancyTransitions({ width: 560, height: 315, delay: 4000, titleOpacity:0 });
	}

	//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() - 50;
		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 ($('#sign-up-form .form p').children().hasClass('error') || $('#sign-up-form p').hasClass('successText')){
		openFooter();
	}

//footer expand
	$(".joinus-btn").live('click', function(e) {
		e.preventDefault();
		
		$(this).removeClass('joinus-btn')
		$(this).addClass('close-footer').html("Close");
		$('.booktable-btn').html("Win a Bar Tab").removeAttr("href");
		
		openFooter ();
		
		footerOpen = 1;
	});
	
	function openFooter(){
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
			
			var windowHeight = $(window).height();
			var height = $(window).height() - 50;
			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('joinus-btn').html("Win a Bar Tab");
		$('.booktable-btn').html("Book a Table").attr("href", "bookings.php");
									  
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		var windowHeight = $(window).height();
		var height = $(window).height() - 50;
		var top = $(document).scrollTop() + height;
		

		$("#footer-wrapper").animate({
				"top": top+"px",
				"height": "50px"
			}, {queue: false});
		} else{
			$("#footer-wrapper").animate({
				"height": "50px"
			}, {queue: false});
		}
		footerOpen = 0;
	});


//rightcol buttons
$('.btn-hover').hover(function(){
		$(this).children('img').stop(true, true).animate({'opacity': 0});
	   }, function(){
		$(this).children('img').stop(true, true).animate({'opacity': 1});
});

	
//Facebook Like Show/Hide

$('#facebook-like2').hide();
$('.facebook').mouseenter(function() {
	$('#facebook-like').hide();
	$('#facebook-like2').show();
}).mouseleave(function(){
	$('#facebook-like').show();
	$('#facebook-like2').hide();
});

//Gallery page selection
	$('ul.gallery').hide();
	$('ul.gallery:first').fadeIn();
	$('select#gallery-selector').change(function(){
		$('ul.gallery:visible').hide();
		var galleryId = $(this).val();
		$('ul.gallery#'+galleryId).fadeIn();
	})

//FancyBox Lightbox
		
	$("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 code

var resHourBox = $('select[name=reservation-time-hour]');

if(resHourBox.length) {
	var resMinBox = $('select[name=reservation-time-minute]');

	function refresh_time_options() {
		var prevHour = resHourBox.val();
		if (prevHour == '19') {
			resMinBox.find('option[value="45"]').remove();
		} else if (resMinBox.find('option[value=45]').length == 0) {
			resMinBox.append('<option value="45">45</option>');
		}
	}
	
	resHourBox.change(function() {
		refresh_time_options();
	});

	refresh_time_options();

	$('select[name^="reservation-date"]').change(function() {
		var day = $('select[name="reservation-date-day"] option:selected').val();
		var month = $('select[name="reservation-date-month"] option:selected').val();
		if (day == '' || month == '') return;
		var year = new Date();
		var date = new Date(year.getFullYear(), month - 1, day, 0, 0, 0, 0);
		
		$('select[name="reservation-time-hour"] option').remove();
		$('select[name="reservation-time-hour"]').append('<option value="">HH</option>');
		
		$('select[name="reservation-time-minute"] option:selected').removeAttr("selected");
		
		if (date.getDay() == 6 || date.getDay() == 0) {
			// Saturday or Sunday
			for (i = 13; i <= 19; i++) {
				$('select[name="reservation-time-hour"]').append('<option value="'+i+'">'+i+'</option>');
			}
		} else {
			// Weekday
			for (i = 17; i <= 19; i++) {
				$('select[name="reservation-time-hour"]').append('<option value="'+i+'">'+i+'</option>');
			}
		}
	});
}

	
});//end jquery

