addLoadListener(initRealLightBox);
addLoadListener(initLightBoxOpeners);

var lightboxcode = "";
var contentWidth = 0;
var contentHeight = 0;

/*********************************************************************/

function initRealLightBox()
{
	var fader = document.createElement('div');
	fader.setAttribute("id","siteFader");
	var stijl=fader.style;
	stijl.position="absolute"; stijl.display="none"; stijl.left="0px";stijl.top="0px";stijl.filter = "alpha(opacity=40)"; stijl.opacity = "0.4"; stijl.MozOpacity = "0.4"; stijl.KhtmlOpacity = "0.4";
	stijl.backgroundColor="#000";
	stijl.width=document.body.parentNode.scrollWidth+"px";
	stijl.height=document.body.parentNode.scrollHeight+"px";
	stijl.zIndex="100";
	document.body.appendChild(fader);

	var lightbox = document.createElement('div');
	lightbox.setAttribute("id","lightbox");
	lightbox.innerHTML = lightboxcode;
	stijl=lightbox.style;
	stijl.position="absolute"; stijl.display="none"; stijl.left="0px";stijl.top="0px";
	stijl.zIndex="101";
	document.body.appendChild(lightbox);
	
	var lightboxclose = document.createElement('div');
	lightboxclose.setAttribute("id","lightboxclose");
	lightboxclose.innerHTML = '<a onclick="sluitLightBox();return false" href="" style="text-decoration:none;color:#fff;">[x] close</a>';
	stijl=lightboxclose.style;
	stijl.position="absolute"; stijl.display="none"; stijl.left="0px";stijl.top="0px";stijl.cursor="pointer";stijl.fontSize="120%";stijl.color="#fff";
	stijl.zIndex="102";
	document.body.appendChild(lightboxclose);
	
	centerLightBox();
}

function initLightBoxOpeners()
{
	var list = getElementsByAttribute("class","instruction_button",document);	
	for(var i = 0; i < list.length; i++ )
	{
		attachEventListener(list[i], "click", openLightBox, false);
	}
	//attachEventListener($('siteFader'), "click", sluitLightBox, false);
	//attachEventListener($('lightboxclose'), "click", sluitLightBox, false);
}




/********************************************************************/



function centerLightBox()
{
	var box = $('lightbox');
	box.style.left="0px";
	box.style.top="0px";
	var dim = getWidth(box);
	var view = getViewPortSize();
	var scrollPos = getScrollingPosition();
	box.style.left=(document.body.parentNode.scrollWidth - contentWidth)/2 + "px";
	box.style.top=scrollPos[1]+(view[1] - contentHeight)/2 + "px";
	$('lightboxclose').style.left=((document.body.parentNode.scrollWidth - contentWidth)/2)+600+"px";
	$('lightboxclose').style.top=(scrollPos[1]+(view[1] - contentHeight)/2) - 30 + "px";
}

function openLightBox(ev)
{	
	var target = getEventTarget(ev);
	var clicked = target;
	var parent = clicked;	
	while((clicked.tagName!="a")&&(clicked.tagName!="A")) clicked=clicked.parentNode;
	while((parent.tagName!="li")&&(parent.tagName!="LI")) parent=parent.parentNode;	
	var loper=parent;
	var teller=0;
	while(loper) 
	{
		loper=loper.previousSibling;
		if(loper){ if((loper.tagName!="li")&&(loper.tagName!="LI")) loper=loper.previousSibling; }
		teller=teller+1;
	}

	var box = $('lightbox');
	box.style.left="0px";
	box.style.top="0px";
	
	var so = new SWFObject(flashINFO[teller]['flashMovie'],flashINFO[teller]['flashMovieName'],flashINFO[teller]['width'],flashINFO[teller]['height'],"7","#ffffff",true);
	if(flashINFO[teller]['addVariable']) { eval(flashINFO[teller]['addVariable']); }
	so.write("lightbox");
	contentWidth=flashINFO[teller]['width'];
	contentHeight=flashINFO[teller]['height'];

	box.style.left="0px";
	box.style.top="0px";

	centerLightBox();

	$('siteFader').style.display="block";
	$('lightbox').style.display="block";
	$('lightboxclose').style.display="block";
}



function sluitLightBox()
{
	$('lightbox').style.display="none";
	$('siteFader').style.display="none";
	$('lightboxclose').style.display="none";
}



/********************************************************************/
