$(document).ready(function() {
    
	/**
	 * Toggle default text in location inputs
	 */
	$('#location-input, #search-input')
	  .focus(function() {
		if( this.value == this.defaultValue ) this.value = "";
	}).blur(function() {
		if( !this.value.length ) this.value = this.defaultValue;
	});
	
	
	/**
	 * Sandwich detail tabs show/hide
	 * Uses JQuery Tools tabs plugin to track history
	 */
	$("ul#detail-tabs").tabs("div#detail-panes > div", { current: 'active', history: true});
	
	
	/**
	 * Ensure floated menu rows are equal heights
	 * This may need to change depending on menu descriptions, etc. going forward
	 */
	$('.menu-entries').each(function() {
		
		maxHeight = 0;
		$children = $(this).find('.entry');
		
		$children.each(function(){
			thisHeight = $(this).height();
		    if(thisHeight > maxHeight) {
		        maxHeight = thisHeight;
		    }
		});
		
		$children.height(maxHeight);
	});
	
	
	/**
	 * Open external links in a new window
	 */
	$('a[href^="http"]').each(function() {
		if(this.href.indexOf(location.hostname.replace(/www./gi, "")) == -1
			// temp check - remove this after dns propagates and EE site_url is set to live domain
			&& this.href.indexOf('eng.ehclients.com') == -1 
			) {
			$(this).click(function() { window.open(this.href, "_blank"); return false; });
		}
	});


	/*
	 * Open PDFs in a new window
	 */
	$('a[href$=".pdf"]').each(function() {
		$(this).click(function() { window.open(this.href, "_blank"); return false; });
	});
	
});



/**
 * Special JS COOKIE handling methodes @see http://www.quirksmode.org/js/cookies.html
 */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
