var defaultLocationPhrase = 'City, State';

/**
 * Additional onload functionality
 */
$(document).ready(function() {
	if($('#keyword_input').isDefined()) {
		$('#keyword_input').inputToggle('Search');
		$('#location_input').inputToggle(defaultLocationPhrase);
		$('#location_input').keypress(function (e) {
		      if (e.which == 32 || (65 <= e.which && e.which <= 65 + 25)
                    || (97 <= e.which && e.which <= 97 + 25)) {
		    	  if($('#location_error').isDefined()) $('#location_error').fadeOut();
		    }
		  });
	}
	$('.rounded').corners();    
	
	$("#top_nav a.psuedo-link").hover(function() {
	      $(this).parent().find("ul.subnav").slideDown('fast').show();
	      $(this).parent().hover(function() {
	      }, function(){
	        $(this).parent().find("ul.subnav").slideUp('fast');
	      });
	    }).hover(function() {
	      $(this).addClass("subhover");
	    }, function(){
	      $(this).removeClass("subhover");
	    });
	
	
	
	if(typeof(pageMode)=='undefined') return;
	
	if(pageMode=='index') {
		if($('#quickMapInput').isDefined()) $('#quickMapInput').inputToggle(defaultLocationPhrase);
		var map = new GMap2($('#mapContainer')[0]);
		map.setCenter(new GLatLng(35,-95), 3);
	}
	
	$('#popular-searches a.psuedo-link').click(function (e) {
		$('.popsearch-popup').hide();
	    var $div = $(e.target).next('.popsearch-popup');
		$div.slideDown();
	    e.preventDefault();
	    
	    return false;
	});
	
});

jQuery.fn.isDefined = function() {
	return typeof($(this)[0]) != 'undefined';
}
jQuery.fn.inputToggle = function(phrase) {
	var t = $(this);
	if(t.val() == '') t.val(phrase);
	t.bind("focus", function(e) {
		if(t.val() == phrase) t.val('');
	});
	t.bind("blur", function(e) {
		if(t.val() == '') t.val(phrase);
	});
}
