var mouseX = 0;
var mouseY = 0;

if(window.Event && document.captureEvents) {
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = getMousePos;

function getMousePos(e) {
	if (!e) var e = window.event || window.Event;
	if (e.pageX || e.pageY) {
		mouseX = e.pageX;
		mouseY = e.pageY;
	} else if ((e.clientX || e.clientY) && (document.body)) {
		mouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
	}
}

function showTip() {
	var e = document.getElementById('tipBox');
	if (e) {
		e.style.display = 'inline';	
	}
}

function hideTip() {
	var e = document.getElementById('tipBox');
	if (e) {
		e.style.display = 'none';	
	}
}

function updateTip() {
	var e = document.getElementById('tipBox');
	if (e) {
		e.style.marginLeft = (mouseX - 280) + 'px';
		e.style.marginTop  = (mouseY - 125) + 'px';
	}
}

function getWindowSize() {
	if (typeof(window.innerWidth) == 'number') {
	   	return Array(window.innerWidth, window.innerHeight);
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		return Array(document.documentElement.clientWidth, document.documentElement.clientHeight);
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		return Array(document.body.clientWidth, document.body.clientHeight);
	} else {
		return Array(0, 0);
	}	
}

function getWindowScroll() {
	if (typeof(window.pageYOffset) == 'number') {
		return Array(window.pageXOffset, window.pageYOffset);
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		return Array(document.body.scrollLeft, document.body.scrollTop);
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		return Array(document.documentElement.scrollLeft, document.documentElement.scrollTop);
	} else {
		return Array(0, 0);	
	}
}

function showFoto(id) {
	var e = document.getElementById('fotoPopup');
	if (e) {
		var imgLoad = document.createElement('img');
			imgLoad.onload = function () {
				while (e.firstChild) e.removeChild(e.firstChild);
				e.appendChild(imgLoad);
				showPopup();
				sizePopup();				
			}
			imgLoad.src = dirPath + '_loading.gif';	

		var imgFoto = new Image();
			imgFoto.onload = function () {
				while (e.firstChild) e.removeChild(e.firstChild);
				e.appendChild(imgFoto);
				sizePopup();
			}
			imgFoto.src = dirPath + 'foto/' + id + '.jpg';
	}
	
}

function sizePopup() {
	var e = document.getElementById('fotoPopup');
	if (e) {
		var siz = getWindowSize();
		var scr = getWindowScroll();
		e.style.left = ( (siz[0] / 2) - (e.clientWidth  / 2) + scr[0] ) + 'px';
		e.style.top  = ( (siz[1] / 2) - (e.clientHeight / 2) + scr[1] ) + 'px';
	}
}

function showPopup() {
	var e = document.getElementById('hideWindow');
	if (e) {
		var size = getWindowSize();
		var main = document.getElementById('mainContainer');			
		var sizeX = (main.offsetWidth  > size[0] ? main.offsetWidth  : size[0]);
		var sizeY = (main.offsetHeight > size[1] ? main.offsetHeight : size[1]);		
		e.style.width   = '100%';
		e.style.height  = sizeY + 'px';		
		e.style.display = 'block';
	}	
	var e = document.getElementById('fotoPopup');
	if (e) {
		e.style.display = 'block';
	}
}

function hidePopup() {
	var e = document.getElementById('hideWindow');
	if (e) {
		e.style.display = 'none';
	}	
	var e = document.getElementById('fotoPopup');
	if (e) {
		e.style.display = 'none';
	}
}
