/*------------ ANKETA -------------------------------------*/
  function hlasuj(id,hlas) {    
    if (window.ActiveXObject) {
      try {
        httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
      }
    }
    else
      {
        httpRequest = new XMLHttpRequest();
    }
    httpRequest.onreadystatechange= function () {zpracovat(id,hlas,httpRequest); } ;
    httpRequest.open("GET", "/hlasovat.php?anketa="+id+"&hlas="+hlas, true);
    httpRequest.send(null);
  }
  
  function zpracovat(id,hlas,httpRequest) {
    if(httpRequest.readyState == 1 || httpRequest.readyState == 2 || httpRequest.readyState == 3) {
      document.getElementById("cekacka").innerHTML="<img src='/img/loader.gif' alt='' />";
    }
    else if (httpRequest.readyState == 4)
    {
      if(httpRequest.status == 200) {
        document.getElementById("pocet"+hlas).innerHTML++;
        document.getElementById("cekacka").innerHTML="<img src='/img/loader.gif' alt='' />";
        
        //znemoznime hlasovani smazanim odkazu
        for (var key in document.getElementById('t-anketa').getElementsByTagName('td')) {
          var val = document.getElementById("t-anketa").getElementsByTagName('td')[key];
          if(val.className=='popis') {
            val.innerHTML = val.firstChild.innerHTML;
          }
        }
        
        //aktualizuji odpovedi
        var odpovedi = httpRequest.responseXML.getElementsByTagName('odpoved');
        var procenta = httpRequest.responseXML.getElementsByTagName('procenta');
        var delka = httpRequest.responseXML.getElementsByTagName('delka');
        for(var i=0; i < odpovedi.length; i++) {
          document.getElementById(odpovedi[i].getAttribute('id')).innerHTML = odpovedi[i].firstChild.data;
        }
        for(var i=0; i < procenta.length; i++) {
          document.getElementById(procenta[i].getAttribute('id')).innerHTML = procenta[i].firstChild.data+"%";
          document.getElementById(delka[i].getAttribute('id')).width=delka[i].firstChild.data;
        }
        document.getElementById("cekacka").innerHTML="";
      }
      else {
        alert("Chyba pri nacitani stanky "+ httpRequest.status);
      }
    }
  }
/*-------------------- VALIDACE FORA-----------------------------------*/

var xhr = vytvorXHR();
var cache = new Array();

function vytvorXHR(){
  var xhr;
  try{
    xhr = new XMLHttpRequest();
  }catch(e){//pro případ starší verze prohlížeče
    var MSXmlVerze = new Array('MSXML2.XML.Http.6.0','MSXML2.XML.Http.5.0','MSXML2.XML.Http.4.0','MSXML2.XML.Http.3.0','MSXML2.XML.Http.2.0','Microsoft.XML.Http');
    for(var i = 0; i < MSXmlVerze.lenght; i ++){
      try{
        xhr = new ActiveXObject(MSXmlVerze[i]);
      }catch(e){
        //vzniklou chybu ignoruji a pokračuji nastavením další verze
      }
    }
  }
  if(!xhr)
    alert("Došlo k chybě při vytváření objektu XMLHttpRequest!");
  else
    return xhr;
}

function vytvorPozadavek(id,hodnota){
if(xhr){
  if(id){
    //zakoduji hodnoty
    id = encodeURIComponent(id);
    hodnota = encodeURIComponent(hodnota);
    //vložím hodnoty do fronty
    cache.push("id="+id+"&hodnota="+hodnota);
  }
  try{
    //pokračovat budu jen v případě že cache není prázdná a objekt
    //XHR nemá co na práci
    if((xhr.readyState == 4 || xhr.readyState == 0)&& cache.length > 0){
      //z cache načtu další hodnotu
      var cacheVstup = cache.shift();
      xhr.open("POST","include/validace.php",true);
      xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      xhr.onreadystatechange = validace;
      xhr.send(cacheVstup);
    }
  }catch(e){
    alert("Nelze se připojik k serveru:\n" + e.toString());
  }
}else{
  alert("Funkce \"precitSoubor()\": chybí objekt XMLHttpRequest");
}
}

function validace(){
  if(xhr.readyState == 4){
    if(xhr.status == 200){
      var XMLRes = xhr.responseXML;
        //zachycení chyb IE a Opery
        if(!XMLRes || !XMLRes.documentElement){
          throw("Chybná struktura XML:\n"+xhr.responseText);
        }
        //chyby firefox
        var rootNodeName = XMLRes.documentElement.nodeName;
        if(rootNodeName == "parsereerror"){
          throw("Chybná struktura XML:\n"+xhr.responseText);
        }
        //čtu dokument, jelikož je vše ok :-)
        xmlRoot = XMLRes.documentElement;
        odpoved = xmlRoot.getElementsByTagName("odpoved")[0].firstChild.data;
        stav = xmlRoot.getElementsByTagName("stav")[0].firstChild.data;
        id = xmlRoot.getElementsByTagName("id")[0].firstChild.data;
        zprava = document.getElementById("err"+id);

        if(odpoved == 0){          
          zprava.innerHTML = stav;
          document.getElementById(id).style.border="1px solid red";
          document.getElementById(id).style.background="#FF7D73";
          
        }else{
          zprava.innerHTML = "";
          document.getElementById(id).style.border="1px solid black";
          document.getElementById(id).style.background="white";
        }
        
        setTimeout("vytvorPozadavek();", 500);
    }else{
      
    }
  }
}

