/**
 * Javascriptove funkce
 */

$(document).ready(function(){

    // fix na # anchory v textu stran BASE HREF
    $("a[href^='\#']").click(function(e){
      e.preventDefault();
      document.location.hash=this.href.substr(this.href.indexOf('#')+1);
    })
    
    // antispamové dobrůtky
    $("#protirobotum").val(Math.round(5.8));
    $("#spamprotirobotum").css({'display' : 'none'});
        
    // PNG fix pro IE
    $(document).pngFix();
    
    // vybernik fotogalerie
    $("#photogallery_select").
        change(function () {
           location.href = serverUrl + $(this).val();
        });
        
    // jsem zde poprve
    $("#jsem_zde_poprve_button").
        click(function () {
            $(document).unbind("click");

            $("#jsem_zde_poprve_bg")
                .css({
                    'width'   : $(document).width(),
                    'height'  : $(document).height(),
                    'top'     : 0,
                    'left'    : 0,
                    'opacity' : 0.5,
                    'display' : 'none'
                })
               .fadeIn(500);

            $("#jsem_zde_poprve_popup")
                .css({
                    'left' : (($(document).width() - $("#jsem_zde_poprve_popup").width()) / 2)
                })
                .fadeIn(
                    500,
                    function () {
                        $(document)
                            .bind(
                                "click",
                                function(){
                                    $("#jsem_zde_poprve_popup")
                                        .fadeOut(500);

                                    $("#jsem_zde_poprve_bg")
                                        .fadeOut(500);
                                }
                            );
                    }
                );

        });


    // karusel
    $("#carousel")
        .carousel();
        
    // blikačka Tickets For People
    tfprepeat();   
    
    // kliknutí na vystoupení v harmonogramu uloží anebo smaže cookie
    // závislé na pluginu jQuery Cookie
    $("li[id^='vystoupeni_']").click(function(){
      
      if ($.cookie(this.id)==1)
        {$.cookie(this.id,null); $(this).removeClass('vybrane_vystoupeni');}
      else{$.cookie(this.id,"1",{ expires: 360 }); $(this).addClass('vybrane_vystoupeni');}
      //return false;   
    })
    $("li[id^='vystoupeni_'] a").click(function(event){
      event.stopPropagation();    
    });      
    
    // fotogalerie

    $(".colorbox").colorbox({
      slideshow: true,
      slideshowSpeed	: 4000,
      slideshowAuto : false,
      next: 'Další',
      previous: 'Předchozí',
      close : 'Zavřít',
      slideshowStart : 'Přehrávat',
      slideshowStop : 'Nepřehrávat',
      current : '{current} z {total}',
      loop : true      
     });


    
});




// nastavuje  vysku stranek na maximalni velikost
function nastav_velikost() {
    
    mujdiv = document.getElementById('mainleft');

    if(document.defaultView) { //MOZ
        vyskadivu = window.document.defaultView.getComputedStyle(mujdiv,null).getPropertyValue('height');
    }
    if(mujdiv.currentStyle) { // IE
        vyskadivu = eval("mujdiv.currentStyle.height")+150;
    }
    vyska = document.documentElement.clientHeight-75;
    if (vyskadivu.substring(0, vyskadivu.length - 2) < vyska || vyskadivu.substring(0, vyskadivu.length) == "auto"){
        document.getElementById('mainleft').style.height = vyska + 'px';
    }
    
}

// kontrola formulare
function kontrola_formulare(formular, typ) {
    nevyplneno_vse = 0;
    prvni = "";
    if (typ == "prispevek") {
        text = "Příspěvek nemůže být vložen, protože nebyla vyplněna tato pole:\n";
    }

    for (var i = 2; i < kontrola_formulare.arguments.length; i++) {
        prvek = kontrola_formulare.arguments[i];
        i++;
        jmeno = kontrola_formulare.arguments[i];

        if (document.forms[formular].elements[prvek].value == "") {
            nevyplneno_vse = 1;
            if (prvni == "") {
              prvni = prvek;
            }
            text += jmeno+"\n";
        }
    }

    if (nevyplneno_vse) {
        alert(text);
        document.forms[formular].elements[prvni].focus();
        return false;
    }

    return true;
}

// filtrovani fora
function filtruj_forum(url) {
    location.href = url + (($("#forum_typ").val() > 0) ? '?typ=' + $("#forum_typ").val() : '');
}

// TFP změny

   function tfprepeat(){
     $("#tfp1").delay(6000).fadeOut("slow",function(){
      $("#tfp2").fadeIn("slow").delay(6000).fadeOut("slow",function(){
        $("#tfp1").fadeIn("slow");
        tfprepeat(); 
        });
      });     
     };
