// Functie voor Popups
// bron: http://jankoehoorn.nl/tuts/js/perfectpopups/

Array.prototype.contains = function (elem) {
	var i;
	for (i = 0; i < this.length; i++) {
		if (this[i] == elem) {
			return true;
		}
	}
	return false;
};

function popupInit () {
	var x = document.getElementsByTagName ('a');
	var xClasses;
	var n = x.length;
	
	for (i = 0; i < n; i++) {
		xClasses = x[i].className.split(" ");
		if (xClasses.contains ('popup')) {
			x[i].onclick = function () {
				return open_picture_win (this);
			}
		}
	}
}

var picture_window;

function open_picture_win (obj) {
	var title = "Klik op de foto om het venster te sluiten"
	var htmlString;
	var settings;
	var left;
	var top;

	var size = obj.getAttribute ('id').split ('_');
	var width, height;
	
	width = (size[1]) ? (size[1]) : (800);
	height = (size[2]) ? (size[2]) : (600);
	
	htmlString = '<html><head><title>' + title + '<\/title>';
	htmlString += "<style>* {border: 0; margin: 0; padding: 0;} body {background-color: black; overflow: hidden; }<\/style><\/head><body style=\"cursor: pointer\" leftmargin=\"0\" topmargin=\"0\" bgcolor=\"#555555\">";
	htmlString += "<img title=\"Klik om te sluiten\" onclick=\"window.close ()\" src=\"";
	htmlString += obj.href;
	htmlString += "\"><\/body><\/html>";
	left = (screen.availWidth - width) / 2;
	top = (screen.availHeight - height) / 2;
	settings = '"toolbar=no, scrollbars=no, left=' + left + ',top=' + top + ',width=' + width + ', height=' + height + '"';

	if (picture_window && !picture_window.closed) {
		picture_window.close ();
	}

	picture_window = window.open ('', '', settings);
	picture_window.document.write (htmlString);
	picture_window.focus ();
	picture_window.document.close ();
	
	return false;
}
