function animateLi(ul){
    ul.children('li[class!=topInfo]:last').animate({ "opacity": 1 }, 3000,
            function(){ $(this).animate(
                {
                  "opacity": 0
                }, 2500, function()
                    {
                    ul.prepend($(this));
                    ul.children('li:first').css({opacity: 1});
                    animateLi( ul );
                    })
           }
        );
}
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
$(document).ready(function() {
$('body.home table ul').each(
    function(){ if($(this).children('li[class!=topInfo]').length > 1) animateLi( $(this) ); }
);
$.preloadImages("/ha/wp-content/themes/ha/gfx/bg-top.png", "/ha/wp-content/themes/ha/gfx/logo-header-b.png", "/ha/wp-content/themes/ha/gfx/portfolio1.png", "/ha/wp-content/themes/ha/gfx/o-nas1.png", "/ha/wp-content/themes/ha/gfx/kontakt1.png");
//$('a[name*=InsertImage]').facebox()
 $('a.miniImg').click(function(){
  var el = $(this);
  var imgP = el.parents('div.storycontent').children('.mainImg');
  var img = imgP.children('img');
  imgP.height(imgP.height());
  img.fadeOut("slow");
  var img2 = document.createElement('img');
  img2.onload = function(){
   img2.style.display='none';
   imgP.html(img2);
   var img = imgP.children('img');
   //$('html,body').animate({scrollTop: (imgP.offset().top-60)}, 500);
   imgP.animate({"height": img.height()}, 500,
      function(){
       img.addClass('aligncenter size-full');
       img.fadeIn();
       imgP.height("auto");
      } 
    );
  }
  img2.src = el.attr('href');
  return false;
  });
  /*
  $('a.miniImg').attr('rel','g1');
  $('a[rel=g1]').fancybox();
  */
  
  $('#sidebar #klienci li.cat-item:not(.current-cat) a:not(.active_category)').each(function(i){
	  if (i > 5) $(this).addClass('hidden').hide();
  });
  var showHidden = $(document.createElement('a'));
  showHidden.attr('id', 'showHiddenKlienci');
  showHidden.attr('class', 'showHidden');
  showHidden.attr('href', '#');
  $('#sidebar #klienci').after(showHidden)
  $('a#showHiddenKlienci').html('pokaż wszystkich klientów').click(function(){
	  $('#sidebar #klienci li.cat-item a.hidden').removeClass('hidden').fadeIn('slow');
	  $(this).remove();
	  return false;
  });
  
  $("a.imgzoom").fancybox();
});
