// 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) {
	//alert('weee');
	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 < height + 50) {
		height = bd.getDimensions().height - 50;
	}
	if(bd.getDimensions().width < width + 30) {
		width = bd.getDimensions().width - 30;
	}
	
	var bg 	 		= $(document.createElement("div"));
	var busy 	 	= $(document.createElement("div"));
	bg.id 			= 
	bg.className 	= "fixed_overlay";
	busy.setStyle({ width:"100%", background:"url(assets/images/ajax_action.gif) center no-repeat",
					height:"100%" });
	
	bd.appendChild(bg);
	bg.appendChild(busy);
	
	var img = new Image();
	
	img.onload 	= img_loaded;
	img.onabort =
	img.onerror =
	busy.onclick =
	bg.onclick = close_window; //close window if something goes wrong
	img.alt 	= alt;
	img.src 	= "libraries/thumb.php?width="+width+"&height="+height+"&pic=../" + url;
	
}

function img_loaded() {
	$('fixed_overlay').remove();
	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:'#404040', position:"relative", zIndex:"99999",
				 color:'#ffffff' });
	
	$(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);
	
		
	// add shadow
	win_width = win.getDimensions().width;
	win_height = win.getDimensions().height;
	
	var s 	= $(document.createElement("div"));
	var se 	= $(document.createElement("div"));
	var e	= $(document.createElement("div"));
	var ne	= $(document.createElement("div"));
	var n	= $(document.createElement("div"));
	var nw	= $(document.createElement("div"));
	var w	= $(document.createElement("div"));
	var sw	= $(document.createElement("div"));
	
	s.setStyle	({ width:(win_width-29-21)+"px", top:"0px", left:"21px", height:"27px" });
	se.setStyle	({ top:"0px", right:"0px", height:"27px", width:"29px" });
	e.setStyle	({ height:(win_height-27-26)+"px", right:"0px", top:"27px", width:"29px" });
	ne.setStyle	({ right:"0px", bottom:"0px", height:"26px", width:"27px" });
	n.setStyle	({ width:(win_width-27-26)+"px", bottom:"0px", left:"26px", height:"26px" });
	nw.setStyle	({ bottom:"0px", left:"0px", height:"26px", width:"26px" });
	w.setStyle	({ height:(win_height-26-22)+"px", left:"0px", top:"22px", width:"21px" });
	sw.setStyle	({ left:"0px", top:"0px", height:"22px", width:"21px" });
	
	s.innerHTML 	= "&nbsp;";
	se.innerHTML 	= "&nbsp;";
	e.innerHTML 	= "&nbsp;";
	ne.innerHTML 	= "&nbsp;";
	n.innerHTML 	= "&nbsp;";
	nw.innerHTML 	= "&nbsp;";
	w.innerHTML 	= "&nbsp;";
	sw.innerHTML 	= "&nbsp;";
	
	s.addClassName('s');
	se.addClassName('se');
	e.addClassName('e');
	ne.addClassName('ne');
	n.addClassName('n');
	nw.addClassName('nw');
	w.addClassName('w');
	sw.addClassName('sw');
	
	win.appendChild(s);
	win.appendChild(e);
	win.appendChild(n);
	win.appendChild(w);
	win.appendChild(se);
	win.appendChild(ne);
	win.appendChild(nw);
	win.appendChild(sw);
	// end add shadow

	
	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"} );	
}
