// google analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-136721-21']);
_gaq.push(['_trackPageview']);
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

// popis u obrazku
$(document).ready(function(){
  $("img.right").hover(function(){
    if($(this).attr("title")=="")$(this).attr("title",$(this).attr("alt"));
  });
});

// vystoupeni
$(document).ready(function(){
  $("table.vystoupeni tr").hover(
    function(){$(this).css("background","#f5f5f5");},
    function(){$(this).css("background","transparent");}
  );
});

// fotogalerie
$(document).ready(function(){
  $(".nahled").click(function(){
    $(".nahled").css("borderColor","#555");
    $(this).css("borderColor","#777");
    if($(this).attr("src").substr($(this).attr("src").length-5)=="s.jpg")
      $("img.foto-large").attr({src:$(this).attr("src").replace("s","b"),title:$(this).attr("title")});
    var pozice = parseInt($(".gal-det").css("left"),10) + parseInt($(".gal-con").offset().left,10)
      - parseInt($(this).offset().left,10) - parseInt($(this).width()/2,10) + parseInt($(".gal-con").width()/2,10);
    $(".gal-det").animate({left:pozice},350);
  });
  setTimeout('$(".nahled:first").click();',100);
});

// diskografie - nahledy alb
var album_foto_id = -1;
$(document).ready(function(){
  if ($("ul.alba span.true").length > 0) {
    var i = Math.floor(Math.random() * $("ul.alba span.true").length);
    album_foto_id = $("ul.alba span.true:eq(" + i + ")").attr("id").replace("album-foto-","");
    album_foto(album_foto_id, "show");
  }
  $("ul.alba span.true, ul.alba span.false").hover(
    function(){
      var i = $(this).attr("id").replace("album-foto-","");
      if (i.search(/^[0-9]{1,}$/) != -1){
        album_foto_id = i;
        var foto_exists = $(this).attr("class");
        if (foto_exists == "true") setTimeout('album_foto(' + i + ',"show");', 300);
        if (foto_exists == "false") setTimeout('album_foto(' + i + ',"hide");', 300);
      }
    },
    function(){
      album_foto_id = -1;
    }
  );
});
function album_foto(i, action) {
  if (i < 1 || album_foto_id != i)
    return;
  if (action == "show") {
    if ($("#album-foto").attr("src") == "foto/album/" + i + ".jpg" && $("#album-foto").css("display") != "none")
      return;
    /*
    $("<img>").attr("src", "foto/album/" + i + ".jpg").load(function(){
      if (album_foto_id != i)
        return;
      $("#album-foto").fadeOut(100);
      setTimeout('$("#album-foto").attr("src","foto/album/' + i + '.jpg");', 100);
      setTimeout('$("#album-foto").fadeIn(100);', 100);
    });
    */
    var image = document.createElement('img');
    image.onload = function(){
      if (album_foto_id != i)
        return;
      $("#album-foto").fadeOut(100);
      setTimeout('$("#album-foto").attr("src","foto/album/' + i + '.jpg");', 100);
      setTimeout('$("#album-foto").fadeIn(100);', 100);
    };
    image.src = "foto/album/" + i + ".jpg";
  }
  if (action == "hide") {
    $("#album-foto").fadeOut(100);
  }
}

// ukazky z alba
$(document).ready(function(){
  $("#play div.container").css("margin","5px 10px").css("padding-bottom","0.5em");
  $("#play div.title").css("margin","8px 0 3px 0").css("font-size","0.85em").css("font-weight","bold").css("text-align","center");
  $("#play span.mp3").css("position","relative").css("top","5px").css("margin","0 30px 0 10px");
  $("#play").css("margin","1em 2em").css("width","320px").css("background","#eee").css("border","1px solid #ccc");
  $("#play").css("display","block");
  $(".mp3").jmp3();
});

