/*

CLAS web services

www.clas.uiowa.edu/web/

*/



/*

Drop down functionality for local navigation

*/

function dropDown() {

  $('#local_navigation ul').hide();

  $('#local_navigation li:has(li)').addClass('has_children');

  

  $('#local_navigation li a').click(function(event) {

    if ( $(this).parent().hasClass('has_children') )

	{

		event.preventDefault();

		$(this).next().toggle();

	}

	

	$.cookie('show_last_selection', null);

	$.cookie('show_last_seleciton', $(this).text());

  });

  

  var last = $.cookie('show_last_selection');

  $("local_navigation li a[text='" +last+ "']").parents().show();

}



/*

Auto-selecting navigation

*/

function autoSelect() {  

  var currentLocation = location.pathname.substring(0);

  var p = currentLocation.slice(0, currentLocation.lastIndexOf('/') + 1);

  

  if (currentLocation.match('index.shtml')) {

	  $("#local_navigation a[href='" +p+ "']").addClass('selected');

	  $(".selected").parents().show();

  } else {

	  $("#local_navigation a[href='" +currentLocation+ "']").addClass('selected');

	  $(".selected").parents().show();

  }

}



function searchSwap() {

  var searchField = $('#search_field');

  var defaultValue = 'Search...';

  

  searchField.focus(function() {

    if ( $(this).attr('value') == defaultValue )

	{

		$(this).attr('value', '');

	}

  });

  

  searchField.blur(function() {

    if ( $(this).attr('value') == '' )

	{

		$(this).attr('value', defaultValue);

	}

  });

}



$(document).ready(function() {

  dropDown();

  autoSelect();

  searchSwap();

});
