﻿function imageWindow(path,title) {
	var wnd = window.open(path,title,'width=512,height=384,menubar=no,toolbar=no,location=no,scrollbars=no,status=no,resizable=no');
	wnd.focus();
}

var centerWindow = function(window) {
	if (!window.opera ) {
		var scW = screen.availWidth ? screen.availWidth : screen.width;
		var scH = screen.availHeight ? screen.availHeight : screen.height;
		window.moveTo(Math.round((scW-oW)/2), Math.round((scH-oH)/2));
	}
}

var frameWindow = function(title, content, onLoad) {
	var wnd = window.open("", title != null && title != "" ? title.replace(" ", "_") : "Okno", "width=512,height=384,resizable=1,toolbar=no,menubar=no");
	if (!wnd) { return null; }
	var src = "<html>" +
		/* head */
		"<head>" +
		"<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\"/>" +
		"<title>" + (title != null && title != "" ? title : "Zdjęcie") + "</title>" +
		"<link rel=\"shortcut icon\" href=\"bin/images/favicon.ico\" /><link rel=\"icon\" href=\"bin/images/favicon.ico\" /><link rel=\"icon\" type=\"image/png\" href=\"bin/images/favicon.png\" />" +
		"<link rel=\"stylesheet\" type=\"text/css\" href=\"bin/css/reset.css\" media=\"screen\" charset=\"utf-8\"><link rel=\"stylesheet\" type=\"text/css\" href=\"bin/css/layout.css\" media=\"screen\" charset=\"utf-8\">" +
		"<sc" + "ript src=\"bin/js/scripts.js\" type=\"text/javascript\"></sc" + "ript>" +
		"</head>" +
		/* body */
		"<body id=\"frame1\"" + (onLoad != null && onLoad != "" ? " onload=\"" + onLoad + "\"" : "") + ">" +
		"<div id=\"frame2\"><table id=\"frame3\">" +
		"<tr><td id=\"frame-nw\">&#xa0;</td><td id=\"frame-n\">&#xa0;</td><td id=\"frame-ne\">&#xa0;</td></tr>" +
		"<tr><td id=\"frame-w\">&#xa0;</td><td id=\"frame-c\">" +
		content +
		"</td><td id=\"frame-e\">&#xa0;</td></tr>" +
		"<tr><td id=\"frame-sw\">&#xa0;</td><td id=\"frame-s\">&#xa0;</td><td id=\"frame-se\">&#xa0;</td></tr>" +
		"</table></div>" +
		"</body>" +
		"</html>";
	wnd.document.open();
	wnd.document.write(src);
	wnd.document.close();
	wnd.focus();
	return wnd;
}

var panoramicImageWindow = function(title, previewImage, panoramicImage, description) {
	var tmp = description != null && description != "";
	var content = "<div><p>" + (tmp ? description : title) + "</p></div><div><applet code=\"ptviewer.class\" height=\"214\" width=\"318\" archive=\"bin/images/panoramic/ptviewer.jar\">" +
		"<param name=\"bgcolor\" value=\"d5d8e1\"><param name=\"wait\" value=\"" + previewImage + "\"><param name=\"file\" value=\"" + panoramicImage + "\"><param name=\"fov\" value=\"88\"><param name=\"tilt\" value=\"0\"><param name=\"quality\" value=\"2\"><param name=\"pan\" value=\"-18\"><param name=\"auto\" value=\"0.25\"><param name=\"tiltmin\" value=\"-90\"><param name=\"tiltmax\" value=\"90\"><param name=\"fovmin\" value=\"60\"><param name=\"fovmax\" value=\"100\">" +
		"</applet></div>";
	var onLoad = "resizeWinTo('frame2');";
	frameWindow(title, content, onLoad);
}

var imageWindow = function(title, path, description) {
	var tmp = description != null && description != "";
	var content = "<div>" + (tmp ? "<p>" + description + "</p>" : "") + "</div><div><a href=\"javascript:window.close()\" title=\"Zamknij okno\"><img src=\"" + path + "\"" + " alt=\"" + (tmp ? description : "") + "\" /></a></div>";
	var onLoad = "resizeWinTo('frame2');";
	frameWindow(title, content, onLoad);
}