/*-------------------------------------------------------------------------------*/
$(document).ready(function(){
    $("a.group").fancybox({
        'zoomSpeedIn': 300, 
        'padding': 5,
        'zoomSpeedOut': 300, 
        'hideOnContentClick': true,
        'overlayShow': true,
        'overlayOpacity' : 0.7,
        'overlayColor' : "#006cbc"
    }); 
    
    $("#autostart").fancybox({ 
    'zoomSpeedIn': 300, 
    'padding': 0,
    'frameWidth' : 640,
	  'frameHeight' : 480,
    'zoomSpeedOut': 300, 
    'overlayOpacity'	:	0.7,
    'overlayColor' : "#006cbc",
    'hideOnContentClick': false,
    'overlayShow': true
  }).trigger('click');
    
    $(".sekceFoto").hide();
    
    $("#btnFoto").hover(function(){
      $(".tlacitko>span>span").css({"background-color":"#006AB3"});
    });
    
    $("#btnFoto").click(function(){
      $(".sekceFoto").slideDown();
      $("#btnFoto").fadeOut("slow");
    });
    
		$("#zpravy").tabs({event: 'click'}).tabs({fx:{opacity: "toggle"}}).tabs("rotate", 6000, true);
		
		$(".ui-tabs-nav-item>a").each(function(){
      $(this).click(function(){
        window.location = "/2-aktuality/"+$(this).attr("rel");
        
      });
    });
		
			/*$("#zpravy").tabs({
			   event: 'click',
        select: function(event, ui) {
          var url = $.data(ui.tab, 'load.tabs');
          location.href = "/2-aktuality";
            return false;
          if( url ) {
            
          }
          return true;
        }
      }); */
		
		$("#muzib .obsah:gt(0)").hide();
		$("#muzia .obsah:gt(0)").hide();
		$("#mladez .mladez-obsah:gt(0)").hide();
		
		$("#muzib").find("li>a:not(:last)").each(function(){
		  $(this).click(function() {
        if($(this).attr("href")=="#tab-aktualni") {
          $("#muzib").find(".obsah").each(function(){
            $(this).hide();
          });
          $("#muzib #tab-aktualni-b").show();
          $("#muzib li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
        if($(this).attr("href")=="#tab-minuly") {
          $("#muzib").find(".obsah").each(function(){
            $(this).hide();
          });
          $("#muzib #tab-minuly-b").show();
          $("#muzib li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
        if($(this).attr("href")=="#tab-tabulka") {
          $("#muzib").find(".obsah").each(function(){
            $(this).hide();
          });
          $("#muzib #tab-tabulka-b").show();
          $("#muzib li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
      return false;  
      });
    });
    
    $("#muzia").find("li>a:not(:last)").each(function(){
		  $(this).click(function() {
        if($(this).attr("href")=="#tab-aktualni") {
          $("#muzia").find(".obsah").each(function(){
            $(this).hide();
          });
          $("#muzia #tab-aktualni").show();
          $("#muzia li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
        if($(this).attr("href")=="#tab-minuly") {
          $("#muzia").find(".obsah").each(function(){
            $(this).hide();
          });
          $("#muzia #tab-minuly").show();
          $("#muzia li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
        if($(this).attr("href")=="#tab-tabulka") {
          $("#muzia").find(".obsah").each(function(){
            $(this).hide();
          });
          $("#muzia #tab-tabulka").show();
          $("#muzia li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
      return false;  
      });
    });
    
    $("#mladez").find("li>a").each(function(){
		  $(this).click(function() {
        if($(this).attr("href")=="#tab-dorost") {
          $("#mladez").find(".mladez-obsah").each(function(){
            $(this).hide();
          });
          $("#tab-dorost").show();
          $("#mladez").find("li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
        if($(this).attr("href")=="#tab-zaci") {
          $("#mladez").find(".mladez-obsah").each(function(){
            $(this).hide();
          });
          $("#tab-zaci").show();
          $("#mladez").find("li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
        if($(this).attr("href")=="#tab-vysledky") {
          $("#mladez").find(".mladez-obsah").each(function(){
            $(this).hide();
          });
          $("#tab-vysledky").show();
          $("#mladez").find("li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
        if($(this).attr("href")=="#tab-tridy") {
          $("#mladez").find(".mladez-obsah").each(function(){
            $(this).hide();
          });
          $("#tab-tridy").show();
          $("#mladez").find("li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
        if($(this).attr("href")=="#tab-pripravka") {
          $("#mladez").find(".mladez-obsah").each(function(){
            $(this).hide();
          });
          $("#tab-pripravka").show();
          $("#mladez").find("li>a").each(function(){
		        $(this).removeClass("aktivni");
		      });
          $(this).addClass("aktivni");
        }
      return false;  
      });
    });
    
    $("#banner").easySlider({
      controlsShow: false,
      auto: true,
      continuous: true,
      pause: 7000
    });
    
    $("#partneri").easySlider({
      controlsShow: false,
      auto: true,
      continuous: true
    });
    
  });

  


