/*
Layerite tüürimise lib
(c)1999 Mart Karu [karu@pi.estnet.ee]

ilma loata kasutajatel munad maha! sorry

*/
var ie = false;
var ns = false;
ie = (navigator.appName=="Microsoft Internet Explorer")&&(parseInt(navigator.appVersion)>= 4);
ns = (navigator.appName == "Netscape")&&(parseInt(navigator.appVersion)>=4);

var no_browser = -99999;


// layerite nähtamine

function hideLayer(layer) {
	if (ie) layer.style.visibility = "hidden";
	if (ns) layer.visibility = "hide";
	
}

function showLayer(layer) {
	if (ie) layer.style.visibility = "visible";
	if (ns) layer.visibility = "show";
}

function isVisible(layer) {
	if (ie && layer.style.visibility == "visible") return(true);
	if (ns && layer.visibility == "show") return(true);
	return(false);
}

// paigutamine

function moveLayer(layer, x, y) {
	if (ns) layer.moveTo(x, y);
	if (ie) {
		layer.style.left = x; 
		layer.style.top  = y;
	}
}

function shiftLayer(layer, x, y) {
	if (ns) layer.moveBy(x, y);
	if (ie) {
		layer.style.pixelLeft += x;
		layer.style.pixelTop  += y;
	}
}

function getLeft(layer) {
	if (ie) return(layer.style.pixelLeft)
	if (ns) return(layer.left)
	return(no_browser)
}

function getRight(layer) {
	if (ie) return(layer.style.pixelLeft + getWidth(layer))
	if (ns) return(layer.left + getWidth(layer))
	return(no_browser)
}

function getTop(layer) {
	if (ie) return(layer.style.pixelTop)
	if (ns) return(layer.top)
	return(no_browser)
}

function getBottom(layer) {
	if (ie) return(layer.style.pixelTop + getHeight(layer))
	if (ns) return(layer.top + getHeight(layer))
	return(no_browser)
}

function getWidth(layer) {
	if (ns) {
		if (layer.document.width) return(layer.document.width);
		else return(layer.clip.right - layer.clip.left);
	}
  	if (ie) {
		if (layer.style.pixelWidth) return(layer.style.pixelWidth);
		else return(layer.clientWidth);
	}
	return(no_browser);
}

function getHeight(layer) {
	if (ns) {
		if (layer.document.height) return (layer.document.height);
		else return(layer.clip.bottom - layer.clip.top);
	}
	if (ie) {
		if (false && layer.style.pixelHeight) return(layer.style.pixelHeight);
		else return(layer.clientHeight);
	}
	return(no_browser);
}

function getZ(layer) {
	if (ns) return(layer.zIndex);
	if (ie) return(layer.style.zIndex);
	return(no_browser);
}

function setZ(layer, z) {
	if (ns) layer.zIndex = z;
	if (ie) layer.style.zIndex = z;
}

// Clip

function clipLayer(layer, clipl, clipt, clipr, clipb) {
	if (ns) {
		layer.clip.left   = clipl;
		layer.clip.top    = clipt;
		layer.clip.right  = clipr;
		layer.clip.bottom = clipb;
	}
	if (ie) layer.style.clip = 'rect(' + clipt + ' ' +  clipr + ' ' + clipb + ' ' + clipl +')';
}

function getClipLeft(layer) {
	if (ns) return(layer.clip.left);
	if (ie) {
		if (!layer.style.clip) return(0);
		var c = IEClip(layer.style.clip);
		return(c[3]);
	}
	return(no_browser);
}

function getClipTop(layer) {
	if (ns) return(layer.clip.top);
	if (ie) {
		if (!layer.style.clip) return(0);
		c = IEClip(layer.style.clip);
		return(c[0]);
	}
	return(no_browser);
}

function getClipRight(layer) {
	if (ns) return(layer.clip.right);
	if (ie) {
		if (!layer.style.clip) return(layer.style.pixelWidth);
		c = IEClip(layer.style.clip);
		return(c[1]);
	}
	return(no_browser);
}

function getClipBottom(layer) {
	if (ns) return(layer.clip.bottom);
	if (ie) {
		if (!layer.style.clip) return(layer.style.pixelHeight);
		c = IEClip(layer.style.clip);
		return(c[2]);
	}
	return(no_browser);
}

function getClipWidth(layer) {
	if (ns) return(layer.clip.right);
	if (ie) {
		if (!layer.style.clip) return(layer.style.pixelWidth);
		c = IEClip(layer.style.clip);
		return(c[1] - c[3]);
	}
	return(no_browser);
}

function getClipHeight(layer) {
	if (ns) return(layer.clip.bottom);
	if (ie) {
		if (!layer.style.clip) return(layer.style.pixelHeight);
		c = IEClip(layer.style.clip);
		return(c[2] - c[0]);
	}
	return(no_browser);
}

function IEClip(str) {
	var c = new Array();
	var i; 
	i = str.indexOf("(");        c[0] = parseInt(str.substring(i + 1, str.length), 10);
	i = str.indexOf(" ", i + 1); c[1] = parseInt(str.substring(i + 1, str.length), 10);
	i = str.indexOf(" ", i + 1); c[2] = parseInt(str.substring(i + 1, str.length), 10);
	i = str.indexOf(" ", i + 1); c[3] = parseInt(str.substring(i + 1, str.length), 10);
	return(c);
}

// Scroll

function scrollLayerTo(layer, x, y, bound) {
	var dx = getClipLeft(layer) - x;
	var dy = getClipTop(layer) - y;
	scrollLayerBy(layer, -dx, -dy, bound);
}