var fitPic = function() {
        if (window.innerWidth) {
                iWidth = window.innerWidth;
                iHeight = window.innerHeight;
        } else {
                iWidth = (document.compatMode=="CSS1Compat") ? document.documentElement.clientWidth : document.body.clientWidth;
                iHeight = (document.compatMode=="CSS1Compat") ? document.documentElement.clientHeight : document.body.clientHeight;
        }
        iWidth = document.images[0].width - iWidth + 96;
        iHeight = document.images[0].height - iHeight + 96;
        window.resizeBy(iWidth, iHeight);
        self.focus();
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// WINDOW RESIZER
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function getRefToDivMod(divID, oDoc) {
	if (!oDoc) { oDoc = document; }
	if (document.layers) {
		if (oDoc.layers[divID]) {
			return oDoc.layers[divID];
		} else {
			for (var x = 0, y; !y && x < oDoc.layers.length; x++) {
				y = getRefToDivNest(divID, oDoc.layers[x].document);
			}
			return y;
		}
	}
	if (document.getElementById) {
		return oDoc.getElementById(divID);
	}
	if (document.all) {
		return oDoc.all[divID];
	}
	return oDoc[divID];
}

function resizeWinTo(idOfDiv) {
	var oH = getRefToDivMod(idOfDiv);
	if (!oH) { return false; }
	var x = window;
	x.resizeTo(screen.availWidth, screen.availWidth);
	var oW = oH.clip ? oH.clip.width : oH.offsetWidth;
	var oH = oH.clip ? oH.clip.height : oH.offsetHeight;
	if (!oH) { return false; }
	x.resizeTo(oW + 200, oH + 200);
	var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
	if (x.innerWidth) {
		myW = x.innerWidth;
		myH = x.innerHeight;
	} else if (d && d.clientWidth) {
		myW = d.clientWidth;
		myH = d.clientHeight;
	} else if (b && b.clientWidth) {
		myW = b.clientWidth;
		myH = b.clientHeight;
	}
	if (window.opera && !document.childNodes) { myW += 16; }
	var oH2 = getRefToDivMod(idOfDiv);
	var oW2 = oH2.clip ? oH2.clip.width : oH2.offsetWidth;
	var oH2 = oH2.clip ? oH2.clip.height : oH2.offsetHeight;
	x.resizeTo(oW2 + (oW + 200 - myW), oH2 + (oH + 200 - myH));
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// IMAGE SWAPPER
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) { 
//Do not delete these comments. 
//Non-Obtrusive Image Swap Script V1.1 by Hesido.com 
//Attribution required on all accounts 
    if (typeof(elem) == 'string') elem = document.getElementById(elem); 
    if (elem == null) return; 
    var regg = /(.*)(_nm\.)([^\.]{3,4})$/ 
    var prel = new Array(), img, imgList, imgsrc, mtchd; 
    imgList = elem.getElementsByTagName('img'); 
    for (var i=0; img = imgList[i]; i++) { 
        if (!img.rolloverSet && img.src.match(regg)) { 
            mtchd = img.src.match(regg); 
            img.hoverSRC = mtchd[1]+'_hv.'+ mtchd[3]; 
            img.outSRC = img.src; 
            if (typeof(mouseOver) != 'undefined') { 
                img.hoverSRC = (mouseOver) ? mtchd[1]+'_hv.'+ mtchd[3] : false; 
                img.outSRC = (mouseOut) ? mtchd[1]+'_ou.'+ mtchd[3] : (mouseOver && mouseOutRestore) ? img.src : false; 
                img.mdownSRC = (mouseDown) ? mtchd[1]+'_md.' + mtchd[3] : false; 
                img.mupSRC = (mouseUp) ? mtchd[1]+'_mu.' + mtchd[3] : (mouseOver && mouseDown && mouseUpRestore) ? img.hoverSRC : (mouseDown && mouseUpRestore) ? img.src : false; 
                } 
            if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;} 
            if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;} 
            if (img.mdownSRC) {preLoadImg(img.mdownSRC); img.onmousedown = imgMouseDownSwap;} 
            if (img.mupSRC) {preLoadImg(img.mupSRC); img.onmouseup = imgMouseUpSwap;} 
            img.rolloverSet = true; 
        } 
    } 
    function preLoadImg(imgSrc) { 
        prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc; 
    } 
} 
function imgHoverSwap() {this.src = this.hoverSRC;} 
function imgOutSwap() {this.src = this.outSRC;} 
function imgMouseDownSwap() {this.src = this.mdownSRC;} 
function imgMouseUpSwap() {this.src = this.mupSRC;}