
(function($) {
	/**
	 * $ is an alias to jQuery object
	 *
	 */
	$.fn.nav = function(settings) {
		//init main nav
		$('#main').html('<a id="nav1" href="http://www.iamheremlf.org/the-project/overview/"></a><a id="nav2" href="http://www.iamheremlf.org/about-mlf/"></a><a id="nav3" href="http://www.iamheremlf.org/how-to-help/"></a><a id="nav4" target="_blank" href="http://www.mlfnow.org/IAMHERE" onClick="javascript:pageTracker._trackEvent("donate", "nav", "global");"></a>');
		//main nav CSS
		$('#nav1').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav1.png") top left no-repeat', 'width' : '153px', 'height' : '44px' });
		$('#nav2').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav2.png") top left no-repeat', 'width' : '150px', 'height' : '44px' });
		$('#nav3').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav3.png") top left no-repeat', 'width' : '158px', 'height' : '44px' });
		$('#nav4').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav4.png") top left no-repeat', 'width' : '174px', 'height' : '44px' });
		//main nav hover CSS
		$('#nav1').hover(function() {
			$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav1-over.png") top left no-repeat', 'width' : '153px', 'height' : '44px' });
			_show_subnav();
		},function() {
			$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav1.png") top left no-repeat', 'width' : '153px', 'height' : '44px' });
		});
		
		$('#nav2').hover(function() {
			$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav2-over.png") top left no-repeat', 'width' : '150px', 'height' : '44px' });
		},function() {
			$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav2.png") top left no-repeat', 'width' : '150px', 'height' : '44px' });
		});
		
		$('#nav3').hover(function() {
			$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav3-over.png") top left no-repeat', 'width' : '158px', 'height' : '44px' });
		},function() {
			$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav3.png") top left no-repeat', 'width' : '158px', 'height' : '44px' });
		});
		
		$('#nav4').hover(function() {
			$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav4-over.png") top left no-repeat', 'width' : '174px', 'height' : '44px' });
		},function() {
			$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav4.png") top left no-repeat', 'width' : '174px', 'height' : '44px' });
		});
		
		//hover state for nav in order to close subnav after inactivity
		$('#nav').hover(function() {
			//nav hover
			if(closeSubNav){
				clearTimeout(closeSubNav);
			}
		},function() {
			//close subnav when nav is hovered off
			closeSubNav = setTimeout(_clear_subnav, 3000);
		});
		
		//set active link state
		switch(window.location.pathname)
		{
		case '/the-project/overview/': 
		$('#nav1').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav1-over.png") top left no-repeat', 'width' : '153px', 'height' : '44px' }).unbind();
		_show_subnav();
		$('#sub1').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub1-on.png") top left no-repeat' }).unbind();
		$('#nav').unbind();
		break;
		case '/the-project/how-it-happened/': 
		$('#nav1').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav1-over.png") top left no-repeat', 'width' : '153px', 'height' : '44px' }).unbind();
		_show_subnav();
		$('#sub2').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub2-on.png") top left no-repeat' }).unbind();
		$('#nav').unbind();
		break;
		case '/the-project/dannys-story/': 
		$('#nav1').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav1-over.png") top left no-repeat', 'width' : '153px', 'height' : '44px' }).unbind();
		_show_subnav();
		$('#sub3').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub3-on.png") top left no-repeat' }).unbind();
		$('#nav').unbind();
		break;
		case '/the-project/media/': 
		$('#nav1').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav1-over.png") top left no-repeat', 'width' : '153px', 'height' : '44px' }).unbind();
		_show_subnav();
		$('#sub4').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub4-on.png") top left no-repeat' }).unbind();
		$('#nav').unbind();
		break;
		case '/the-project/gallery/': 
		$('#nav1').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav1-over.png") top left no-repeat', 'width' : '153px', 'height' : '44px' }).unbind();
		_show_subnav();
		$('#sub5').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub5-on.png") top left no-repeat' }).unbind();
		$('#nav').unbind();
		break;
		case '/the-project/partners/': 
		$('#nav1').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav1-over.png") top left no-repeat', 'width' : '153px', 'height' : '44px' }).unbind();
		_show_subnav();
		$('#sub6').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub6-on.png") top left no-repeat' }).unbind();
		$('#nav').unbind();
		break;
		case '/about-mlf/': 
		$('#nav2').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav2-over.png") top left no-repeat', 'width' : '150px', 'height' : '44px' }).unbind();
		break;
		case '/how-to-help/': 
		$('#nav3').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav3-over.png") top left no-repeat', 'width' : '158px', 'height' : '44px' }).unbind();
		break;
		case '/donate/': 
		$('#nav4').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/nav4-over.png") top left no-repeat', 'width' : '174px', 'height' : '44px' }).unbind();
		break;
		}
		
		
		//close subnav function 
		function _clear_subnav() {
			$('#sub').html('');
		}
		
		function _show_subnav() {
			//add sub nav
			$('#sub').html('<a id="sub1" href="http://www.iamheremlf.org/the-project/overview/"></a><a id="sub2" href="http://www.iamheremlf.org/the-project/how-it-happened/"></a><a id="sub3" href="http://www.iamheremlf.org/the-project/dannys-story/"></a><a id="sub4" href="http://www.iamheremlf.org/the-project/media/"></a><a id="sub5" href="http://www.iamheremlf.org/the-project/gallery/"></a><a id="sub6" href="http://www.iamheremlf.org/the-project/partners/"></a>');
			//sub nav CSS
			$('#sub1').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub1.png") top left no-repeat', 'width' : '75px', 'height' : '20px' });
			$('#sub2').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub2.png") top left no-repeat', 'width' : '113px', 'height' : '20px' });
			$('#sub3').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub3.png") top left no-repeat', 'width' : '102px', 'height' : '20px' });
			$('#sub4').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub4.png") top left no-repeat', 'width' : '55px', 'height' : '20px' });
			$('#sub5').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub5.png") top left no-repeat', 'width' : '65px', 'height' : '20px' });
			$('#sub6').css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub6.png") top left no-repeat', 'width' : '72px', 'height' : '20px' });
			//sub nav hover CSS
			$('#sub1').hover(function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub1-over.png") top left no-repeat' });
			},function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub1.png") top left no-repeat' });
			});
			$('#sub2').hover(function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub2-over.png") top left no-repeat' });
			},function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub2.png") top left no-repeat' });
			});
			$('#sub3').hover(function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub3-over.png") top left no-repeat' });
			},function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub3.png") top left no-repeat' });
			});
			$('#sub4').hover(function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub4-over.png") top left no-repeat' });
			},function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub4.png") top left no-repeat' });
			});
			$('#sub5').hover(function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub5-over.png") top left no-repeat' });
			},function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub5.png") top left no-repeat' });
			});
			$('#sub6').hover(function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub6-over.png") top left no-repeat' });
			},function() {
				$(this).css({ 'background' : 'url("http://www.iamheremlf.org/wp-content/themes/mlf_theme/images/sub6.png") top left no-repeat' });
			});
		}

	};
})(jQuery); // Call and execute the function immediately passing the jQuery object