function scrollLayerBy(layer, dx, dy, bound) {
	var cl = getClipLeft(layer);
	var ct = getClipTop(layer);
	var cr = getClipRight(layer);
	var cb = getClipBottom(layer);
	if (bound) {
		if (cl + dx < 0) dx = -cl;
		else if (cr + dx > getWidth(layer)) dx = getWidth(layer) - cr;
		if (ct + dy < 0) dy = -ct;
		else if (cb + dy > getHeight(layer)) dy = getHeight(layer) - cb;
	}
  clipLayer(layer, cl + dx, ct + dy, cr + dx, cb + dy);
  shiftLayer(layer, -dx, -dy);
}

// backgroundz
function setBgColor(layer, color) {
	if (ns) layer.bgColor = color;
	if (ie)layer.style.backgroundColor = color;
}

function setBgImage(layer, src) {
	if (ns) layer.background.src = src;
	if (ie) layer.style.backgroundImage = "url(" + src + ")";
}

// utiliidid
function getLayer(name) {
	if (ns) return findLayer(name, document);
	if (ie) return eval('document.all.' + name);
	return null;
}

function findLayer(name, doc) {
	var i, layer;
	for (i = 0; i < doc.layers.length; i++) {
		layer = doc.layers[i];
		if (layer.name == name) return layer;
		if (layer.document.layers.length > 0) {
			layer = findLayer(name, layer.document);
			if (layer != null) return layer;
		}
	}
	return null
}

// kliendi aken

function getWinWidth() {
	if (ns) return(window.innerWidth);
	if (ie) return(document.body.offsetWidth);
	return(no_browser);
}

function getWinHeight() {
	if (ns) return(window.innerHeight);
	if (ie) return(document.body.offsetHeight);
	return(no_browser);
}

function getPageWidth() {
	if (ns) return(document.width);
	if (ie) return(document.body.scrollWidth);
	return(no_browser);
}

function getPageHeight() {
	if (ns) return(document.height);
	if (ie) return(document.body.scrollHeight);
	return(no_browser);
}

function getScrollX() {
	if (ns) return(window.pageXOffset);
	if (ie) return(document.body.scrollLeft);
	return(no_broswser);
}

function getScrollY() {
	if (ns) return(window.pageYOffset);
	if (ie) return(document.body.scrollTop);
	return(no_browser);
}

function docrap(){
	var uudis = getLayer('uudis');
	moveLayer(uudis, getTop(uudis), getLeft(uudis) );
}

// create popup window for images on the fly 
// script by Michael Paige (http://www.treetrybe.com/imm/)
// edited for Mac by Mark Howells (http://www.mark.ac/journal/) 

var imgWindow = new Object;
var imgWindow = null;

function popImg(thepic,w,h,zetekst,asukoht,autor) {
	var specs 	= 'width=' + w + ', height=' + h;
	var img = thepic;
	if (!imgWindow || imgWindow.closed) {
		//imgWindow = window.open(thepic,'',specs); 
		
		hh = h + 60;
		imgWindow = window.open('','','width=' + w + ', height=' + hh + ', location=0, toolbar=0, status=no, menubar=0, directories=0, scrollbars=0, status=0, resizable=0');
		imgWindow.document.write('<?xml version="1.0" encoding="UTF-8"?\>'); 
		imgWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'); 
		imgWindow.document.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'); 
		imgWindow.document.write('<head><title>kolhoos.pri.ee</title>');
		imgWindow.document.write('<meta http-equiv="imagetoolbar" content="no">');
		imgWindow.document.write('<base href="http://kolhoos.pri.ee/" />'); 
		imgWindow.document.write('<link rel="stylesheet" href="stiil.css">');
		imgWindow.document.write('<style type="text/css"><!--'); 
 		
		// Works in NN4 to achieve zero margins
 		imgWindow.document.write('body {margin:-10px 0 0 -10px;padding:0}');

		// Works in real browsers to achieve zero margins
		imgWindow.document.write('html body {margin:0}'); 
		imgWindow.document.write('img {display:block;border:0}'); 
		imgWindow.document.write('\/\/--></style></head>'); 
		imgWindow.document.write('<body onblur="self.close()">'); 

		imgWindow.document.write('<div><table border=0 cellpadding=0 cellspacing=0 height="' + hh + '"><tr><td background="laadimine.gif" width="' + w + '" height="' + h + '"><img src="' + thepic + '"></td></tr>');
		imgWindow.document.write('<tr><td height=2 bgcolor=#c8c8c8></td></tr><tr><td align=right>');
		imgWindow.document.write('<font class=tekst><font size=-2 color=#c8c8c8>');
		if (autor) imgWindow.document.write(autor);
		imgWindow.document.write('&nbsp;</font></font></td></tr>');
		imgWindow.document.write('<tr><td align=left><table border=0 cellpadding=1 cellspacing=1><tr><td valign=middle>');
		imgWindow.document.write('<font class=tekst><font color=#000000>');
		if (zetekst) imgWindow.document.write(zetekst);
		imgWindow.document.write('&nbsp;</font></font></td></tr></table></td></tr>');
		imgWindow.document.write('</table></div>');		
		imgWindow.document.write('</body></html>');
		imgWindow.document.close(); /*added by me*/
	/*	gowidth=(screen.width/2-(w/2))
		goheight=(screen.height/2-(h/2))
		imgWindow.moveTo(gowidth,goheight)
		imgWindow.focus() */
	}
	else {
		imgWindow.focus();
	}
}

