/*	var popup = document.createElement('div');
	popup.setAttribute('id','popup');
	var zoom = document.createElement('img');
	zoom.setAttribute('id','ImgZoom');
	zoom.style.display = "none";
	var parag = document.createElement('p');
	parag.setAttribute('id','closeZoom');
	parag.style.display = "none";
	var close = document.createTextNode('Zamknij');
	parag.appendChild(close);
	popup.appendChild(parag);
	popup.appendChild(zoom);
	popup.style.visibility = 'hidden';
	popup.onclick = function() {
		return Hide(this);

	}
	var content = document.getElementsByTagName("body").item(0);
	content.appendChild(popup);
	var lnks = content.getElementsByTagName('a');
	for (i=0;i<lnks.length;i++) {
		var lnkclass = lnks[i].className;
		if (lnkclass == "zoom") {
			lnks[i].onclick = function() {
				return Show(this);
			}
		}
	}
}
*/
function Show(img) {
	if (document.getElementById && document.createElement) {
		var url = img.getAttribute('href');
		var zoom = document.getElementById('ImgZoom');
		zoom.setAttribute('src', url);
		zoom.style.display = "block";
		var popUp = document.getElementById('popup');
		popUp.style.visibility = 'visible';
		popUp.style.position   = 'absolute';	
		popUp.style.padding    = '5px';
		/* parse image href for dimensions
		based on http://www.themaninblue.com/writing/perspective/2004/08/05/ */		
		var paramString = url.replace(/.*\?(.*)/, "$1");
 		var paramTokens = paramString.split("&");
 		var paramList = new Array();

 		for (i = 0; i < paramTokens.length; i++) {
			var paramName = paramTokens[i].replace(/(.*)=.*/, "$1");
			var paramValue = paramTokens[i].replace(/.*=(.*)/, "$1");
			paramList[paramName] = paramValue;
		}
 		imgWidth  = paramList["x"];
 		imgHeight = paramList["y"];
		
		if (imgWidth)  {zoom.style.width  = imgWidth  + 'px';}
 		if (imgHeight) {zoom.style.height = imgHeight + 'px';}
		popUpPosition(popUp);
		window.onscroll = function() {
			popUpPosition(popUp);
		}
		window.onresize = function() {
			popUpPosition(popUp);
		}
		var close = document.getElementById('closeZoom');
		close.style.display = "block";
		return false;
	}
	else
		return true;
}

function Hide(popup) {
	if (document.getElementById('ImgZoom'))
		document.getElementById('ImgZoom').src = 'images/blank.gif';
	popup.style.visibility = 'hidden';
	popup.style.padding    = '0';
}

function getScreenHeight() {
	var y;
	if (self.innerHeight) {
		// wszystko poza IE
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		// IE 6 Strict
		y = document.documentElement.clientHeight;
	}
	else if (document.body) {
		// inne IE
		y = document.body.clientHeight;
	}
	return y;
}

function getScreenWidth() {
	var x;
	if (self.innerWidth) {
		// wszystko poza IE
		x = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		// IE 6 Strict
		x = document.documentElement.clientWidth;
	}
	else if (document.body) {
		// inne IE
		x = document.body.clientWidth;
	}
	return x;
}

function getScroll() {
	var y;
	if (self.pageYOffset) {
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) {
		y = document.documentElement.scrollTop;
	}
	else if (document.body) {
		y = document.body.scrollTop;
	}
	return y;
}

function popUpPosition(popUp) {
	var popUpHeight  = popUp.offsetHeight;
	var screenHeight = getScreenHeight();
	var scrolled     = getScroll();
	var top = ((screenHeight - popUpHeight)/2) + scrolled;
	popUp.style.top  = top+"px";
	var ScreenWidth  = getScreenWidth();
	var popUpWidth   = popUp.offsetWidth;
	var left = (ScreenWidth-popUpWidth)/2;
	popUp.style.left = left+"px";
}

function singlePopUp() {
    var popup = document.getElementById("popUp");
    popup.onclick = function() {
		return Hide(this);
	}
    popup.style.display    = "block";
    popup.style.visibility = 'visible';
	popup.style.position   = 'absolute';	
	popup.style.padding    = '5px';
 	popup.style.width  = '400px';
 	popup.style.height = '320px';
    document.getElementById("closeZoom").style.cursor = "pointer";
    popUpPosition(popup);
    window.onscroll = function() {
        var popup = document.getElementById("popUp");
        if (popup.style.display == "block") {
            popUpPosition(popup);
        }
    }
    window.onresize = function() {
        var popup = document.getElementById("popUp");
        if (popup.style.display == "block") {
            popUpPosition(popup);
        }
    }
}

window.onload = function() {
	if (document.getElementById && document.createElement) {
		if (document.getElementById("images"))
			popUpImg();
        if (document.getElementById("popUp")) {
            singlePopUp();
        }
	}
}

