$(document).ready( function(){
	activateMenu();
	
	galleryThumbs();
})



function activateMenu()
{
	var fullUrl = window.location.toString();
	var fullUrlParts = fullUrl.split('/');
	var partsCount = fullUrlParts.length -1;
	var pageParts = fullUrlParts[partsCount].split('?');
	var page = pageParts[0];
	
	var hoofdmenu = $('#menu').children('li').children('a');
	var i=0;
	for(i=0; i<hoofdmenu.length; i++)
	{
	
		if( $(hoofdmenu[i]).attr('href') == page )
		{
			$(hoofdmenu[i]).parent().children('ul:first').show();
			$(hoofdmenu[i]).addClass('active');
			$(hoofdmenu[i]).parent().addClass('active');
			$(hoofdmenu[i]).parent().addClass('hoofdmenu');
			$(hoofdmenu[i]).parent().children('ul').addClass('submenu');
		}else{
			$(hoofdmenu[i]).hover(hideActiveMenu, showActiveMenu);
		
		
		//Ga ook submenu na
			var submenu = $(hoofdmenu[i]).parent().children('ul').children('li').children('a');
			var j=0;
			for(j=0; j<submenu.length; j++)
			{
				if( $(submenu[j]).attr('href') == page )
				{
					$(submenu[j]).parent().parent().show();
					$(hoofdmenu[i]).parent().addClass('active');
					$(hoofdmenu[i]).parent().addClass('subhoofdmenu');
					$(submenu[j]).addClass('active');
					$(submenu[j]).parent().addClass('active');
					
				}else{
					$(submenu[j]).hover(hideActiveMenu, showActiveMenu);
				}
			}	
		}
	}
	
	$('.subhoofdmenu').children('ul').children('li').children('a').unbind('mouseenter');
	$('.subhoofdmenu').children('ul').children('li').children('a').unbind('mouseleave');
}

function hideActiveMenu()
{
	
		$('.active:first').children('ul').hide();
}

function showActiveMenu()
{
	$('.active:first').children('ul').show();
}

function galleryThumbs()
{
	$('.galleryThumb').click(function()
	{
		openLightbox(this.href, this.alt, this);
		
		return false;
	});
}

function openLightbox(href, alt, clicked)
{
	var sourceOffset = $(clicked).offset();
	
	var img = new Image;
	img.src = href;
	img.alt = alt;
	
	img.onload = function()
	{
			var wHeight = $(window).height();
			var wWidth = $(window).width();
			
			var dHeight = $(document).height();
			var dWidth = $(document).width();
			
			$('#overlay').html('<img src="'+img.src+'" alt='+img.alt+' id=\'lightboxImg\'/>');
			
			$('#lightboxImg').css({top: sourceOffset.top, left: sourceOffset.left, width:'50px', height:'50px'});
			$('#overlay').css({width: dWidth+'px', height: dHeight+'px'});
			$('#overlay').fadeIn(500);
			
			var scrollTop = document.body.scrollTop;
			
			$('#lightboxImg').animate({top: (((wHeight/2)-(img.height/2)) + scrollTop)+'px', left: ((wWidth/2)-(img.width/2))+'px', width: img.width, height: img.height}, 500, false)
			$('#lightboxImg').click(hideLightbox);
			$('#overlay').click(hideLightbox);
	}
}



function hideLightbox()
{
	$('#overlay').fadeOut(500);
	$('#overlay').html('');
}
