function addLoadEvent(func)	{
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function showPic (whichpic) {
 if(document.getElementById) {
  document.getElementById("fullsize").src = whichpic.href;
  return false;
 } else {
  return true;
 }
}

function prepareGallery ()	{
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("imagegallery")) return false;
	var gallery = document.getElementById("imagegallery");
	var links = gallery.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		links[i].onclick = function() {
			return showPic(this);
		}
	}
}

function preparePopUp ()	{
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("popupgallery")) return false;
	var gallery = document.getElementById("popupgallery");
	var links = gallery.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		links[i].onclick = function() {
			return popUp(this);
		}
	}
}

var newWin = '';

function popUp (whichpic) {
	if(document.getElementById) {
		function doit() {
			newWin.document.getElementById('placeholder').src = whichpic.href;
			if (whichpic.title) {
				newWin.document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
			} else {
				newWin.document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
			}
		}
		if (!newWin.closed && newWin.location) {
			newWin.focus();
			doit();
		} else {
			newWin = window.open('popup.html','mywin', 'toolbar=no, scrollbars=yes, resizable=yes, menubar=no, status=no, width=500, height=500');
			newWin.focus();
			newWin.onload = function() {
				doit();
			}
		}
		return false;
	} else {
		return true;
	}
}


addLoadEvent(prepareGallery);
addLoadEvent(preparePopUp);

