iCurOpen=false;
n=false;

aMenuStyles=new Array();
aMenuStyles["1"]="about";
aMenuStyles["2"]="assortiment";
aMenuStyles["3"]="vacatures";
aMenuStyles["4"]="vacatures";

function initBrezan()
{
	startcatching();
}


function openMenu(sID)
{
	if(n) clearTimeout(n);
	closeOpen();
	oSubMenuDiv=document.getElementById('submenu_'+sID);
	oSubMenuDiv.style.display='block';
	iCurOpen=sID;
	oHeaderButton=document.getElementById('menu_opener_'+iCurOpen);
	oHeaderButton.className="button_"+aMenuStyles[iCurOpen]+"_over";
}

function closeOpen()
{
	if(n) clearTimeout(n);
	if(!iCurOpen) return;
	oSubMenuDiv=document.getElementById('submenu_'+iCurOpen);
	oSubMenuDiv.style.display='none';
	oHeaderButton=document.getElementById('menu_opener_'+iCurOpen);
	oHeaderButton.className="button_"+aMenuStyles[iCurOpen];
}

function delayCloseOpen()
{
	n=setTimeout('closeOpen();',1000);
}

function checkEmail()
{
	sEmail = document.getElementById("email").value;

	sRe=/^[a-z0-9]+([_\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\.[a-z]{2,}$/;
	bStatus=sRe.test(sEmail);

	if(bStatus == false) alert("U hebt een ongeldig e-mailadres ingevuld.");
	return bStatus;
}


// functions for lightbox alternative (non-menu, but hey...)

function showBigPhoto(sFilename)
{
	oDarkener = document.getElementById("darkener");

	iDocWidth = document.body.offsetWidth;
	iDocHeight = document.body.offsetHeight;

	iScreenHeight = document.documentElement.clientHeight;

	if(iScreenHeight > iDocHeight) iDocHeight = iScreenHeight;

	oDarkener.style.width = iDocWidth + 'px';
	oDarkener.style.height = iDocHeight + 'px';

	var oPopin = document.createElement("div");
	oPopin.id = 'popin';
	document.body.appendChild(oPopin);

	oPopin.style.left = ((iDocWidth - 320) / 2) + 'px';
	oPopin.style.top = (((iScreenHeight - 320) / 2) + getScrollPos()) + 'px';
	oPopin.style.backgroundImage = 'url(/shared/images/custom/loading.gif)';

	loadImage(sFilename);
}

function checkImageLoaded()
{
	oImg = document.getElementById('newmainimage');
	if(oImg.complete)
	{
		iImageWidth = oImg.width;
		iImageHeight = oImg.height;

		oPopin = document.getElementById("popin");
		iDocWidth = document.body.offsetWidth;
		iScreenHeight = document.documentElement.clientHeight;

		oPopin.style.left = ((iDocWidth - (iImageWidth + 20)) / 2) + 'px';
		oPopin.style.top = (((iScreenHeight - (iImageHeight + 20)) / 2) + getScrollPos()) + 'px';
		oPopin.style.width = (iImageWidth + 20) + 'px';
		oPopin.style.height = (iImageHeight + 20) + 'px';
		oImg.style.visibility = 'visible';
	}
	else
	{
		setTimeout('checkImageLoaded()', 50);
	}
}

function loadImage(sFilename)
{
	if(!sFilename) return false;

	oPopin = document.getElementById("popin");

	sHTML = '<img src="'+sFilename+'" alt="" id="newmainimage" style="visibility:hidden;" onclick="closePhoto();" />';
	sHTML += '<div class="kruizert" onclick="closePhoto();"></div>';

	oPopin.innerHTML = sHTML;

	setTimeout('checkImageLoaded()', 50);
}

function getScrollPos()
{
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
		    ScrollTop = window.pageYOffset;
		else
		    ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	return ScrollTop;
}

function closePhoto()
{
	oDarkener = document.getElementById("darkener");

	oDarkener.style.width = '0px';
	oDarkener.style.height = '0px';

	oPopin = document.getElementById("popin");
	if(oPopin) document.body.removeChild(oPopin);
}


function addEvent(hoo, wot, fun)
{
	if(document.addEventListener)
		hoo.addEventListener(wot, fun, null);
	else if(document.attachEvent)
		hoo.attachEvent('on' + wot, fun);
	else hoo['on' + wot] = fun;        
}

function catchEscape(e)
{
	e=(window.event)?window.event:e;
	if(e.keyCode == 27)
	{ 
		closePhoto();
	}

	return true;
}

function startcatching()
{
	addEvent(document, 'keyup', catchEscape);
}

function showProvence(xPos, yPos)
{
	oDiv = document.getElementById("beneluxdiv");
	oDiv.style.backgroundPosition = '-'+xPos+'px -'+yPos+'px';
}
