 	$(function(){
		$(".toggleListElement").click(function(){
			$(this).css({cursor: "pointer"});
			$(this).removeAttr("href");
			if($(this).parent().find("ul").is(":hidden")){
				$(this).parent().find("ul").css({display: "block"})
			} else {
				$(this).parent().find("ul").css({display: "none"})
			} 
		});
		
		$(".pageLinkDetail").click(function() { 
			$(".liDetail").each(function(i) {
				$(".liDetail").attr({className : "liDetail"});
			});

			$(this).css({cursor: "pointer"});
			$(this).parent().attr({className : "liDetail active"});
			
			getvestigingDetail($(this).attr("rev"), $(this).attr('href'))
		});
		
		$(".serviceAreaVestiging").click(function() { 
			getvestigingDetail(0, $(this).attr('href'))
		});
		
		
		$(".menuVestiging").click(function() { 
			getvestigingDetail(0, $(this).attr('href'))
		});
		
		checkUrl();
 	});

function getvestigingDetail(id, urlLink) {
	$(".contentAreaRightLarge").html("<div class=\"dataLoader\">\n<img src=\"/images/layout/loader.gif\" alt=\"De vestiging wordt geladen\" /><br />\n<label>De vestiging wordt geladen.</label>\n</div>");
	if(id == 0 && urlLink != "")
	{
		if(urlLink.indexOf('/vestiging/#/') == 0)
			urlLink = urlLink.substr(11);
		
		$.post("/vestiging-detail.php",{url : urlLink.substr(2)},
		function(data) {
			$(".contentAreaRightLarge").html(openDepartment(data));
		});
		
		$(".liDetail").each(function(i) {
			$(".liDetail").attr({className : "liDetail"});
		});
	}
	else
	{
		$.post("/vestiging-detail.php",{contactId : id},
		function(data) {
			$(".contentAreaRightLarge").html(openDepartment(data));
		});
	}

	location.href = urlLink;
}

function openDepartment(data)
{
	$('#dep'+data.substring(0,data.indexOf('-||-'))).css({display: "block"});
	return data.substring(data.indexOf('-||-')+4);
}

function checkUrl()
{
	var url = window.location.href;
	if(url.indexOf('#') > 0)
	{
		var urlArray = url.split('#/');
		getvestigingDetail(0, '#/'+urlArray[1]);
	}
	else if(url.indexOf('vestigingen.html') > 0)
		location.href = '/vestiging/';
}
