function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		but1b = newImage("images/but1b.gif");
		but2b = newImage("images/but2b.gif");
		but3b = newImage("images/but3b.gif");
		but4b = newImage("images/but4b.gif");
		but7b = newImage("images/but_avaleht_b.gif");
		preloadFlag = true;
	}
}
//
var w = screen.availWidth - 170;
var x = Math.ceil(w * Math.random());
var y = screen.availHeight + Math.ceil(900 * Math.random());
var yend = -380;
var ystep = 2;
function kasshiir() {
	//document.getElementById("debug").innerHTML = drg;
	y = y - ystep;
	document.getElementById("kass").style.left = document.getElementById("kate").style.left = x + 'px';
	document.getElementById("kass").style.top = document.getElementById("kate").style.top = y + 'px';
	if (y < yend) {
		x = Math.ceil(w * Math.random());
		y = screen.availHeight + Math.ceil(1100 * Math.random());
		document.getElementById("kate").style.left = x + 'px';
		document.getElementById("kate").style.top  = y + 'px';
	}
	//if (drg < 1) {
		kt = window.setTimeout('kasshiir()',40);
	//}
}
// start dragdrop
var _startX = 0;
var _startY = 0;
var _offsetX = 0;
var _offsetY = 0;
var _dragElement;
var _oldZIndex = 0;
//var drg = 0;

InitDragDrop();

function InitDragDrop() {
	document.onmousedown = OnMouseDown;
	document.onmouseup = OnMouseUp;
}

function OnMouseDown(e) {
	if (e == null) 
		e = window.event; 
		var target = e.target != null ? e.target : e.srcElement;
	
	if ((e.button == 1 && window.event != null || e.button == 0) && target.className == 'drag') {
		_startX = e.clientX;
		_startY = e.clientY;
		
		_offsetX = ExtractNumber(target.style.left);
		_offsetY = ExtractNumber(target.style.top);
		
		_oldZIndex = target.style.zIndex;
		target.style.zIndex = 10000;
		
		_dragElement = target;

		document.onmousemove = OnMouseMove;
		
		document.body.focus();
		
		document.onselectstart = function () { return false; };
		target.ondragstart = function() { return false; };
		//drg = 1;
		
		return false;
	}
}

function ExtractNumber(value) {
	var n = parseInt(value);
	return n == null || isNaN(n) ? 0 : n;
}

function OnMouseMove(e) {
	if (e == null)
		var e = window.event; 
		_dragElement.style.left = (_offsetX + e.clientX - _startX) + 'px';
		_dragElement.style.top = (_offsetY + e.clientY - _startY) + 'px';
		x = (_offsetX + e.clientX - _startX);
		y = (_offsetY + e.clientY - _startY);
}

function OnMouseUp(e) {
	if (_dragElement != null) {
		_dragElement.style.zIndex = _oldZIndex;
		document.onmousemove = null;
		document.onselectstart = null;
		_dragElement.ondragstart = null;
		_dragElement = null;
	}
	//drg = 0;
	window.clearTimeout(kt);
	kasshiir();
}
// end dragdrop
//
function nospam(user,domain) {
locationstring = "mailto:" + user + "@" + domain;
window.location = locationstring;
}
//
function winOpen(loc,nimi,scr,rez,pwidth,pheight) {
//var aeg = new Date().getTime();
ltpopup = window.open (loc,nimi,"directories=0,toolbar=0,location=0,status=0,menubar=0,scrollbars="+scr+",resizable="+rez+",width="+pwidth+",height="+pheight+",copyhistory=1");
}
// 
function pilt(ploc,pnimi,pscr,prez,pwidth,pheight,pcolor) {
  myWin = open('', 'piltwindow', 'directories=0,toolbar=0,location=0,status=0,menubar=no,scrollbars='+pscr+',resizable='+prez+',width='+(pwidth+60)+',height='+(pheight+40)+'');
  myWin.document.open();
  myWin.document.write('<html>\n\r<head>\n\r<title>'+pnimi+'<\/title>\n\r<\/head>'
  +'\n\r<body style="background-color: #'+pcolor+'; margin: 20px 0 20px 0;">'
  +'\n\r<div align="center">'
  +'\n\r<a href="javascript:void(0);" onClick="window.close();"><img src="'+ploc+'" height="'+pheight+'" width="'+pwidth+'" alt="" border="0" title="click to close this window"><\/a>'
  +'\n\r<\/div>\n\r<\/body>\n\r<\/html>');
  myWin.document.close();  
}
//
function winPrint() {
	setTimeout('window.print()',500);
}
//
function changeLinks(linknum) {
	document.getElementById("mlink" + linknum).style.color = "#000";
}
//

