// JavaScript Document
function loadImages() {
	var imgs = $A(document.getElementsByTagName("img")).findAll( function (i) { 
		return i.src.toString().match(/userfiles[^&]+/i); 
	});
	imgs.each(function (i) {
		$(i).setStyle({ cursor:"pointer" });
		i.onclick = function() {
			overLay(this.src.toString().match(/userfiles[^&]+/i), this.alt);
		};
	});
}

function overLay(url, alt) {
	var bd = $(document.body);
	if (window.external && (typeof window.XMLHttpRequest == "undefined")) { //target IE 6
		bd.setStyle( {overflow:"hidden", position:'relative'} );
	}
	var width = 700;
	var height = 700;
	if(bd.getDimensions().height < 750) {
		height = bd.getDimensions().height - 50;
	}
	if(bd.getDimensions().width < 730) {
		width = bd.getDimensions().width - 30;
	}
	
	var img = new Image();
	img.onload = img_loaded;
	img.alt = alt;
	img.src = "libraries/thumb.php?width="+width+"&height="+height+"&pic=../" + url;
}

function img_loaded() {
	var bd = $(document.body);
	
	var bg 	 = $(document.createElement("div"));
	var cont = $(document.createElement("div"));
	var win  = $(document.createElement("div"));
	var a  	 = $(document.createElement("a"));
	bg.id 			= 
	bg.className 	= "fixed_overlay";
	cont.id			=
	cont.className	= "window_container";
	win.id			=
	win.className 	= "window";
	
	a.innerHTML = "&nbsp;Venster sluiten&nbsp;";
	a.setStyle({ display:"block", textAlign:"right", height:"20px", overflow:"hidden", lineHeight:"20px",
			   	 cursor:'pointer', width:"100%", background:'#ffffff', position:"relative", color:"#000000" });
	
	$(win).setStyle({ width:this.width+"px", height:(this.height+20)+"px" });
	
	bd.appendChild(bg);
	
	bg.appendChild(cont);
	//cont.hide();
	cont.appendChild(win);
	win.appendChild(this);
	win.appendChild(a);
	
	window.onresize = onResize;
	window.onresize();
	
	
	
	bg.onclick 	=
	cont.onclick=
	win.onclick =
	a.onclick	= close_window;
	
	//cont.show();
}

function close_window() {
	var fo = $('fixed_overlay');
	fo.remove(); 
	fo = null;
	var bd = $(document.body);
	bd.setStyle( {overflow:"visible", position:'relative'} );
	window.onresize = null;
}

function onResize() {
	var bd 	= $(document.body);
	var win = $('window');
	var cont= $('window_container');
	var top_offset = (bd.getHeight() - win.getHeight()) / 2;
	cont.setStyle( {top:top_offset+"px"} );	
}

	
/*
var s 	= new Image();
var se 	= new Image();
var e	= new Image();
var ne	= new Image();
var n	= new Image();
var nw	= new Image();
var w	= new Image();
var sw	= new Image();
s.src 	= "assets/images/pic_top.png";
se.src	 	
e.src	
ne.src	
n.src	
nw.src	
w.src	
sw.src	
*/
