// JavaScript Document
var popUpImageList = Array();
var browserWindowHeight = 0;
var browserWindowWidth = 0;

function showImagePopUp(e) {
	if (!e)
		e = window.event;
		
	var elem = (e.target) ? e.target : e.srcElement;
	
	_calculateBrowserSize();
	/*var x, y;

	if (typeof(e.pageX) == 'number') {
		x = e.pageX + 16;
		y = e.pageY + 16;
	}
	else {
		if (typeof(e.clientX) == 'number') {
			x = (e.clientX + document.documentElement.scrollLeft) + 16;
			y = (e.clientY + document.documentElement.scrollTop) + 16;
		}
		else {
			x = 0;
			y = 0;
		}
	}*/
	
	if(document.getElementById('popUpImg')) {
		var popup = document.getElementById('popUpImg');
		popup.style.top = '385px';
		if (browserWindowWidth > 800) 
			popup.style.left = ((browserWindowWidth / 2) - 400) + 233 + 'px';
		else
			popup.style.left = '233px';
			
		while (popup.firstChild)
			popup.removeChild(popup.firstChild);
		
		var pid = Number(elem.parentNode.id.substr(7));
		
		if (!isNaN(pid)) {
			if (pid > -1 && pid < popUpImageList.length) {
				var img = document.createElement('img');
				img.setAttribute('src', popUpImageList[pid]);
				img.setAttribute('width', '250');
				img.setAttribute('height', '250');
				popup.appendChild(img);
			}
		}
		
		popup.style.display = 'block';
	}
}

function hideImagePopUp(e) {
	document.getElementById('popUpImg').style.display = 'none';
}


function _calculateBrowserSize() {
	// calculate window width - height
	if (navigator.userAgent.indexOf('MSIE') != -1) {
		if (document.documentElement.clientWidth == 0)
			browserWindowWidth = document.body.clientWidth;
		else	
			browserWindowWidth = document.documentElement.clientWidth;
			
		if (document.documentElement.clientHeight == 0)
  			browserWindowHeight = document.body.clientHeight;
		else
			browserWindowHeight = document.documentElement.clientHeight;
	}
	else {
		browserWindowWidth = window.innerWidth;
  		browserWindowHeight = window.innerHeight;
	}
	
	// calculate document width height
	var x,y;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) { // all but Explorer Mac
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	}
	else {// Explorer Mac;
		 //would also work in Explorer 6 Strict, Mozilla and Safari
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}
	
	// set the max of both
	browserWindowWidth = Math.max(browserWindowWidth, x);
	browserWindowHeight = Math.max(browserWindowHeight, y);
}
