/*
Scripts to handle the collection search in Bolton.

Requires jQuery library: jquery.js.


*/

$(document).ready(function(){
//activate the top menu link
$('span.navOpen').click(function(){window.location.href="./"});
//check term field exists
if($('#term').size()>0){
//initially the input search field is default, thus greyed it out
var term_val=$('#term').attr('value');
if(term_val==null){$('#term').attr('value','Enter search term');$('#term').attr('style','color:#bbbbbb');}
else if(term_val.toLowerCase=='Enter search term'.toLowerCase){$('#term').attr('style','color:#bbbbbb');}

$('#term').focus(function(){ 
						  if($('#term').attr('value')=='Enter search term')$(this).attr('value','');
						  $('#term').attr('style','color:#000000');
						  });
//when click outside the input box
// - if the input is empty, rewrite in it 'Enter search term' in pale grey
// - if the input is not Enter search term, don't change color.
$('#term').blur(function(){
						 if($(this).attr('value')=='Enter search term')
						 	{
								$(this).attr('value','Enter search term');$(this).attr('style','color:#bbbbbb');
							}
							else if($(this).attr('value')==null)
							{
								$(this).attr('value','Enter search term');$(this).attr('style','color:#bbbbbb');
							}
						});
$('#submit').click(function(){if($('#term').attr('value')=='Enter search term')$('#term').attr('value',''); return true;});

//automatically sort on changing criteria from drop-down menu
$('#sort-by').change(function(){$(this).parent().submit();return true;});
}
});
