$(function(){
  // fancybox
  if ( ! $("body.homepage").length) {
    $("a.fancybox").fancybox({
      'zoomSpeedIn': 300,
      'zoomSpeedOut': 300,
      'overlayShow' :true
    });
  }

   $(document).keydown(function(e) {
      var url = false;
         if (e.which == 37 || e.which == 38) {  // Left and top arrow key code
            var prevUrl = $('#portfolio_button a.prev').attr('href');
            if (prevUrl !== "#") {
               var url = prevUrl;
            }
         }
         else if (e.which == 39 || e.which == 40) {  // Right and bottom arrow key code
            var nextUrl = $('#portfolio_button a.next').attr('href');
            if (nextUrl !== "#") {
               var url = nextUrl;
            }         }
         if (url) {
            window.location = url;
         }
   });

  // menu
  $("#level1 li.level1").hover(
    function () {
      $(this).addClass("hover");
    },

    function () {
      $(this).removeClass("hover");
    }
  );
  
  // more less
  $('.short').truncate({max_length: 200});
  
  // show hide
  $('#tech div.detail').hide();
  $('#tech div.introduction a.show').click(function() {
    $('#tech div.detail').toggle(400);
    $(this).toggleClass("hide");
    $(this).text($(this).text() == 'zobrazit detaily' ? 'skrýt detaily' : 'zobrazit detaily');
    return false;
  });

  $('#tech div.detail a.hide').click(function() {
    $('#tech div.detail').hide(400);
    $('#tech div.introduction a.show').removeClass("hide");
    $('#tech div.introduction a.show').addClass("show");
    $('#tech div.introduction a.show').text('zobrazit detaily');
    return false;
  });
  
  // opacity
  $('#portfolio_list div.box1 div').css('opacity', 0);
  $('#portfolio_list div.box2 div').css('opacity', 0);
  $('#portfolio_list div.box3 div').css('opacity', 0);

  $('#portfolio_list div.box1 div').each(function() {
    $(this).hover(function() {
      $(this).stop().animate({ opacity: 1.0 }, 500);
    },
    function() {
      $(this).stop().animate({ opacity: 0 }, 500);
    });
  });

  $('#portfolio_list div.box2 div').each(function() {
    $(this).hover(function() {
      $(this).stop().animate({ opacity: 1.0 }, 500);
    },
    function() {
      $(this).stop().animate({ opacity: 0 }, 500);
    });
  });

  $('#portfolio_list div.box3 div').each(function() {
    $(this).hover(function() {
      $(this).stop().animate({ opacity: 1.0 }, 500);
    },
    function() {
      $(this).stop().animate({ opacity: 0 }, 500);
    });
  });

});

