iPop.DegradeTarget = "_self";

iPop.ClickImageToClose = true;

iPop.CloseOpenWindows = true;

iPop.Version = 2.50;
iPop.imgWin = null;
function iPop(img, imgTitle) {
	function degrade() {
		switch(iPop.DegradeTarget) {
			case "_blank" : open(img); break;
			case "_self" : location = img; break;
			case "_top" : top.location = img; break;
			case "_parent" : parent.location = img; break;
			default : open(img, iPop.DegradeTarget);
		}
		return false;
	}
	
	if(!document.images || !document.getElementById) return degrade();
	
	if(iPop.CloseOpenWindows && iPop.imgWin) {
		if(iPop.imgWin.close) iPop.imgWin.close();
		iPop.imgWin = null;
	}
	
	var width = 500, height = 600;
	var left = (screen.availWidth - width)/2, top = (screen.availHeight - height)/ 2;
	var imgWin = window.open("about:blank", "", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);

	if(!imgWin) return degrade();
	
	imgTitle = imgTitle || "Slika (" + img + ")";
	
	
	
	
	
	var html = '<!--\niPop Script (http://mvm.si/)';
	html += '\niPop.Version = ' + iPop.Version + '\n-->';
	html += '\n<html><head><title>Nalagam</title>';
	html += '\n<script type="text/javascript">\nvar _e = null;';
	html += '\nvar ip = window.opener.iPop;';
	html += '\nvar _pageLoaded = false;';
	html += '\nvar _title = "' + imgTitle + '"';
	html += '\nonload = function(e) { _pageLoaded = true; }';
	html += '\nfunction imgLoad(e) { ip.ImageLoaded(e, window); }';
	html += '\nfunction imgError(e) { ip.ImageError(e, window); }';
	html += '\nimgShow = ip.ImageShow;';
	html += '\nimgManualPopup = ip.ImageLoadedManualPopup;';
	html += '\n</script>';
	html += '\n<style type="text/css">';
	html += '\nhtml, body { font : 12px Arial; margin : 0; } h1 { font-size : 1.5em; }';
	html += '\n h2 { font-size : 1.2em; } a { color : blue; } img { border-color : black; }';
	html += '\n .message { position : absolute; left : 0px; top : 0px; width : 150px; height : 100px; background : white; text-align : center; }';
	html += '\n .message .main-message { font-weight : bold; display : block; }';
	html += '\n .message .secondary-message { color : #999; font-size : 11px; }';
	html += '\n .main-message.loading { margin-top : 35px; } .main-message.loaded { margin-top : 33px; } .main-message.error { margin-top : 25px; }';
	html += '\n #loading { z-index : 50; } #resize { z-index : 30; } #error { z-index : 40; }';
	html += '\n #image { position : absolute; left : 0px; top : 0px; width : 100%; height : 100%; z-index : 20; padding : 10px; background : white; }';
	html += '\n</style>';
	html += '\n</head>\n<body>';

	
	
	html += '\n<div id="loading" class="message"><span class="main-message loading">Nalagam sliko.</span> <span class="secondary-message">Prosimo pocakajte...</span></div>';
	html += '\n<div id="error" class="message"><span class="main-message error">Ne najdem slike.</span> <span class="secondary-message">Prišlo je do napake.<br><a href="javascript:window.close()">Zapri</a></span></div>';
	html += '\n<div id="resize" class="message"><span class="main-message error">Slika naložena..</span> <span class="secondary-message">Vaš brskalnik ne omogoca spreminjanja velikosti okna.<br><a href="javascript:imgManualPopup(_e, window)">Poglej sliko.</a></span></div>';
	html += '\n<div id="image">';
	if(iPop.ClickImageToClose) html += '\n<a href="javascript:window.close()" title="Zapri okno">';
	

	
	html += '\n<img src="' + img + '" onload="imgLoad(this)" onerror="imgError(this)"><div id="1" style="position:absolute;left:1px;top:1px;width:500px;height:500px;z-index:1;"><img src="images/spacer.gif" alt="Slike so avtorsko zašcitene." width="800" height="800" /></div>';
	
	if(iPop.ClickImageToClose) html += '</a>';
	html += '\n</div>';
	html += '\n</body></html>';




var message="Nelegalno kopiranje slik je prepovedano!";


function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")


	
	
	
	imgWin.document.open();
	imgWin.document.write(html);
	imgWin.document.close();
	
	iPop.imgWin = imgWin;
	
	return false;
}

