
function gid($co)
	{
	return document.getElementById($co);
	}

function switch_comments(e)
	{
	var $skryj=document.body.className=="skryjkomentare"?false:true;
	document.body.className=$skryj?"skryjkomentare":"";
	document.cookie="skryjkomentare="+($skryj?1:0)+";path=/";
	}

function c_kontrolz()
	{
	var $i,$anode,$bnode,$cnode,ee;
	// skryti komentaru 
	document.body.className=document.cookie.indexOf("skryjkomentare=1")>-1?"skryjkomentare":"";
	var $koment_elements=find_class(document.body,"skryvatkomentare");
	if($koment_elements.length)
		{
		$anode=document.createElement("span");
		$anode.appendChild(document.createTextNode("skrýt komentáře"));
		$anode.title="přepne zobrazení / skrytí komentářů pro větší přehlednost kódu";
		$bnode=document.createElement("div");
		$bnode.className="prepinackomentaru";
		$bnode.appendChild($anode);
		for($i=0;$i<$koment_elements.length;$i++)
			{
			$cnode=$bnode.cloneNode(true);
			$cnode.onclick=switch_comments;
			$koment_elements[$i].parentNode.insertBefore($cnode,$koment_elements[$i]);
			$cnode=$bnode.cloneNode(true);
			$cnode.onclick=switch_comments;
			$cnode.className+=" bottom";
			try{$koment_elements[$i].parentNode.insertBefore($cnode,$koment_elements[$i].nextSibling,$bnode.cloneNode(true));}
			catch(ee){}
			}
		}
	// konec skryti komentaru
	
	this.heading="Nastavení:";
	
	this.page_width=false;
	var $tnode,$hnode,$nwnode;
	if(gid("kontrolz").firstChild)
		{
		this.node=gid("kontrolz");
		this.node.removeChild(this.node.firstChild);
		
		this.add_page_width=add_page_width;
		
		$hnode=document.createElement("h3");
		$tnode=document.createTextNode(this.heading);
		$hnode.appendChild($tnode);
		this.node.appendChild($hnode);
		this.node.style.visibility="visible";
		
		// otevírač nového okna:
		$nwnode=document.createElement("label");
		$nwnode.id="windowopener";
		this.node.appendChild($nwnode);
		setTimeout("init_opener()",100);
		// konec otevírače nového okna
		}
	else return null;
	}

	function add_page_width()
		{
		this.page_width=new c_page_width();
		}

function c_page_width()
	{
	this.units="em";
	this.step=3;
	this.max_width=99;
	this.min_width=40;
	this.default_width=58;
	this.description="šířka stránky: ";
	this.plus_title="zvětšit šířku stránky";
	this.minus_title="zmenšit šířku stránky";
	
	this.plus=plus;
	this.minus=minus;
	this.create_width_kontrolz=create_width_kontrolz;
	this.set_width=set_width;
	
	if (document.cookie.indexOf("page_width=")>-1) 
		this.page_width=Number(document.cookie.substr(document.cookie.indexOf("page_width=")+11,2));
	if(isNaN(this.page_width))this.page_width=this.default_width;
	this.create_width_kontrolz();
	this.set_width(this.page_width);
	}

	function minus()
		{
		this.set_width(this.page_width-this.step);
		}

	function plus()
		{
		this.set_width(this.page_width+this.step);
		}

	function set_width($jak)
		{
		if($jak>this.max_width) $jak=this.max_width;
		if($jak<this.min_width) $jak=this.min_width;
		this.page_width=$jak;
		gid("main").style.width=this.page_width+this.units;
		document.cookie="page_width="+this.page_width+";path=/;expires=Wed, 30 Apr 2014 12:00:00 GMT";
		this.pwvalue.firstChild.nodeValue=" "+this.page_width+this.units+" ";
		}

	function create_width_kontrolz()
		{
		var $tnode,$imgnode;
		this.node=document.createElement("div");
		$tnode=document.createTextNode(this.description);
		this.node.appendChild($tnode);
		
		$imgnode=document.createElement("img");
		$imgnode.src="/img/arrows/wminus.gif";
		$imgnode.title=this.minus_title;
		$imgnode.alt=$imgnode.title;
		$imgnode.onclick=function(){$kontrolz.page_width.minus();}
		this.node.appendChild($imgnode);
		
		this.pwvalue=document.createElement("span");
		this.pwvalue.id="pwvalue";
		this.pwvalue.appendChild(document.createTextNode(""));
		this.node.appendChild(this.pwvalue);
		
		$imgnode=document.createElement("img");
		$imgnode.src="/img/arrows/wplus.gif";
		$imgnode.title=this.plus_title;
		$imgnode.alt=$imgnode.title;
		$imgnode.onclick=function(){$kontrolz.page_width.plus();}
		this.node.appendChild($imgnode);
		
		$kontrolz.node.appendChild(this.node);
		}

function setStatValues()
	{
	document.cookie="rozliseni_x="+ screen.width+"; path=/";
	document.cookie="rozliseni_y="+screen.height+"; path=/";
	document.cookie="velikost_okna_x="+ (self.innerWidth ? self.innerWidth : document.body.clientWidth)+"; path=/";
	document.cookie="velikost_okna_y="+ (self.innerHeight ? self.innerHeight : document.body.clientHeight)+"; path=/";
	}

