var name = "#menu";  
var menuYloc = null; 

$(function(){
	$('#menu li').last().addClass('last');
	$('input').click(function(){
		$(this).val('');
	});
	
	// email subscription form 
	$('form .hidden').css({'display':'none'});
	$('form #CustomFields_183_82').click(function(){
		$('form .hidden').css({'display':'block'});
	});
	
	
	// move the nav when the page scrolls
	menuYloc = 0;	
	$(window).scroll(function () {  
		var offset = menuYloc;
		var offsetleft = $('#wrapper').offset().left;
		var scrolltop = $(document).scrollTop();
		if(scrolltop > 100){
			$(name).css({position:'fixed',top:offset,left:offsetleft});	
		}else{
			$(name).css({position:'absolute',top:'100px',left:'0'});		
		}
	});
	
	// Fix the left position of the nav if browser is resized horizontally
	$(window).resize(function () {
	    var offsetleft = $('#wrapper').offset().left;	   
		if($(name).css('position') == 'fixed'){
	    	$(name).css('left', offsetleft);  
		}
	});

	// Scroll to anchor when link is clicked in menu
	$('#menu a').click(function(){
		if(this.hash){
			var scrolltarget = $(this.hash).offset().top;
			$('body').scrollTo($(this.hash), 500);
			return false;
		}		
	});
	
	
});
