checkSelectedMenuItem = function(cutOffPoint, obj)
{
	var oSelectedItem = $(obj);
	if (!oSelectedItem.is('.selected'))
	{
		var urlOriginal = $(obj).find('> a').attr('href');
		if (urlOriginal == "#")
		{
			var onClick = $(obj).find('> a').attr('onclick').toString();
			
			var regEx = /document\.location\s*\=\s*[\'\"](.*)[\'\"]/;
			if (regEx.test(onClick))
			{
				urlOriginal = regEx.exec(onClick)[1];			
			}
		}
		
		var urlFolder = urlOriginal;
		var lastIndex = urlFolder.lastIndexOf(cutOffPoint);
		
		if (lastIndex > -1)
		{
			urlFolder = urlFolder.substr(0, lastIndex + 1);
		}
		
		//alert(location.pathname);
		//alert(urlFolder);
		//alert(location.pathname.indexOf(urlFolder));
		if (location.pathname.indexOf(urlFolder) > -1 || urlOriginal == location.pathname)
		{
			if (urlFolder != '' && urlOriginal != '#' && urlFolder != '#')
			{
				$(obj).addClass('selected');
			}
		}
	}
}

checkSelectedMenuItemMain = function() {
	checkSelectedMenuItem('/', this);
}

checkSelectedMenuItemLeft = function() {
	checkSelectedMenuItem('.htm', this);
}

var TimeLine = new Object();
TimeLine.Scrolling = false;
TimeLine.Speed = 20;
TimeLine.Step = 3;
TimeLine.Top = 25;

TimeLine.Init = function() {
	$("#timeline_gradient_bottom").hover(
		function() {
			TimeLine.Scrolling = true;
			TimeLine.ScrollDown(TimeLine.Step);
		},
		function() {
			TimeLine.Stop();
		}
	)
	$("#timeline_gradient_top").hover(
		function() {
			TimeLine.Scrolling = true;
			TimeLine.ScrollUp(TimeLine.Step);
		},
		function() {
			TimeLine.Stop();
		}
	)
}

TimeLine.ScrollUp = function(step) {
	if (TimeLine.Scrolling)
	{
		var top = parseInt($('#timeline_scroll > ul').css('margin-top').replace('px', ''));
		if (top < TimeLine.Top)
		{
			top = top + step;
			if (top > TimeLine.Top) top = TimeLine.Top;
			$('#timeline_scroll > ul').css('margin-top', top + 'px');
			$('#timeline_top').css('margin-top', top + 'px');
			setTimeout('TimeLine.ScrollUp('+ (step + 0.2) +')',TimeLine.Speed);
		}
	}
}

TimeLine.ScrollDown = function(step) {
	if (TimeLine.Scrolling)
	{
		var top = parseInt($('#timeline_scroll > ul').css('margin-top').replace('px', ''));
		var height = $('#timeline_scroll > ul').height();
		if (top > (height * -1) + $('#timeline_scroll').height() - 10)
		{
			top = top - step;
			$('#timeline_scroll > ul').css('margin-top', top + 'px');
			$('#timeline_top').css('margin-top', top + 'px');
			setTimeout('TimeLine.ScrollDown('+ (step + 0.2) +')',TimeLine.Speed);
		}
	}
}

TimeLine.Stop = function() {
	TimeLine.Scrolling = false;
}

$(document).ready(function()
{
	// Hide open sollicitatie date
	$(".date").each(function() {
		var html = $(this).html();
		var year = html.substr(html.length - 4, 4);
		if (year == 2020)
		{
			$(this).hide();
		}
	});
	
	$("#left_nav > div > ul li").each(checkSelectedMenuItemLeft);
	$("#menu > div > ul > li").each(checkSelectedMenuItemMain);
	
	Cufon.replace('#menu a', { fontFamily: 'Clarendon' });
	Cufon.replace('h1', { fontFamily: 'Clarendon' });
	Cufon.replace('h2', { fontFamily: 'Clarendon' });
	Cufon.replace('h3', { fontFamily: 'Clarendon' });
	Cufon.replace('h4', { fontFamily: 'Clarendon' });
	Cufon.replace('#left_nav > div  ul  li  a', { fontFamily: 'Clarendon' });

	$("#timeline ul li:odd").addClass("even");
	$("#timeline ul li").click(function() {
		$("#timeline ul li .info_inner").attr("style", "");
		$("#timeline ul li").removeClass("active");
		$("#timeline ul li div.image img").css("margin-top", "0");
		$(this).addClass("active");
		$(this).find("div.image img").css("margin-top", "-120px");
	});
	
	$("#timeline ul li input.intermezzo").click(function() {
		$(this).parent().parent().find("div.info_inner").toggle();
		return false;
	});
	
	TimeLine.Init();
	
	$(".productItem h4 a").each(function() {
		var objImg = $(this).parent().parent().find(".beeldbankImage img");
		if ($(objImg).length > 0)
		{
			$(this).attr("href", $(objImg).attr("src")).addClass("lightbox");
		}
	});
	$("a.lightbox").lightBox({imageBtnClose : '/system/images/lightbox/lightbox-btn-close.gif', imageLoading: '/system/images/lightbox/lightbox-ico-loading.gif'});
});

// Check if age cookie is present
var valid = $.cookie('validAge');
if (valid != 'true')
{
	location.href = '/leeftijd.html';
}
