$(document).ready(function(){

	
//Rotaing drink Images in Header	
	$('#drink-pics').cycle({
		fx: 'fade',
		speed: 1500
		
	});


//Image Zoom

$("a.zoom").fancybox({

	'imageScale': true,
	'overlayShow': true,
	'zoomSpeedIn'			: 800,
	'zoomSpeedOut'			: 600,
	'easingIn'				: 'easeOutQuart',
	'easingOut'				: 'easeInQuart'
	
	});


//Event Filter

$("#show-all").click(function(){
       $(".event-row").slideDown();
       $("#date-filter ul li a").removeClass("current");
       $(this).addClass("current");
       return false;
});

$(".filter").click(function(){
        var thisFilter = $(this).attr("id");
        $(".event-row").slideUp();
        $("."+ thisFilter).slideDown();
        $("#date-filter ul li a").removeClass("current");
        $(this).addClass("current");
        return false;
});


//Form Ajax Submit


$("form.guestlist").ajaxForm({

	beforeSubmit: function() {
	
		return $("form#reservations").validate({
			
			rules: {
		email: {
		required: true,
		email: true
			}
		}
	}).form();
		
	},
	
	  success: function() {
	  	$('ul.event-form').hide("fast");
    	$('div.loading').hide("fast");
    	$('div.thankyou').show("fast");
    
    }
		
});


$("form#reservations").ajaxForm({

	beforeSubmit: function() {
	
		return $("form#reservations").validate({
			
			rules: {
		email: {
		required: true,
		email: true
			}
		}
	}).form();},
	
	  success: function() {
	  	$('form#reservations').hide("fast");
    	$('div.loading').hide("fast");
    	$('div.thankyou').show("fast");
    
    }
		
});



$("form#contact").ajaxForm({

	beforeSubmit: function() {
	
		return $("form#reservations").validate({
			
			rules: {
		email: {
		required: true,
		email: true
			}
		}
	}).form();
		
	},
	
	  success: function() {
	  	$('form#contact').hide("fast");
    	$('div.loading').hide("fast");
    	$('div.thankyou').show("fast");
    
    }
		
});



$("div.event").hover(function(){

	$(this).find('img.black-white').fadeOut("fast");
	$(this).find('img.color').fadeIn("fast");

},function(){
	$(this).find('img.color').fadeOut("fast");
	$(this).find('img.black-white').fadeIn("fast");
	
});


//Food and Drink Menu Switch
// perform JavaScript after the document is scriptable. 
$(function() { 
    // setup ul.tabs to work as tabs for each div directly under div.panes 
    $("ul.tabs").tabs("div.panes > div", {
    
    	effect: 'fade'
    
    }); 
});
$('#food_button a').click(function(){
	$('div#food-menu-intro-copy').toggle();
	$('div#drink-menu-intro-copy').toggle();
	return false
});

$('#drink_button a').click(function(){
	$('div#drink-menu-intro-copy').toggle();
	$('div#food-menu-intro-copy').toggle();
	return false
});


//Guetslist Overlay
$("a.guestlist-button[rel]").overlay({
	closeOnClick:	false,
	left: "center", 
	 expose: { 
        color: '#333', 
        loadSpeed: 100, 
        opacity: 0.5 
    },
    onLoad: function() {
    	//$(this).addClass("active");
    	
    } 
});


//show and hide global function

$("a.expander").click(function(event){

	var divToOpen = $(this).attr("href");

	$(divToOpen).slideDown("fast");
	
	event.stopPropagation();

	return false
	
});

$("div.expandee").click(function(e){

	 e.stopPropagation();


});


$(document).click(function(){

	$("div.expandee").slideUp("fast");
	
	
});

//Newsletter Ajax Submit


$("#subForm input:submit").click(function() {	
	
	// First, disable the form from submitting
	$('form#subForm').submit(function() { return false; });
	
	// Grab form action
	formAction = $("form#subForm").attr("action");
	
	// Hacking together id for email field
	// Replace the xxxxx below:
	// If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
	emailId = "mkdir";
	emailId = emailId.replace("/", "");
	emailId = emailId + "-" + emailId;
	
	// Validate email address with regex
	if (!checkEmail(emailId)) 
	{
		alert("Please enter a valid email address");
		return;
	}
	
	// Serialize form values to be submitted with POST
	var str = $("form#subForm").serialize();
	
	// Add form action to end of serialized data
	final = str + "&action=" + formAction;
	
	// Submit the form via ajax
	$.ajax({
		url: "proxy.php",
		type: "POST",
		data: final,
		success: function(html){
			$("#theForm").hide(); // If successfully submitted hides the form
			$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
		}
	});
});

function checkEmail(email)
	{	
		var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emailVal = $("#" + email).val();
		return pattern.test(emailVal);
	}

});//End of Document Ready