jQuery(function($){
	var element_groups = {
	
		'navagation': function(){
			
			//set a inactivity timeout
			var hide_nav_in = 2;
							
			//add the class allowing for overriding css hover
			$('div.navigation div.button a, div.logo a', '#header').addClass('js');
			
			//create a background for the hover
			$('<div id="nav_hover"></div>').appendTo('body').css({
				'background': '#000',
				'position': 'absolute',
				'-moz-border-radius': 6,
				'-webkit-border-radius': 6,
				'border-radius': 6,
				'display': 'none',
				'padding': '6px 10px',
				'z-index': 0
			});
			
			//move the hover effect under the hovered navigation link
			$('div.navigation div.button a, div.logo a', '#header').hover(function(){
				
				//if a timeout loop exists clear it
				if(typeof hide_nav_loop !== 'undefined'){
					clearInterval(hide_nav_loop);
				}
				
				//set a inactivity timeout
				hide_nav_in = 100;
				
				//get the coords, height, and width for the hovered button
				var button = {
					'left': $(this).offset().left,
					'top': $(this).offset().top,
					'width': $(this).width(),
					'height': $(this).height()
				}
			
				//if visable animate, if not fade in
				if($('#nav_hover').hasClass('active')){
					$('#nav_hover').animate({
						'left': button.left,
						'top': button.top,
						'width': button.width,
						'height': button.height
					}, 200);
				}
				else{
					$('#nav_hover').addClass('active').css({
						'left': button.left,
						'top': button.top,
						'width': button.width,
						'height': button.height
					}).fadeIn(200);
				}
				
			},
			function(){
			
				//start an inactivity counter to hide the hover effect after inactivity
				hide_nav_loop = setInterval(function(){
					if(hide_nav_in > 0){
						hide_nav_in -= 1;
					}
					else{
						$('#nav_hover').fadeOut('300', function(){
							$(this).removeClass('active');
						});						
						clearInterval(hide_nav_loop);
					}
				}, 1);
				
			});			
		},
		
		'contact_form': function(){
			
			//set the css up and activate nice labels
			$('form p', 'div.contact_form').css({
				'position': 'relative'
			});
			$('form p label', 'div.contact_form').css({
				'position': 'absolute',
				'top': 0,
				'left': 0,
				'color': '#000'
			}).inFieldLabels();
			
			//expand the textarea as needed
			$('form p textarea', 'div.contact_form').autoResize({
			    animateDuration: 300,
			    extraSpace: 40,
			    limit: 420
			});
			
		}		
		
	}
	
	element_groups.navagation();
	element_groups.contact_form();
});