iPop.ImageLoaded = function(e, win) {
	if(!e || !win) return;
	e.onload = null;
	e.onerror = null;
	if( win._pageLoaded ) {
		function show() {
			win.imgShow(e, win);
		}
		win.setTimeout(show, 100);
	} else {
		function noShow() {
			win.imgLoad(e, win);
		}
		win.setTimeout(noShow, 100);
	}
}

iPop.ImageShow = function(e, win) {
	if(!e || !win) return;
	e.onload = null; e.onerror = null;
	
	var doc = win.document;
	var width = e.width + 30, height = e.height + 55;
	var tooLarge = false;
	
	if(width > screen.availWidth) {
		width = screen.availWidth - 20;
		tooLarge = true;
	}
	if(height > screen.availHeight) {
		height = screen.availHeight - 20;
		tooLarge = true;
	}
	if(tooLarge) {
		doc.getElementById("image").style.overflow = "auto";
	}
	
	var tooSmall = false;
	if( e.width < doc.body.clientWidth && e.height < doc.body.clientHeight ) {
		tooSmall = true;
	}
	
	var left = (screen.availWidth - width)/2, top = (screen.availHeight - height)/ 2;
	win.resizeTo(width, height);
	win.moveTo(left, top);
	
	var winWidth = doc.body.clientWidth, winHeight = doc.body.clientHeight;
	if( (tooLarge && (winWidth < 200 || winHeight < 200) )
		|| !tooLarge && !tooSmall && (e.width > 150 && winWidth <= 150 || e.height > 100 && winHeight <= 100) ) {
		win._e = {
			src : e.src,
			width : e.width,
			height : e.height,
			tooLarge : tooLarge
		}
		doc.getElementById("loading").style.display = "none";
		doc.getElementById("error").style.display = "none";
		doc.getElementById("image").style.display = "none";
		doc.title = "Image Loaded";
	} else { // can resize
		doc.getElementById("loading").style.display = "none";
		doc.getElementById("error").style.display = "none";
		doc.getElementById("resize").style.display = "none";
		doc.title = win._title;
	}
}

iPop.ErrorLoading = function(e, doc, win) {
	if(!e || !doc || !win) return;
	e.onload = null; e.onerror = null;
	
	doc.getElementById("loading").style.display = "none";
	doc.getElementById("resize").style.display = "none";
	doc.getElementById("image").style.display = "none";
	doc.title = "Image not found";
}

iPop.ImageLoadedManualPopup = function(e, win) {
	if(!e || !win) return;
	var width = e.width + 20, height = e.height + 20;
	if(width > screen.availWidth) width = screen.availWidth - 20;
	if(height > screen.availHeight) height = screen.availHeight - 100;
	var left = (screen.availWidth - width)/2, top = (screen.availHeight - height)/ 2;
	win.open(e.src, "ManualImageViewer", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + (e.tooLarge ? ",scrollbars" : ""));
	win.close();
}


iPop.AutoApply = function(container) {
	if(!container) container = document;
	var a = container.getElementsByTagName("A");
	for(var i = 0; i < a.length; i++) {
		if( a[i].href.match(/\.(gif|jpg|png|jpeg)$/i) ) {
			applyPopup(a[i]);
		}
	}
	
	function applyPopup(link) {

		var n, imgs = 0, whitespace = 0, alt = null;
		for(var i = 0; n = link.childNodes[i]; i++) {
			if(n.tagName == "IMG") {
				imgs++;
				alt = n.alt;
			} else if(n.nodeValue) {
				var val = n.nodeValue;
				if( val.replace(/\s+/g, "") == "" ) whitespace++;
			}
		}
		n = null;
		
		link.onclick = function(e) { return iPop(this.href, alt); }
	}
}

