/* does as it's name */	

function emptyFieldOnFocus(fieldNameSelector)
{
	$(fieldNameSelector).focus( function(){ $(this).val(''); } );
}
	
	


$(document).ready(function(){


/* Focus the login box */
	$('#user').focus();


/* University News - Main central section */	
	$("#universityNews li").hover(
		function(){
			$(this).css('background-color','#e0efff');
		},
		function(){
			$(this).css('background-color','#fff');
		}
	);
	
	$("#universityNews li a").click(function(){
		if ($(this).attr('href') != '#')
		{
			window.location.href = $(this).attr('href');
		}
		return false;
	});
	$("#universityNews li").click(function(){

		// h3Title is a global her, so can be accessed elsewhere
		h3Title = $(this).children('h3')[0].innerHTML;

		if (this.style.height=='auto')
		{
			// collapse this
			$(this).height('75px');

			// Set the tooltip
			$(this).attr( 'title', "View more about '" + h3Title + "'");
		} else
		{
			// collapse siblings
			$(this).siblings().each(
				function()
				{
					// Collaspe
					$(this).height('75px');
					// Reset the tooltip
					$(this).attr( 'title', "View more about '" + $(this).children('h3')[0].innerHTML + "'");
				}
			);

			// and then

			// expand this
			$(this).height('auto');

			// Set the tooltip to be blank
			$(this).attr( 'title', "");
		}
		return false;
	});

		

/* Sign in link */
	$('.signin').click(function(){
		
		$('#user').focus();
		$('.login').css('background-color','#ac9');
	});
	
/* Reset the form bg color on form blur */
	$('#user').blur(function(){
		$('.login').css('background-color','#e0efff');
	});
	
	
	
/* Person Search tab selection */

	// $.tabs('personSearch');
	$('#personSearch').tabs();//{ fxSlide: true });
	

/* Empty file on focus */	

emptyFieldOnFocus("#q"); // Search - top RHS
emptyFieldOnFocus(".suggest"); // Person search fileds

/* Person Search submit */

 $('#personUK').submit( 
 	function()
 	{
 		if ($("input[@name='searchUK']:checked").val() == "staff") 
 		{ 
 			formAction = "http://www.nottingham.ac.uk/cgi-bin/directory_lookup.cgi?surname2="
 				+ $("#surnameUK").val().replace("'",'%27')
 				+ "&initials=&number=&department=All+departments";
  		}
 		else
 		{
  			formAction = "http://www.nottingham.ac.uk/cgi-bin/student_lookup.cgi?surname="
 				+ $("#surnameUK").val().replace("'",'%27')
 				+ "&initials=&submit=Search+";
 		}
 		window.open(formAction);
 		return false;
 	}
 );
 
 $('#personChina').submit( 
 	function()
 	{

 		formAction = "http://www.nottingham.ac.uk/contacting/staff-look-up-unnc.phtml?unc_surname="
			+ $("#surnameChina").val().replace("'",'%27')
			+ "&unc_initial=&unc_dept=&search=Search";

 		window.open(formAction);
 		return false;
 	}
 );
 
 $('#personMalaysia').submit( 
 	function()
 	{
 		formAction = "http://www.nottingham.ac.uk/contacting/staff-look-up-unmc.phtml?unim_surname="
			+ $("#surnameMalaysia").val().replace("'",'%27')
			+ "&unim_dept=&search=Search&search=Search";
 		
 		window.open(formAction);
 		return false;
 	}
 );
 
 
 
 
 /* PG PSP login form - prefix with 'pg_' if omitted */
 
 $('#pg_psp_login').submit(function(){
 	
 	var username = $('#pg_psp_login #user').val();
 	if( username.substring(0,3) != 'pg_')
 	{
 		$('#pg_psp_login #user').val('pg_'+username);
 	}
	
 });

 
}); //document.ready
