// namespace
$.femme = {
	global: {}
};

$(document).ready(function(){
    if ($.browser.safari) {
        $("body").addClass("webkit");
    };
	
	// initialize header
	if($("body").hasClass("home")) {
		$.femme.global.Header = new $.femme.Header({mode: "static"});
	} else {
		$.femme.global.Header = new $.femme.Header();
	}
});


$.femme.Header = function(options) {
	var settings = $.extend({
		mode: ""		 
	}, options);
	
	// INITIALIATION
	var $menu = $("#menu");
	var $menuLinks = $("#menu a");
//	var $content = $("#content");
//	var $contentContainer = $("#contentContainer");
	
//	new $.femme.Search();
	
	$menuLinks.click(scrollPage);
	
	//if we enter a URL containing a hash, make it active and scroll to it
	var $active =  $("#menu a[href='"+window.location.hash+"']");
	$active.addClass("active");
	$(window).load(function(){
	    $active.click();
	});
	
	// BIND EVENTS
	
	
	var hash = window.location.hash;
	setInterval(function() {
		if(window.location.hash != hash) {
			hash = window.location.hash;
			$menuLinks.removeClass("active");
			$("#menu a[href='"+window.location.hash+"']").addClass("active");
			if(!$.browser.msie) {
				$("#menu a[href='"+window.location.hash+"']").click();
			}
		}
	}, 100);
	
	// private functions
	function scrollPage(e) {
		e.preventDefault(e);
		
		$menuLinks.removeClass("active");
		e.target.className += " active";
		//SCROLL HANDLING
		//get the href value
		var whereTo = $(this).attr("href");
		var targetLink = whereTo.substring(1); //remove hash
		var offset = parseInt($("#header").css("height"));
		
		//if there is a div on this page where id = whereTo, then scroll to it
		if($("#"+targetLink).text() != ''){
			$.scrollTo( $("#"+targetLink), 1000, {axis: 'y', easing: '',  
			onAfter:function(whereTo) {
				setTimeout(function() {
					window.location.hash = targetLink;
					hash = window.location.hash;
				}, 100);
			}} );
		} else{
			window.location = rootPath + whereTo;
		}
	}
	
	
};

(jQuery);

