$(document).ready(function(){
	initAjax();
	initCanvas();
	var show_layover=getCookie('layover');
	if (show_layover!=null && show_layover!=""){
		//layover is already shown
	}else{ // layover cookie is not set or expired
		setIframeSrc("layover/layover.htm");
	}
});//window onload

window.onresize=function(){
	if(document.getElementById('layover')){positionPopup('layover');}
}

/* ********** Ajax ********** */

function initAjax(){
	var thebody=document.getElementsByTagName('body')[0];
	var theiframe = document.createElement('div');
	theiframe.id="the_layover_iframe";
	theiframe.style.display='none';
	theiframe.innerHTML='<iframe id="layover_iframe" width=0 height=0 src="copyright.htm" />';
	thebody.appendChild(theiframe);
}

function updateContentWithPopupAndFunction(content,title,endfunc){
	var thebody=document.getElementsByTagName('body')[0];
	if(!document.getElementById('temp')){
		var tempcont=document.createElement('div');
		tempcont.id="temp";
		var container=document.getElementById('container');
		thebody.insertBefore(tempcont,container);
	}
	document.getElementById('temp').innerHTML=content;
	initPopups();
	eval(endfunc);
}


function setIframeSrc(link){
	document.getElementById("layover_iframe").src = link;
}

function initLayover(){
	initMenu();
	$('#layover .item').mouseover(function(){$(this).addClass('high');});
	$('#layover .item').mouseout(function(){$(this).removeClass('high');});
	//$('#layover .item').click(function(){window.location=$(this).find('a').last().href;});
	$('continue').click(function(){closeonclick(this.parentNode);return false;});
	//$('#layover').click(function(){closeonclick(this);});
}

/* ********** General Remark ********** */
//zie ook: window resize

function positionPopup(id){
	var browserheight=$(window).height();
	var browserwidth=$(window).width();
	var element=document.getElementById(id);
	if(browserheight>464){element.style.top=parseInt((browserheight-464)/2)+"px";}else{element.style.top="0px";}
	if(browserwidth>824){element.style.left=parseInt((browserwidth-824)/2)+"px";}else{element.style.left="0px";}
}

function initPopups(){
	if(getElementsByClassName(document,"div","popup")[0]){
		var popups=getElementsByClassName(document,"div","popup");
		for(var i=0,il=popups.length;i<il;i++){
			addCloseButtonTo(popups[i]);
		}
	}
}

function addCloseButtonTo(element){
	var close=document.createElement("a");
	close.innerHTML="<span>top</span>";
	close.className='close';
	close.href="#top";
	close.title="sluiten";
	close.onclick=function(){
			closeonclick(this.parentNode);
			return false;
	};
	element.appendChild(close);
}

var infrontofCanvas="";//id

function initCanvas(){//ie bug
	var thebody=document.getElementsByTagName('body')[0];
	var thecanvas = document.createElement('div');
	thecanvas.id="canvas";
	thecanvas.style.display="none";
	thecanvas.title="klik om de popup te sluiten";
	thecanvas.onclick=function(){
		closeCanvasAnd(infrontofCanvas);
	}
	var container=document.getElementById('container');
	thebody.insertBefore(thecanvas,container);
}

function openCanvas(){
	showIt('canvas');
	return false;
}
function closeCanvas(){
	hideIt('canvas');
	return false;
}

function openCanvasAnd(id){	
	showIt('canvas');
	showIt(id);
	infrontofCanvas=id;
	return false;
}

function closeCanvasAnd(id){
	hideIt('canvas');
	hideIt(id);
	infrontofCanvas="";
	return false;
}

function hideIt(id){if(document.getElementById(id)){document.getElementById(id).style.display="none";}}
function showIt(id){if(document.getElementById(id)){document.getElementById(id).style.display="block";}}
function hideObj(obj){obj.style.display="none";}
function showObj(obj){obj.style.display="block";}

function closeonclick(obj){
	obj.style.display="none";
	if(infrontofCanvas!=""){
		closeCanvas();
		hideIt(infrontofCanvas);
		infrontofCanvas="";
	}
}

/* 
Simple JQuery Accordion menu.
-----------------------------------------
Copyright 2007-2010
Original script by: 
	web: http://www.i-marco.nl/weblog/
	email: marco@i-marco.nl
Adjustements by:
	web: http://www.yaki.be
	email: info@yaki.be
-----------------------------------------
Free for non-commercial use
-----------------------------------------
using jQuery: download at http://jquery.com
*/

function initMenu() {
	$('#vermatmenu ul').hide();
	$('#vermatmenu li.selected ul').show();
	$('#vermatmenu li.selected li:not(.selected) ul').hide();
	$('#vermatmenu').find('li ul').parent().addClass('hassubitems');
	$('#vermatmenu li a').click(
		function() {
			var checkElement = $(this).next();
			if((checkElement.is('ul')) && (checkElement.is(':visible'))){
			  	checkElement.slideUp('normal').parent().removeClass('selected');
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))){
				if($(this).parent().parent().parent().is('li')){
					var temp=$(this).parent().parent().parent();
					temp.find('li.selected ul:visible').slideUp('normal').parent().removeClass('selected');
				}else{
					$('#vermatmenu ul:visible').slideUp('normal').parent().removeClass('selected');
				}
				checkElement.slideDown('normal').parent().addClass('selected');
				return false;
			}
		}
	);
}


