$(document).ready(function(){
	var arrsections = new Array();
	
	arrsections[0] = new Array('hem');
	arrsections[1] = new Array('portfolio');
	arrsections[2] = new Array('projekt');
	arrsections[3] = new Array('tjanster');
	arrsections[4] = new Array('process');
	arrsections[5] = new Array('kunder');
	arrsections[6] = new Array('partners');
	arrsections[7] = new Array('kontakt');
						   
	function animateMenuLogo(menu) {
		var scrollposition = $(window).scrollTop();
		var top = $("#"+ menu +"").offset().top;
		var sectionheight = $("#"+ menu +"").next().outerHeight();
		
		//if (((top-30) < scrollposition) && ((top+sectionheight-30) > scrollposition)) {
		if (((top-18) < scrollposition)) {
			$('#menu li').removeClass("current_page_item");
			$("#menu li a[href='#"+ menu +"']").parent().addClass("current_page_item");
		} else {
			$("#menu li a[href='#"+ menu +"']").parent().removeClass("current_page_item");
		}		
	}


    $(window).scroll(
    	function() {
    		          
            for (var i = 0; i < arrsections.length; i++) {
            	animateMenuLogo(arrsections[i][0]);
            } 
            
    	}
   	);  
	
	
	$("#menu ul a").click(
		function(event) {
			event.preventDefault();
			var loc = $(this).attr("href");    
			var loc = loc.substring(1);
			var dest = 0;
			if (loc == "") {
				dest = 0;
			} else {
				dest = $("#"+ loc).offset().top;	
			}
			$("body, html").stop().animate({scrollTop: dest}, {duration:2000});
		}
	);
	
	$("a[href^=#]").click(
		function(event) {
			event.preventDefault();
			var loc = $(this).attr("href");    
			var loc = loc.substring(1);
			var dest = 0;
			if (loc == "") {
				dest = 0;
			} else {
				dest = $("#"+ loc).offset().top;	
			}
			$("body, html").stop().animate({scrollTop: dest}, {duration:2000});
		}
	);	
});