/* IE6 flicker fix
-------------------------------------------------- */
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

/* Mark checkboxes
-------------------------------------------------- */
function markall(id,value) {
	f = document.forms[id];
	for (i = 0; i < f.elements.length; i++) {
		f.elements[i].checked = value;
	}
}

/* Popup
-------------------------------------------------- */
function popup(url, size) {

	window_width = '800px';
	window_height = '500px';
	window_name = 'Tabel';

	settings=
	"toolbar=no,location=no,directories=no,"+
	"status=no,menubar=no,scrollbars=yes,"+
	"resizable=yes,width="+window_width+",height="+window_height;

	NewWindow=window.open(url,window_name,settings);

	if (window.focus) {
		NewWindow.focus();
	}
}

/* Toggle ID
-------------------------------------------------- */
function toggle(id){
	var element = document.getElementById(id);

	if (element.style.display == 'none') {
		element.style.display = '';
	} else {
		element.style.display = 'none';
	}
}

/* Show ID
-------------------------------------------------- */
function show(id){
	var element = document.getElementById(id);
	element.style.display = '';
}

/* =floater
-------------------------------------------------- */
function JSFX_FloatTopLeft() {
	var startX = 10, startY = 20;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	var px = document.layers ? "" : "px";

	function ml(id) {
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
		el.x = startX; el.y = startY;
		return el;
	}

	window.stayTopLeft=function() {
		var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		var dY = (pY > startY) ? (pY+20) : startY;
		ftlObj.y += (dY - ftlObj.y)/10;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 20);
	}
	ftlObj = ml("floatmenu");
	stayTopLeft();
}

function create_floatmenu() {
	JSFX_FloatTopLeft();
}

/* =jQuery functions
-------------------------------------------------- */
var toggleResults = {
	init : function(){
		$("div.results div.result-title").click(this.clickIt);
	},
	clickIt : function(){
		$(this).next("div.content").slideToggle("medium");
		$(this).children("h2").toggleClass("closed");
	}
};
function fixIEoverflow() {
	if (!/*@cc_on!@*/0) return;

	var all = document.getElementsByTagName('*'), i = all.length;
	while (i--) {
		// adding a class match just to show the difference
		if (all[i].className.match(/scrollwrap/) && all[i].scrollWidth > all[i].offsetWidth) {
			all[i].style['overflowY'] = 'hidden';
			all[i].style['paddingBottom'] = '17px';
		}
	}
}

$(document).ready(function(){
	$("body:not(#popup) table.data").wrap("<div class='scrollwrap'></div>");
	$("body:not(#popup) table.data td").wrapInner("<div class='nowrap'></div>");
	fixIEoverflow();

	$("#content div.kastitekst_tabel").next("p.kastitekst").css("margin-top","0");
	$("#content div.kastitekst_tabel").next("p.kastitekst_pealkiri").css("margin-top","0");
	$("#content p.kastitekst_pais").next("p.kastitekst").css("margin-top","0");
	$("#content p.kastitekst_pais").next("p.kastitekst_pealkiri").css("margin-top","0");
	$("#content p.kastitekst").next("p.kastitekst_pealkiri").css("margin-top","0");
	$("#content p.kastitekst").next("p.kastitekst").css("margin-top","0");
	$("#content p.kastitekst_pealkiri").next("p.kastitekst").css("margin-top","0");
	$("#content p[class^='kastitekst']").next("p[class^='kastitekst']").css("padding-top","0");

	$("#content p.hallikastitekst_pais").next("p.hallikastitekst").css("margin-top","0");
	$("#content p.hallikastitekst_pais").next("p.hallikastitekst_pealkiri").css("margin-top","0");
	$("#content p.hallikastitekst").next("p.hallikastitekst_pealkiri").css("margin-top","0");
	$("#content p.hallikastitekst").next("p.hallikastitekst").css("margin-top","0");
	$("#content p.hallikastitekst_pealkiri").next("p.hallikastitekst").css("margin-top","0");
	$("#content p[class^='hallikastitekst']").next("p[class^='hallikastitekst']").css("padding-top","0");
});
