$(document).ready(function() {
  
  // gives us the pretty round edges without the hassle of using multiple background images etc.
  $("#nav_container .left").corner("round tl 5px");
  $("#nav_container .right").corner("round tr 5px");
  $("#feature").corner("round 8px");
  
  // sets and unsets the search text in the global search box
  $("#sp-searchtext").attr("value", "Search");
  $("#sp-searchtext").focus(function() {
    if ($(this).attr("value") === "Search") {
      $(this).attr("value", "");
    } else {
      $(this).select();
    }
  });
  $("#sp-searchtext").blur(function() {
    if ($(this).attr("value") === "") {
      $(this).attr("value", "Search")
    }
  });
  
  // clicking anywhere on the feature take us to the gallery
  $("#feature").click(function() {
  	document.location.href = $("#feature_link").attr("href");
  });  
  
  // START - navigation links - hover - ignore current section (on)
  $(".container .nav_links li a img").mouseover(function() {
    if ($(this).attr("src").indexOf('_on.gif') <= 0) {
      $(this).attr("src", $(this).attr("src").replace(".gif", "_hover.gif"));
    }
  });
  $(".container .nav_links li a img").mouseout(function() {
    if ($(this).attr("src").indexOf('_on.gif') <= 0) {
      $(this).attr("src", $(this).attr("src").replace("_hover.gif", ".gif"));
    }
  });
  // END - navigation links - hover
  
  // lightbox photos
  $('a[@rel*=thumb]').lightBox();
	
	// set the focus to the first error form field if it exists
	$('div.fieldWithErrors input:first').focus();
	
	$('div.flash').fadeOut(5000);
	
	// removes leading and trailing whitespace from email fields
  $(".text").change(function () {
    $(this).attr("value", jQuery.trim($(this).attr("value")));
  });
  
	// form validation. the first form is always the search button, so get the second
	$("form[1]").validate();
	
});