function gid($co) {return document.getElementById($co);}

function init_page()
	{
	init_opener();
	init_page_width();
	write_counter($stranka,$verze);
	}

// page width:

function init_page_width()
	{		
	var $ww,$ee;
	try
		{
		var $input=document.createElement("input");
		$input.id="narrower";
		$input.type="checkbox";
		$ww=document.body.clientWidth ? document.body.clientWidth : self.innerWidth;
		if(document.cookie.indexOf("narrow")>-1) $input.checked=document.cookie.indexOf("narrow=1")>-1?true:false;
		else $input.checked=true;
		$input.onchange=s_expand_width;
		$input.onkeyup=s_expand_width;
		$input.onclick=s_expand_width;
		gid("narrowbox").appendChild($input);
		gid("narrowbox").appendChild(document.createTextNode(" pružný design – podle velikosti písma"));
		gid("narrowbox").setAttribute("for","narrower");
		s_expand_width();
		}
	catch($ee){}
	}

function s_expand_width()
	{
	var $ee;
	try
		{
		gid("main").className=gid("main").className.replace(/narrow/,"");
		gid("main").className+=gid("narrower").checked?" narrow":"";
		document.cookie="narrow="+(gid("narrower").checked?"1":"0")+"; path=/";
		}
	catch(ee){}
	}

// new window:

function switch_new_win_stnd(e)
	{
	switch_new_win(e.currentTarget.checked);
	}

function switch_new_win(st)
	{
	document.cookie="neotevirat_v_novem_okne="+(st?"0":"1")+"; path=/";
	}

function get_anchor(el)
	{
	while(el.nodeName!="A") el=el.parentNode;
	return el;
	}

function open_anchor(e)
	{
	if(!e)e=window.event;
	var atarget=e.currentTarget?e.currentTarget:get_anchor(e.srcElement);
	open_new_window=document.getElementById("windowswitch").checked;
	atarget.target=open_new_window?"_blank":"";
	}

function check_anchor(a)
	{
	var test_exp=new RegExp("^(http(s)?://"+self.location.host+"|mailto:)");
	return ((!test_exp.test(a.href) || a.rel=="external" || a.className.indexOf("external")>-1) && a.href);
	}

function init_opener()
	{
	var i,e,open_new_window,anch,test_exp,found_ext_anchors,switchdiv;
	var sdtitle=" otevírat odkazy vedoucí mimo server www.all-stars.cz v novém okně - doporučené";
	var linktext=" otevírat externí odkazy v novém okně";

	if(document.getElementsByTagName("a"))
		{
		open_new_window=document.cookie?((document.cookie.indexOf("neotevirat_v_novem_okne=1")>-1)?false:true):true;
		anch=document.body.getElementsByTagName("a");
		found_ext_anchors=0;
		for(i=0;i<anch.length;i++)
			{
			if(anch[i].href.indexOf("local-redir")>-1) anch[i].href=unescape("http://"+anch[i].href.substr(7,anch[i].href.substr(7).indexOf("/"))+anch[i].href.substr(anch[i].href.indexOf("=")+1));
			if(check_anchor(anch[i]))
				{
				anch[i].className+=" external";
				try
					{
					anch[i].addEventListener("click",open_anchor,true);
					}
				catch(e){}
				try
					{
					anch[i].onclick=open_anchor;
					}
				catch(e){}
				found_ext_anchors++;
				}
			}
		if(found_ext_anchors)
			{
			switchdiv=document.getElementById("windowopener");
			switchdiv.title=sdtitle;
			try
				{
				switchdiv.innerHTML="<input type='checkbox' id='windowswitch' onchange='switch_new_win(this.checked);' "+(open_new_window?"checked='checked' ":"")+"/>"+linktext;
				}
			catch(e)
				{
				var switchbox=document.createElement("input");
				switchdiv.appendChild(switchbox);
				switchbox.setAttribute("type","checkbox");
				switchbox.setAttribute("id","windowswitch");
				switchbox.addEventListener("change",switch_new_win_stnd,false);
				if(open_new_window) switchbox.checked=true;

				switchdiv.appendChild(document.createTextNode(linktext));
				}
			switchdiv.setAttribute("for","windowswitch");
			}
		}
	}

function write_counter(stranka,verze)
	{
	var ee;
	if(stranka)
		{
		var $src='/pocitadlo/counter.php?server='+top.location.host+'&stranka='+stranka+'&verze='+verze+'&referer='+escape(top.document.referrer)+'&rozliseni_x='+screen.width+'&rozliseni_y='+screen.height+'&velikost_okna_x='+(top.innerWidth ? top.innerWidth : top.document.body.clientWidth)+'&velikost_okna_y='+(top.innerHeight ? top.innerHeight : top.document.body.clientHeight);
		try
			{
			counter.innerHTML="<img src='"+$src+"' />";
			}
		catch(ee)
			{
			var c_hory=document.createElement("img");
			with(c_hory)
				{
				id="pocitadlo";
				src=$src;
				alt="";
				width="0";
				height="0"
				}
			gid("counter").appendChild(c_hory);
			}
		}
	}
