fookuses = false;
function o(i)  { if (typeof(i) != "string") return i; return document.getElementById ? document.getElementById(i) : document.all[i] }
function os(i) { return o(i).style }
function rnd(algus, lopp) { return Math.round((Math.random() * (lopp-algus)) + algus); }
function fixScroll(div) { if (!fookuses) { var s = div.scrollTop; div.firstChild.focus(); div.scrollTop = s; } }

function load_skin()
{
  var tahan_infot_resu_kohta = new Image(); tahan_infot_resu_kohta.src = "resu.gif?" + document.body.clientWidth + 'x' + document.body.clientHeight;
 	set_paike(); window.onresize = function() { set_paike() }
	return true;
}

function load_folk()
{
	var c = o('content'), f, e, el;
	c.insertBefore(document.createElement('a'), c.firstChild);
	c.onmouseover = function() { fixScroll(this); }
	c.onmousedown = function() { this.onmouseover = null; }
	c.onmouseup   = function() { if (window.getSelection && window.getSelection() == '') { this.onmouseover=function() {fixScroll(this)}; fixScroll(this); } }
	fixScroll(c);

	// anname teada kui mõni vormi element fookuses on; sellel ajal scrollimise "extension" ei tööta ;)
	for(f = 0; f < document.forms.length; f++)
	for(e = 0; e < document.forms[f].elements.length; e++)
	if ((el = document.forms[f].elements[e]) && (el.nodeName == 'INPUT' || el.nodeName == 'TEXTAREA' || el.nodeName == 'SELECT'))
	{
		el.onfocus = function() { fookuses = true; }
		el.onblur  = function() { fookuses = false; }
	}

	if (document.body.className == 'linnaplaan' 
	    || document.body.className == 'town_map'
	    || document.body.className == 'kartta') load_linnaplaan();
	if (document.body.className == 'album') load_album();
}


function set_paike()
{
	var b = document.body, p = 250;  // paike.gif on ise 250 ehk p
	var c = o('content'), s = c.style,

 // IE layout-i puhul on need offsetWidth-id alati vordsed
	l = b.offsetWidth == c.offsetWidth ?  rnd(150, c.clientWidth - p - 40) : rnd(150, c.clientWidth - (p/2)),
	t = rnd(1, document.body.clientHeight - p);
	if (b.clientWidth > 500)
	s['background'] = 'url(skin/paike.gif) no-repeat ' + l + 'px ' + t + 'px fixed';
	else s['background'] = 'transparent';
}


function load_linnaplaan()
{
	kohapilt = document.createElement('div');
	kohapilt.pilt = document.createElement('img');
	kohapilt.tekst = document.createElement('div');
	kohapilt.setAttribute('id', 'kohapilt');
	kohapilt.style.visibility = 'hidden';
	kohapilt.naita = function(koht, tekst)
	{
		this.pilt.src = 'img/viljandi/' + koht + '.gif';
		this.tekst.innerHTML = tekst;
		this.style.visibility = 'visible';
	}
	kohapilt.appendChild(kohapilt.pilt);
	kohapilt.appendChild(kohapilt.tekst);
	document.body.appendChild(kohapilt);

	nrlist = document.getElementsByName('nr');
	for(var i = 0; i < nrlist.length; i++)
	{
		nrlist[i].ovsrc  = new Image(); nrlist[i].ovsrc.src  = 'img/nr/' + (i+1) + '_ov.gif';
		nrlist[i].defsrc = new Image(); nrlist[i].defsrc.src = nrlist[i].src;
		nrlist[i].mummu  = nrlist[i];
		
		nrlist[i].onmouseover = mummu_over;
		nrlist[i].onmouseout  = mummu_out;
	}

	var legend = o('legend');
	for (var r = 0; r < legend.rows.length; r++)
	for (var c = 0; c < 3; c += 2)
	if (i = parseInt(legend.rows[r].cells[c].innerHTML))
	{
		legend.rows[r].cells[c  ].mummu = nrlist[i - 1];
		legend.rows[r].cells[c+1].mummu = nrlist[i - 1];
		legend.rows[r].cells[c  ].onmouseover = mummu_over;
		legend.rows[r].cells[c+1].onmouseover = mummu_over;
		legend.rows[r].cells[c  ].onmouseout  = mummu_out;
		legend.rows[r].cells[c+1].onmouseout  = mummu_out;
	}
}

function spix(o, n) { return (parseInt(o) + n) + 'px'; }
function mummu_over()
{
	var mumm = this.mummu;
	mumm.src = mumm.ovsrc.src;
	mumm.style.left = spix(mumm.style.left, -20);
	mumm.style.top  = spix(mumm.style.top,  -20);
	kohapilt.naita(mumm.id, mumm.alt);
}
function mummu_out()
{
	var mumm = this.mummu;
	mumm.style.left = spix(mumm.style.left, 20);
	mumm.style.top = spix(mumm.style.top, 20);
	mumm.src = mumm.defsrc.src;
}


function load_album()
{
}


