Array.prototype.withEvery = function(what)
{
	for(var i = 0; i < this.length; i++) what(this[i])
};
Array.prototype.numSort = function()
{
	return this.sort(function(a, b) { return a - b });
};
var intro = !document.getElementById("text");

var ui = {
	"width": 736,
	"fontSize": 83,
	"font": "sans",
	"align": "justify"
};

var page = {
	"setWidth": function(n)
	{
		ui.width = [360, n, 960].numSort()[1];
		return n - ui.width;
	},
	"setFontSize": function(n)
	{
		ui.fontSize = [60, n, 160].numSort()[1];
		return n - ui.fontSize;
	},
	"setFont": function(n)
	{
		ui.font = n;
	},
	"setAlign": function(n)
	{
		ui.align = n;
	},
	"setState": function(s)
	{
		if(!intro)
		{
			document.getElementById("text").style.width = document.getElementsByTagName("dir")[0].style.width = ui.width + "px";
			document.documentElement.style.fontSize = ui.fontSize + "%";
		}
		document.documentElement.className = ui.font + " " + ui.align + "";
		if(this.tio)
		{
			clearTimeout(this.tio);
			this.tio = 0;
		}
		if(!s) this.to = setTimeout(function()
		{
			for(var p in ui) document.cookie = "ui." + p + "=" + ui[p] + "; expires=" + (new Date(2010, 12, 31)).toGMTString();
		}, 250);
	},
	"loadState": function()
	{
		document.cookie.split("; ").withEvery(function(n)
		{
			if(!n.match(/^ui/)) return false;
			ui[n.split("=")[0].substring(3)] = n.split("=")[1];
		});
		page.setWidth(1 * ui.width);
		page.setFontSize(1 * ui.fontSize);
		page.setFont(ui.font);
		page.setAlign(ui.align);
		page.setState(true);
	}
};


window.onload = function()
{
	if(!intro)
	{
		if(document.write)
		{
			var scriptMenu = document.createElement("script");
			scriptMenu.src = "ui.menu";
			document.documentElement.appendChild(scriptMenu);
		}
	}
};
if(!intro)
{
	if(!document.write)
	{
		document.createElement = function(n)
		{
			return document.createElementNS(document.documentElement.getAttribute("xmlns:html"), "html:" + n)
		};
		document.body = document.documentElement;
		document.cookie = "";
	}
}


page.loadState();

if(intro)
{
	(window.onresize = function()
	{
		var w = document.body.clientWidth;
		document.body.style.fontSize = (w < 1100 ? w < 1000 ? w < 800 ? w < 700 ? w < 600 ? 64 : 73 : 75 : 84 : 96 : 100) + "%";
	})()
}
else
{
	document.body.onclick = document.body.onmouseup = function()
	{
		document.body.onmousemove = null;
	};

	["T", "C", "B", "R"].withEvery(function(r)
	{
		var re = document.createElement("div");
		re.id = "resizer" + r;
		re.title = "Dvojklikem nastavíte výchozí " + (r == "R" ? "velikost písma" : "šířku");
		re.onmousedown = function()
		{
			if(arguments[0]) window.event = arguments[0];
			document.body.onmousemove = function()
			{
				if(arguments[0]) window.event = arguments[0];
				if(r == "R")
				{
					if(!page.setFontSize(ui.fontSize + (event.screenY - this.currentY) * 2 * (document.getElementsByTagName("dir")[0].offsetHeight - 10) / ui.fontSize)) this.currentY = event.screenY;
				}
				else
					if(!page.setWidth(ui.width + (event.screenX - this.currentX) * 2)) this.currentX = event.screenX;
				page.setState();
			};
			document.body.currentX = event.screenX;
			document.body.currentY = event.screenY;
		};
		re.ondblclick = function()
		{
			if(r == "R") page.setFontSize(83); else page.setWidth(736);
			page.setState();
		};
		(r == "R" ? document.getElementsByTagName("dir")[0] : document.getElementById("text")).appendChild(re);
	});


	var sw = document.createElement("div");
	sw.id = "switch";
	sw.appendChild(document.createTextNode("T"));
	sw.onclick = function()
	{
		page.setFont({"sans": "serif", "serif": "gothic", "gothic": "sans"}[ui.font]);
		page.setState();
	};
	document.getElementById("text").appendChild(sw);
}



setTimeout(function()
{
	var img = document.createElement("img");
	img.src="http://cnt1.pocitadlo.cz/counter.php?poc=41213&ref="+escape(top.document.referrer)+"&depth="+screen.colorDepth+"&width="+screen.width+"&height="+screen.height+"&tmp="+Math.floor(1000000 * Math.random());
	img.style.position = "absolute";
	img.style.left = img.style.top = "-100px";
	img.style.width = img.style.height = "10px";
	document.body.appendChild(img);
}, 3000)