function find_class($element,$classnames,$result,$first)
	{
	if(!$first)$first=$element;
	if(!$result)$result=new Array();
	if ($element.nodeType==1)
		{
		var $test_exp=new RegExp("(^| )("+$classnames+")( |$)");
		if($test_exp.test($element.className)) $result[$result.length]=$element;
		}
	if ($element.hasChildNodes()) $result=find_class($element.firstChild,$classnames,$result,$first);
	if ($element.nextSibling && $element!=$first) $result=find_class($element.nextSibling,$classnames,$result,$first);
	return $result;
	}

function switch_new_win_stnd(e)
	{
	switch_new_win(e.target.checked);
	}

function switch_new_win(st)
	{
	document.cookie="otevirat_nove_okno="+(st?"1":"0")+"; 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)
	{
	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 mimo tyto stránky do nového okna";
	var linktext=" otevírat externí odkazy v novém okně";
		
	if(document.getElementsByTagName("a"))
		{
		open_new_window=document.cookie?((document.cookie.indexOf("otevirat_nove_okno=1")>-1)?true:false):false;
		anch=document.getElementsByTagName("a");
		found_ext_anchors=0;
		for(i=0;i<anch.length;i++) if(check_anchor(anch[i])) 
			{
			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));
				}
			}
		}
	}

function get_current_style($element,$property)
  {
  var ee,$i,$val;
  try
    {
    var $cs=document.defaultView.getComputedStyle($element,'');
    $val=$cs.getPropertyValue($property);
    }
  catch(ee)
    {
    if($element.currentStyle)
    	{
	    $property=$property.split("-");
	    for($i=1;$i<$property.length;$i++) $property[$i]=$property[$i].toUpperCase();
	    $property=$property.join("");
	    $val=$element.currentStyle.getAttribute($property);
	    }
    }
  return $val;
  }

function color2array($value)
	{
	if($value.substr(0,1)=="#")return hex2array($value);
	else if($value.indexOf("rgb")>-1) return rgb2array($value);
	else return false;
	}

function rgb2array($value)
	{
	var $i;
	var $regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
	var $array=$regexp.exec($value);
	$array.shift();
	for($i=0;$i<3;$i++)$array[$i]=parseInt($array[$i]);
	return($array);
	}

function hex2array($value)
	{
	return new Array(parseInt($value.substr(1,2),16),parseInt($value.substr(3,2),16),parseInt($value.substr(5,2),16));
	}

setTimeout("setStatValues()",1000);

function write_counter(stranka,verze)
	{
		var ee;
	if(stranka)
		{
		var $src='/pocitadlo/counter.php?server=seky&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
			{
			gid("counter").innerHTML="<img src='"+$src+"' />";
			}
		catch(ee)
			{
			var c_hory=document.createElement("img");
			with(c_hory)
				{
				id="pchpocitadlo";
				src=$src;
				alt="";
				width="0";
				height="0"
				}
			gid("counter").appendChild(c_hory);
			}
		}
		}

/* Written by Scorpi: */ 	

Page = function () {};

Page.showPicture = function (imgNode, src, w, h, title) 
{
   var ImgDiv = document.getElementById('page-orig-image');
   
   if (ImgDiv) {
      if (ImgDiv.parentNode) {
         ImgDiv.parentNode.removeChild(ImgDiv);
      };
      var TitleDiv = ImgDiv.getElementsByTagName('div')[0];
      var Img = ImgDiv.getElementsByTagName('img')[0];
   } else {
      ImgDiv = document.createElement('div');
      ImgDiv.id = 'page-orig-image';
      ImgDiv.style.position = 'fixed';
      if (document.all && !window.Opera) {
         ImgDiv.style.position = 'absolute';
      };
      
      ImgDiv.style.left = '0';
      ImgDiv.style.textAlign = 'center';
      ImgDiv.style.width = '100%';
      
      TitleDiv = document.createElement('div');
      
      ImgDiv.onclick = function () {this.parentNode.removeChild(this)};
      
      var Img = document.createElement('img');
      ImgDiv.appendChild(TitleDiv);
      ImgDiv.appendChild(Img);
   };
   
   var vp = Page.getViewport();
   
   Img.src = '';
   Img.src = src;
   
   var pomerX = w/(vp.x-4);
   var pomerY = h/(vp.y-4-20);
   
   if (pomerX>1 || pomerY>1) {
      var pomerMax = pomerX > pomerY ? pomerX : pomerY;
      w = Math.round(w/pomerMax);
      h = Math.round(h/pomerMax);
   };
   Img.width = w;
   Img.height = h;
   
   ImgDiv.style.top = ((vp.y/2)-(h/2)-2)+'px';
   Img.style.backgroundColor = 'white';
   
   Img.style.border = '2px solid black';
   
   if (!title) title = '';
   TitleDiv.innerHTML = title;
   
   document.body.appendChild(ImgDiv);
};

Page.getViewport = function () {
   var x,y;
   if (self.innerHeight) {
   	x = self.innerWidth;
   	y = self.innerHeight;
   } else if (document.documentElement && document.documentElement.clientHeight) {
   	x = document.documentElement.clientWidth;
   	y = document.documentElement.clientHeight;
   } else if (document.body) {
   	x = document.body.clientWidth;
   	y = document.body.clientHeight;
   };
   return {'x' : x, 'y' : y};
};
