$(function() {
	
	$("#access .menu-header ul li").eq(0)
		.css("background-image","url(/wp-content/themes/welovepeople/images/wlp-logo.png)")
		.css("background-repeat","no-repeat")
		.css("background-position","left center")
		.css("width","165px")
		.find("a").css("text-indent","-99999px")
		.css("background-image","none")
		.hover(function(){$(this).css("background-image","none")
	});
  		//$("#access .menu-header > ul > li").last().css("background-image","url(/wp-content/themes/welovepeople/images/heart.png)").css("background-repeat","no-repeat").css("background-position","right 16px").css("width","48px");  
  		$("#access .menu-header > ul > li")
		.eq(4)
		.find("a").css("float","left")
		.append("<img src='/wp-content/themes/welovepeople/images/heart.png' style='position:relative;top:2px;left:7px;padding:0 5px 0 0;'>");    
	
	$('#arkiv li:has(ul)').click(function(event) {
	
		$(this).css('list-style-image', $(this).children().is(':hidden') ? 'url(/wp-content/themes/welovepeople/images/minus.png)' : 'url(/wp-content/themes/welovepeople/images/plus.png)')
		$(this).children("ul").toggle('fast')
		return false
	})
	.css({cursor:'pointer', 'list-style-image':'url(/wp-content/themes/welovepeople/images/plus.png)'})
	.children().hide()

	$('#arkiv li:not(:has(ul))').click(function(event) { window.location = $(this).find("a").attr("href");return false })
		.css({cursor:'default', 'list-style-image':'none'})
    	
	$(".year").each(function(index) {
		var yearcount = $(this).parent("li").find('li.c-count').length;
		$(this).html(" ("+yearcount+")").show();
	});
	$(".month").each(function(index) {
		var monthcount = $(this).parent("li").find('li.c-count').length;
	$(this).html(" ("+monthcount+")").show();
	});

	$("#lock").mouseenter(function(){
		$("#customerlogin").fadeIn();     
		}).mouseleave(function(){
    $("#customerlogin").fadeOut();      
	});

	// WE BEGIN
	$(".we-submenu-links").bind('click',function(e){
		var newH = $(this).attr("href");
		existingHash = "";
		empUrl = 0;
		
		if (newH.indexOf("#") != -1) { 
			e.preventDefault();
			$("a.we-submenu-links").parent("li").removeClass("current_page_item");
			$(this).parent("li").addClass("current_page_item");						
			$('.jcarousel-control a[href="'+newH+'"]').trigger('click');							
			Cufon.refresh();
		}	
		
	});
	
	$("#we-employees-inner .employeeItem").bind('click',function(e){
		e.preventDefault();
		
		if ($(this).attr("href") != existingHash) {
			setHash($(this).attr("href"));
			//if (window.console) console.log("SETTING HASH FROM emp click func: "+existingHash); 
		}
		
		googlePageTrack('/we/'+$(this).attr("href"));
		
		if ($('a.we-submenu-links[href="#mennesker"]').parent("li").hasClass('current_page_item') == false) {			
			fakeClick("#mennesker");
			//if (window.console) console.log("fakeclicking #mennesker FROM emp click func: "); 
		}
		
		$("a.employeeItem").addClass("opacity-85");		
		$(this).removeClass("opacity-85");
		
		var theitem = $('.we-menu .current_page_item');
		var indexitem = $(".we-menu li").index(theitem);
		//var index = $("li").index(indexitem);
		//console.log(indexitem);
		
		$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper").hide().html("<div class='floatleft'><h1></h1></div><div class='floatright'><img src='' /></div><div class='clear'></div>");
		// afspejle den markup der er i 2 column typen
		
		$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper .floatright img").attr("src","");
		$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper .floatleft").html("");
		
		var fullname = $(this).find(".employee-info .firstname").html()+' '+$(this).find(".employee-info .lastname").html();
		var title = $(this).find(".employee-info .jobtitle").html();
		var intro = $(this).find(".employee-info .intro").html();
		var email = $(this).find(".employee-info .email").html();
		var email_url = "/wp-content/themes/welovepeople/images/icon_mail.png";
		var phone = $(this).find(".employee-info .phone").html();		
		var mobile = $(this).find(".employee-info .mobile").html();
		var mobile_url = "/wp-content/themes/welovepeople/images/icon_mobile.png";
		var twitter = $(this).find(".employee-info .twitter").html();
		var twitter_url = "/wp-content/themes/welovepeople/images/icon_twitter.png";
		var blog = $(this).find(".employee-info .blog").html();
		var blog_url = "/wp-content/themes/welovepeople/images/icon_blog.png";
		var fullimage = $(this).find(".employee-info .fullimage").html();
		var divider_url = "/wp-content/themes/welovepeople/images/icon_divider.png";
								
		$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper .floatleft").append("<h1 class='emp_h1'>"+fullname+"</h1>");
		$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper .floatleft").append("<h4 class='emp_h4' style='margin:-20px 0 0 0;'>"+title+"</h4>");
		$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper .floatleft").append("<p class='emp_text'><img src='"+divider_url+"'><br>"+intro+"</p>");	
		
		$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper .floatleft").append("<div class='emp_social'></div>");
		
		//if (mobile !== "") {$("ul#frontpage-slider li").eq(2).find("#frontpage-slider-wrapper .floatleft .emp_social").append("<span><img src='"+mobile_url+"'></span>");}
		if (email !== "") {$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper .floatleft .emp_social").append("<a class='emp_mail' href='mailto:"+email+"'><img src='"+email_url+"'></a>");}
		if (twitter !== "") {$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper .floatleft .emp_social").append("<a href='http://twitter.com#"+twitter+"' target='_blank'><img src='"+twitter_url+"'></a>");}
		if (blog !== "") {$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper .floatleft .emp_social").append("<a href='"+blog+"' target='_blank'><img src='"+blog_url+"'></a>");}
		
			
		$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper .floatright img").attr("src",fullimage);		
		Cufon.refresh();
		$("ul#frontpage-slider li").eq(indexitem).find("#frontpage-slider-wrapper").delay(250).fadeIn(600);

	});
	// WE END
	
	// CASES BEGIN	
	// CASES END

  
});


function fakeClick(existingHash) {	
	$('#main a[href="'+existingHash+'"]').trigger('click');
}

// HASH FUNCTIONS
function getHash() {
	return window.location.hash;
}
function setHash(newHash) {
	window.location.hash = newHash;		
}

function googleTrack(category,action,label) {
	//	analytics push event
_gaq.push(['_trackEvent', category, action, label]);
	//	alert(category+'-'+action+'-'+label);	
	//console.log('eventtrack: cat:'+category+' action:'+action+' label: '+label);			
}
function googlePageTrack(page) {
_gaq.push(['_trackPageview',page]);
//console.log('pagetrack: '+page);	
}
