var PocetDesignu=5;
var aktualni_vzhled=1;
var ulozeno = PrectiVzhledzCookie();
//alert(ulozeno);
if (ulozeno)
    prepnutistylu(ulozeno);
//else
//    UlozVzhleddoCookie(aktualni_vzhled);


function inicializace()
{
  var patka=document.getElementById("patka");
  var i,p;

  var k=document.getElementById("vzhled"); 
  if (k) {
   } 
  else
    {
    var mezera=document.createElement("span");
    if (mezera) {
      mezera.setAttribute("class","s");
      mezera.appendChild(document.createTextNode(String.fromCharCode(160,160,160)));

      var vzhled=document.createElement("a");
      vzhled.setAttribute("href","javascript:prepnutistylu(-1);");
      vzhled.setAttribute("id","vzhled");
      vzhled.appendChild(document.createTextNode("Jinį"+String.fromCharCode(160)+"kamuflį"));

      patka.appendChild(mezera);
      patka.appendChild(vzhled);
    }
  }
  return false;  
}




function prepnutistylu(vybrany_vzhled)
{
  var i,p,pp;

//  alert('vybrano '+vybrany_vzhled);
  if (vybrany_vzhled<0)
     aktualni_vzhled++;
  else
     aktualni_vzhled=vybrany_vzhled;
  if (aktualni_vzhled>PocetDesignu)
     aktualni_vzhled=1;
//  alert('aktualni '+aktualni_vzhled);
  pp = document.getElementsByTagName("link");
  for(i=0;i<pp.length ; i++) {
     if(pp[i].getAttribute("rel").indexOf("style") != -1 && pp[i].getAttribute("title")) {
         pp[i].disabled=true;
//   alert(pp[i].getAttribute("title")+' nastavuji vypnuti  na true, ale ma '+pp[i].disabled);
         if (aktualni_vzhled==i) {
            pp[i].disabled=false;
//  alert(pp[i].getAttribute("title")+' nastavuji vypnuti na false, ale ma '+pp[i].disabled);
         }
     }
  }
  UlozVzhleddoCookie(aktualni_vzhled);
}




function UlozVzhleddoCookie(vzhled)
{
	var konec_platnosti = new Date();
	konec_platnosti.setMonth(konec_platnosti.getMonth() + 1);
	document.cookie = "VzhledHAO=" + escape(vzhled)
		+ '; EXPIRES=' + konec_platnosti.toGMTString()
		+ '; PATH='+'/';
//  alert('V cookies je: '+PrectiVzhledzCookie());
}

function PrectiVzhledzCookie()
{
	var vzhled = null;
	if (document.cookie) {
		var zacatek = document.cookie.indexOf("VzhledHAO=");
		if (zacatek!=-1) {
			var pozice_hodnoty = zacatek + "VzhledHAO=".length;
			var konec = document.cookie.indexOf(';', pozice_hodnoty);
			if (konec!=-1)
			  vzhled = unescape(document.cookie.substring(pozice_hodnoty,konec));
			else
			  vzhled = unescape(document.cookie.substring(pozice_hodnoty));
		}
	}
	return vzhled;
}

