$(document).ready(function () {
	// If no JS CSS menu will still work
	
	$("#menu").removeClass("cssonly");

	// Find subnav menus and slide them down
	$("#menu li a").hover(function(){
		$(this).parent().find("ul.subnav").slideDown(500);
		$(this).parent().find("ul.subnav").css('float','left');
		var parent_offset = Math.round($(this).parent().position().left);

		$(this).parent().find("ul.subnav").css('margin-left', parent_offset - 4);
		
		$(this).parent().hover(function() {
		}, function() {
			// On hovering out slide subnav menus back up
			$(this).parent().find("ul.subnav").slideUp(500);
			$(this).parent().parent().find('ul.mainMenu li a.main').stop().animate(
				{backgroundPosition:'(0 130px)'}, 
				{duration:500})
		
		})
	});
	
	$('ul.mainMenu li a.main')
		//.css( {backgroundPosition: '0 130px'} )
		.mouseover(function(){
			$(this).stop().animate(
				{backgroundPosition:'(0 145px)'}, 
				{duration:500})
			})
	
	// Navigation Animation
	//$('ul.mainMenu li a.main').css({backgroundPosition: '0 -30px'})
	
	//animate_menu();
	

});


function animate_menu()
{
		
	var increment = 500;

	$('ul.mainMenu li a.main').each(function(){

		$(this).stop().delay(increment).animate(
			{backgroundPosition:'(0 130px)'}, 
			{duration: 500}	
		)	
		
		increment += 500;
	});

	
	$('ul.mainMenu li a.main')
		//.css( {backgroundPosition: '0 130px'} )
		.mouseover(function(){
			$(this).stop().animate(
				{backgroundPosition:'(0 145px)'}, 
				{duration:500})
			})
}