$(document).ready(function(){

  //TITLE
  $(document).mousemove(function(e){
      $('#atrtitle').css({ 
        top:e.pageY+10,
        left:e.pageX+10
      });
      
  });
  $('*[title]').mouseover(function(e){
      //alert($(this).attr("title"));
      $('div#foot').after('<div id="atrtitle"></div>');
      var ttext = $(this).attr("title");
      $(this).attr({title:""});
      $('#atrtitle').text(ttext).show().fadeTo(800,0.8);
  });
      $('*[title]').mouseout(function(e){
      $(this).attr({title:$('#atrtitle').text()});
      $('#atrtitle').hide().remove();
  });
  
  //WEATHER
  $('.pocasiPicture').hover(
          function() {
                  $('div.pocasiInfo', this).css('display', 'block');
                  //$(this).addClass("hover");
          },
          function() {
                  $('div.pocasiInfo', this).css('display', 'none');
                  //$(this).removeClass("hover");
          }
  );
  
  //PERSON
  $('.personWrap').hover(
          function() {
                  $('.personPreview', this).css('display', 'block');
          },
          function() {
                  $('.personPreview', this).css('display', 'none');
          }
  );
  
  //COLORBOX
  $('.colorbox').colorbox( {
      transition:"none",
      maxHeight:"95%",
      maxWidth:"95%",
      opacity:0.3,
      previous: "předchozí",
      next: "další",
      current: "Obrázek {current}/{total}",
      onComplete: function(){
          var labels = new Array();
          var initialTags = new Array();
          var alt = $('img', 'a[href="'+($('img#cboxPhoto').attr("src"))+'"]').attr('alt');
          var title = alt.split("|")[0];
          var width = alt.split("|")[1];
          var height = alt.split("|")[2];
          var ratio =  $('img#cboxPhoto').width() * 1.0 / (width * 1.0);
          //alert(ratio);
          var tagsString = alt.split("|")[3];
          var tags = tagsString.split("&");
          for (var i = 0; i < tags.length; i++){
              if (tags[i] == "") continue;
              //alert(tags[i]);
              eval("var params = " + tags[i]);
              params['id'] = i;
              params['width'] *= ratio;
              params['height'] *= ratio;
              params['top'] *= ratio;
              params['left'] *= ratio;
              initialTags.push(params);
              labels.push("<label rel='jTagTag"+i+"'>"+params['label']+"</label>");
          }
          $("#cboxPhoto").tag({
                canDelete: false,
                canTag: false,
                showLabels: true,
                defaultTags: initialTags,
                clickToTag: false
         });

         if (labels.length){
             labels = "<br /><span class='jTagLabels'>(na snínku: "+labels.join(", ")+")</span>";
         } else {
             labels = "<br /><span class='jTagLabels'>&nbsp;</span>";
         }

         $("#cboxTitle").html(title+labels);
         $(".jTagLabels label").live('mouseenter',function(){
                $("#"+$(this).attr('rel')).css('opacity',1); //.find("span").show();
                //$(".jTagDeleteTag").show();
        });

        $(".jTagLabels label").live('mouseleave',function(){
                $("#"+$(this).attr('rel')).css('opacity',0); //.find("span").hide();
                //$(".jTagDeleteTag").hide();

						});
         //$("#cboxTitle").append($(".jTagLabels").html());

        //alert(
        //  "aaa" + $('img#cboxPhoto').attr("src")
        //);
      }
  } );
  $('.colorboxiframe').colorbox( {iframe:true, innerWidth:640, innerHeight:480} );
  
  //OVERLAY
  $('.hoveroverlay').fadeTo(400, 0.4).hover(
          function() {
                  $(this).fadeTo(200, 1.0);
          },
          function() {
                  $(this).fadeTo(200, 0.4);
          }
  );
  $('ul.shortInfo li').hover(
          function() {
                  $(this).css('border-color', '#b0b0b0');
          },
          function() {
                  $(this).css('border-color', '#ccc');
          }
  );
});

$(function() {
        $(".bezspamu").parent().parent().hide();
        $("input.bezspamu").val("bez" + "spamu");
});

function startGallery(){
  //$('#commentFormAdd').trigger('click');  
  $('a[rel="galerie"]:first').trigger('click');
  return false;
}


