$(document).ready(function(){
	updateClock(); setInterval(function() { updateClock(); }, 1000);
	
	jQuery.easing.def = 'easeOutQuint';
	var el; var p; var posstore; var valstore;
	
	var curel = $("#nav ul ul.current"); p = curel.offset();
	$('#content-arrow').stop(true, true).animate({top:((p.top) - 28)}, {duration: 300});
	
	$('#nav ul ul').hover(function() {

		el = $(this);
		p = el.offset();
		posstore = (p.top) - 28;
  		$('#content-arrow').stop(true, true).animate({top:((p.top) - 28)}, {duration: 500});
		
	}, function() {
		
		p = curel.offset();
		$('#content-arrow').stop(true, true).delay(300).animate({top:((p.top) - 28)}, {duration: 300});
		
	});
	
	$('#content-arrow').hover(function(){
        $('#content-arrow').stop(true, true).offset({top:posstore});
	}, function() {
		
		p = curel.offset();
		$('#content-arrow').stop(true, true).delay(300).animate({top:((p.top) - 28)}, {duration: 300});
		
	});
	
	$('#search').focus(function(){ valstore = $('#search').val(); $('#search').val(''); });
	$('#search').blur(function(){
		if($('#search').val() == ''){
			$('#search').val(valstore); 
		}
	});
	
	function updateClock(){
		var currentTime = new Date ( );
		var currentHours = currentTime.getHours ( );
		var currentMinutes = currentTime.getMinutes ( );
		var currentSeconds = currentTime.getSeconds ( );
		// Pad the minutes and seconds with leading zeros, if required
		currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
		currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
		// Choose either "AM" or "PM" as appropriate
		var timeOfDay = ( currentHours < 12 ) ? "am" : "pm";
		// Convert the hours component to 12-hour format if needed
		currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
		// Convert an hours component of "0" to "12"
		currentHours = ( currentHours == 0 ) ? 12 : currentHours;
		// Compose the string for display
		var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
		// Update the time display
		$("a.time").html(currentTimeString);
	}
	
	$('div#nav a').each(function() {
		if($(this).attr('href') == window.location){
			$(this).addClass('current');
		}
	});

});
