$(document).ready(function(){
    
	var url = window.location.pathname;
	var filename = url.substring(url.lastIndexOf('/')+1);
	$("ul#nav li a").css({"opacity" : 0})
	
	/** Main nav mouse over / mouse out **/
	$("ul#nav li a").hover(function(){
		$(this).stop().animate({"opacity" : 1}, 200);
	}, function(){		
		$(this).stop().animate({"opacity" : 0}, 100);
		if($(this).attr("id") == "current") {
			$(this).stop().css({"opacity" : 1});
		}	
	});
	// active state
	$("ul#nav li a").each(function() {
		var hreflink = $(this).attr("href");
		if(hreflink.toLowerCase() == "http://www.fatbike.co.uk"){
			$("ul#nav li.home a").attr("id", "current").css({"opacity" : 1});
		}
		if (hreflink.toLowerCase()==filename) {
			$(this).attr("id", "current").stop().css({"opacity" : 1});
			$("ul#nav li.home a").removeAttr("id").css({"opacity" : 0});
			if(filename == "technical.php"){
				$("#ul-sub-nav li a.technologies").addClass("subnavactive");
			}
		}
	})
	/** Footer nav **/
	$("#footer-nav li a").each(function(){
		var hrefvalue = $(this).attr("href");
		if(url == "/") {
			$("#footer-nav li a.first").addClass("active");
		}
		if(hrefvalue == filename) {
			$(this).addClass("active");
		}
	})
});
