$(document).ready(function() {
	$('body#home').find('#directions').find("a#open").click(function(){
		$("#map").addClass("on-screen");
		return false;
	});
	
	$('body#home').find('#directions').find(".close-button").click(function(){
		$("#map").removeClass("on-screen");
		return false;
	});
	
	// $('body#home').click(function(event){
	// 		if( $('#map').is(".on-screen") ){
	// 			$('#map').removeClass('on-screen');
	// 			}
	// 	})


	$('body#home').find('#our-story').find('a#open').click(function(){
		$("#story").addClass("show");
		return false;
	});
	
	$('body#home').find("#our-story").find('a.close-button').click(function(){
		$("#story").removeClass("show");
		return false;
	});
	
	// $('body#home').click(function(event){
	// 		if( $('#story').is(".show") ){
	// 			$('#story').removeClass('show');
	// 			}
	// 	})


	$('body').find('#space-rental').find('a#open').click(function(){
		$('#space-rental-full-content').addClass('show');
		return false;
	});
	
	$('body').find('#space-rental').find('a.close-button').click(function(){
		$('#space-rental-full-content').removeClass('show');
		return false;
	});
	
	
	// $('body').click(function(event){
	// 		if( $('#space-rental-full-content').is('.show') ){
	// 			$('#space-rental-full-content').removeClass('show');
	// 			}
	// 	})


	$('body').find('#book-an-event').find('a#open').click(function(){
		$('#event-form').addClass('show');
		return false;
	});
	
	$('body').find('#book-an-event').find('a.close-button').click(function(){
		$('#event-form').removeClass('show');
		return false;
	});
	$("body").find("#event-form #dropdown").find("form").each(function(){
		$(this).find('input[type=text], textarea').clearonfocus();
	});
	
	
	$('body').click(function(event){
		if( !($(event.target).parents("#event-form")[0]) ){
			if( $('#event-form').is('.show') ){
				$('#event-form').removeClass('show');
			}
		}
	})

//Catering confirmation and failure message
$('body').click(function(){
 		if( $('#event-form-success').is('.show') ){
	 			$('#event-form-success').removeClass('show');
	 			}
	})



//Space Rental confirmation and failure message
 	$('body').click(function(){
 		if( $('#space-rental-success').is('.show') ){
	 			$('#space-rental-success').removeClass('show');
	 			}
	})



//The Backyard event form dropdown
	$('body').find('#event-form').find('a#open').click(function(){
		$('#dropdown').addClass('show');
		return false;
	});
	
	$('body').find('#event-form').find('a.close-button').click(function(){
		$('#dropdown').removeClass('show');
		return false;
	});
	
	$('body').click(function(event){
		if( !($(event.target).parents("#dropdown")[0]) ){
			if( $('#dropdown').is('.show') ){
				$('#dropdown').removeClass('show');
			}
		}
	})
	
	
//Lightbox Activator
	//$(function(){
		$('body').find('a[rel=lightbox]').lightBox()
	//});
	
		
});

jQuery.fn.clearonfocus = function() {
	return this
		.bind('focus', function() {
			if ( !this.defaultValue ) this.defaultValue = this.value;
			if ( this.defaultValue && this.defaultValue != this.value ) return;
			this.value = '';
		})
		.bind('blur', function() {
			if ( this.value.match(/^\s*$/) )
				this.value = this.defaultValue;
		});
};


$('body').find('.category-name').click(function(){
	$('.product-category').addClass('selected');
	return false;
});
