function popUpImg() {
	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.style.padding = "0";
	popup.style.margin  = "0";
	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";
		/* 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';}

		popUp.style.width   = "auto";
		popUp.style.height  = "auto";
		popUp.style.padding = "5px";
		var popUpHeight  = document.getElementById('popup').offsetHeight;
		var screenHeight = getScreenHeight();
		var scrolled     = getScroll();
		var top = ((screenHeight - popUpHeight)/2) + scrolled;
		//alert("wysokosc popupa:" + popUpHeight + " wysokosc ekranu" + screenHeight + " ile przewiniete:" + scrolled + " poz:" + top);
	    if (top < 335)
			top = 335;
		popUp.style.top = top+"px";
		var ScreenWidth = getScreenWidth();
		var popUpWidth  = document.getElementById('popup').offsetWidth;
		var left = (ScreenWidth-popUpWidth)/2;
		popUp.style.left    = left+"px";
		var close = document.getElementById('closeZoom');
		close.style.display = "block";
		close.style.margin  = "0";
		close.style.padding = "0";
		close.style.color   = "#fff";
		popUp.style.cursor  = "pointer";
		return false;
	}
	else
		return true;
}

function Hide(popup) {
	document.getElementById('ImgZoom').src = 'images/blank.gif';
	popup.style.visibility = 'hidden';
}

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 popUpAnim() {
    if (document.getElementById("popUpAnim")) {
        var popup = document.getElementById("popUpAnim");
    } else {
        var popup = document.createElement("div");
        popup.setAttribute("id", "popUpAnim");
        popup.style.display == "none";
        var flash = document.createElement("div");
        flash.setAttribute("id","flashAnim");
        var parag = document.createElement("p");
        parag.setAttribute("id", "closeAnim");                
        parag.style.cursor  = "pointer";
        var close = document.createTextNode("Zamknij");
        parag.appendChild(close);
        popup.style.padding = "0";
        popup.style.margin  = "0";
        popup.appendChild(parag);
        popup.appendChild(flash);
        flash = parag = close = null;
        var content = document.getElementsByTagName("body").item(0);
        content.appendChild(popup);
    }
    if (popup.style.display != "block") {
        //pokaz
        var fo = new FlashObject("images/intro.swf", "flashAnim", "500", "300", "8", "#fff", "true");
        fo.addParam("wmode", "opaque");
        fo.addParam("menu", "false");
        fo.write("flashAnim");
        fo = null;
        popup.style.position = "absolute";
        popup.style.width    = "auto";
		popup.style.height   = "auto";
		popup.style.padding  = "5px";
		var popUpHeight      = 300;
		var screenHeight     = getScreenHeight();
		var scrolled         = getScroll();
		var top = ((screenHeight - popUpHeight)/2) + scrolled;
	    if (top < 335)
			top = 335;
		popup.style.top = top+"px";
		var ScreenWidth = getScreenWidth();
		var popUpWidth  = 500;
		var left = (ScreenWidth-popUpWidth)/2;
		popup.style.left    = left+"px";
        popup.style.display = "block";
    } else {
        //schowaj
        var flash           = document.getElementById("flashAnim");
        flash.innerHTML     = "";
        flash               = null;
        popup.style.display = "none";
    }
	popup.onclick = function() {
		popUpAnim();
	}
	popup = null;
	return false;
}

window.onload = function() {
	if (document.getElementById && document.createElement) {
		if (document.getElementById("images")) {
			popUpImg();
		}
		if (document.getElementById("animStart")) {
            var animStart = document.getElementById("animStart");
            animStart.onclick = function () {
                return popUpAnim();
            }
            animStart = null;           
		}
	}
}