var timer;

function showMenu(){
    if ($("#head-text").is(":hidden")) {
        $("#head-text").slideDown("slow");
    }
}

function zmenTypKurzu(id){
window.location.hash="#"+id;
}

function skocNaJazyk(id){
window.location.hash="#"+id;
}

function donthideMenu(){
    clearTimeout(timer);
}

function hideMenu(){
    timer = setTimeout("setHide()",100);
}

function setHide(){
    if ($("#head-text").is(":hidden")) {
    }
    else {
        $("#head-text").slideUp();
    }
}

function zobrazitDiv(id){
	var div=document.getElementById(id);
	var odkaz=document.getElementById('zobraz_'+id);
	div.style.display="block";
	odkaz.style.display="none";
}

function zobrazPobocku(id){

if(id=="hk") {
document.getElementById(id).style.display="block";
 document.getElementById("pce").style.display="none";
}
else if(id=="pce") {
document.getElementById(id).style.display="block";
 document.getElementById("hk").style.display="none";
}
else
{
 document.getElementById("pce").style.display="none";
 document.getElementById("hk").style.display="none";
}
}

function skrytDiv(id){
	var div=document.getElementById(id);
	var odkaz=document.getElementById('zobraz_'+id);
	div.style.display="none";
	odkaz.style.display="inline";
}

function postZapis(id){
//  window.location.href="https://zapis.evcentrum.cz/zapis-kurzu-id-"+id+"/"; 
   var formular = document.createElement("form");
    formular.setAttribute("method", "get");
    formular.setAttribute("action", "https://zapis.evcentrum.cz/");
    var hiddenField = document.createElement("input");
    hiddenField.setAttribute("type", "hidden");
    hiddenField.setAttribute("name", "id-kurzu");
    hiddenField.setAttribute("value", id);
    formular.appendChild(hiddenField);

    document.body.appendChild(formular);    // Not entirely sure if this is necessary
    formular.submit();       
}

var elementlast="flash1";

function showSWFPreview(currSWF,elementId){
    if (elementlast==elementId) {
        return;
    }
    var flashObjStr = "<object type='application/x-shockwave-flash' data='/files/esfcr-minisite/site/flash/flvplayer.swf?file="+currSWF+"' width='500' height='365'><param name='movie' value='/files/esfcr-minisite/site/flash/flvplayer.swf?file="+currSWF+"' /><param name='allowFullScreen' value='true' /></object>";
    document.getElementById("main-video-popisek").innerHTML = $("#"+elementId).find(".menu-video-popisek").html();
    document.getElementById("main-video").innerHTML = flashObjStr;
    $("#"+elementId).hide();
    $("#"+elementlast).show();
    elementlast=elementId;
}


$(document).ready(function(){


    $('#menu-history').find('.menu-history-small img').click(function(){
        $('#menu-image').attr('src',$(this).attr('src').replace("/thumb",""));
        $('#menu-image-popisek').html($(this).attr('rel'));
        return false;
    });

    function showRequest(formData, jqForm, options) { 
        $('#doporucit-form .odesilam').show();
        return true; 
    } 

    function showResponse(responseText, statusText)  { 
        $('#doporucit-form .odesilam').hide();
    } 



    $('.left_stin').find('ul:has(.aktualni)').slideDown(1,function(){
    
        });

    $('.left_stin').find('li.aktualni ul:first').slideDown(1,function(){

        });

    $('.left_stin').find('li:has(ul)').find('img.sipka').click(function(){
        $(this).parent('li').children('ul').slideToggle("slow",function(){

        });
        return false;
    });

    $('#doporucit-link').click(function(){
        $('#doporucit-skryte').slideToggle("slow",function(){

        });
	window.scrollBy(0,60);
        return false;
    });

    $("#footer-hrefs li").hover(function(e){
        $("body").append("<div id='tooltip'>"+ $(this).find("a").attr('rel').replace("\n", "<br />").replace("{b}", "<span class='nadpis'>").replace("{bb}", "</span>") +"</div>");     
        $("#tooltip")
            .css("top",(e.pageY - 10) + "px")
            .css("left",getLeftPos(e) + "px")
            .fadeIn("normal");                        
        $(this).find("img").animate({ width:"110px", height:"90px", marginTop: "-15px", marginLeft: "-15px" }, { queue:false, duration:500 } );
    },
    function(e){  
        $("#tooltip").remove();
        $(this).find("img").animate({ width:"70px", height:"60px", marginTop: "0px", marginLeft: "0px" }, { queue:false, duration:500 }  );
    }); 

    $("#footer-hrefs li").mousemove(function(e){
        $("#tooltip")
            .css("top",(e.pageY - 10) + "px")
            .css("left",getLeftPos(e) + "px");
    });    

    $("#logo").hover(function(e){                       
        $(this).find("img").animate({ width:"230px", height:"110px", marginTop: "0px", marginLeft: "-10px" }, { queue:false, duration:500 } );
    },
    function(e){
        $(this).find("img").animate({ width:"210px", height:"100px", marginTop: "0px", marginLeft: "0px" }, { queue:false, duration:500 }  );
    });      

    $("#menu-history").find(".menu-history-small img").click(function(){
        $("#menu-image").attr("src",$(this).attr("src").replace("/thumb",""));
        $("#menu-image-popisek").html($(this).attr("rel"));
        $("#menu-history").find(".menu-history-small .active").attr("class","");
        $(this).attr("class","active");
        return false;
    });

    $(".menu-kurzy .licha, .menu-kurzy .suda").hover(
      function () {
        $(this).find("td:not(.zvyrazneny-cervene)").css("color","#ff0000");
      }, 
      function () {
        $(this).find("td:not(.zvyrazneny-cervene)").css("color","#000000");
      }
    );

});

function getLeftPos(e){
    if ((e.pageX + 30 + 370)> document.body.clientWidth) 
        return e.pageX - 400;
    else
        return (e.pageX + 30);
}

function zmenStudovnaPozadi(){
	var obj=document.getElementById('odkazStudovna');
	obj.style.background='#8fabcb';
}

function vratStudovnaPozadi(){
	var obj=document.getElementById('odkazStudovna');
	obj.style.background='none';
}

function overitEmail(str){
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str)){
if(window.confirm('Opravdu chcete na e-mailovou adresu ' + str + ' zasílat novinky ?')){
        if (window.ActiveXObject)
        {
          XMLHttpRequestObjekt = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          XMLHttpRequestObjekt = new XMLHttpRequest();
        }
if(XMLHttpRequestObjekt) { 
              XMLHttpRequestObjekt.open("GET", "ulozmail.php?p_odeslano="+document.sendmail.p_odeslano.value+"&p_email="+document.sendmail.p_email.value); 
              XMLHttpRequestObjekt.onreadystatechange = function() 
              { 
                if (XMLHttpRequestObjekt.readyState == 4 && 
                  XMLHttpRequestObjekt.status == 200) { 
                   alert(XMLHttpRequestObjekt.responseText); 
                } 
              } 
              XMLHttpRequestObjekt.send(null); 
            }

}
}
else{
alert("Prosím zadejte platnou emailovou adresu!")
}
}