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.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 sfHover() {
	var sfEls = document.getElementById("bip_menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className +=" hover";
            var uls = this.getElementsByTagName("ul");
            if (uls.length) {
                var ul = uls.item(0);
                if (ul.offsetWidth < 150) {
                    ul.style.width = 150+"px";
                }
                ul = null;
            }
            uls = null;
		}
		sfEls[i].onmouseout=function() {
			this.className =this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
    sfEls = null;
}

function hideAndShow() {
    var list  = document.getElementById("hide-show");
    var links = list.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
        if (links.item(i).className == "show-hide-lnk") {
            links.item(i).onclick = function () {
                var pid = this.getAttribute("href").substr(this.getAttribute("href").indexOf("#") + 1);
                var pTable = document.getElementById(pid);
                var show = false;
                if (typeof(pTable) != "undefined" && pTable != null && pTable.hasChildNodes()) {
                    var text = this.childNodes.item(0).nodeValue;
                    if (text.indexOf("Pokaż") != -1) {
                        show = true;
                    }
                    var trs = pTable.getElementsByTagName("tr");
                    for (var k = 0; k < trs.length; k++) {
                        if (trs.item(k).className != "hdr-row") {
                            if (show) {
                                if (!document.all || window.opera) {
                                    trs.item(k).style.display = "table-row";
                                } else {
                                    trs.item(k).style.display = "block";
                                }
                            } else {
                                trs.item(k).style.display = "none";
                            }
                        }
                    }
                    if (show) {
                        var newText = document.createTextNode("Ukryj");
                    } else {
                        var newText = document.createTextNode("Pokaż");
                    }
                    this.replaceChild(newText, this.childNodes.item(0));
                }
                pTable = newText = trs = null;
            }
        }
    }
    list = links = null;
}

window.onload = function() {
	if (document.getElementById && document.createElement) {
		if (document.getElementById("images")) {
			popUpImg();
        }
        if (document.all && !window.opera) {
            sfHover();
        }
        if (document.getElementById("hide-show")) {
            hideAndShow();
        }
	}
}


