/* Speciální skripty šablony */
jQuery(document).ready
(
  function($)
  {
    var speed=500;
    
    $("article section.tabs").each
    (
      function()
      {
        $tabs=$(this);
        $tabs.find("header").eq(0).append("<div class=\"tabs\" />");
        $tabs.children("section.tab").each
        (
          function()
          {
            $tab=$(this);
            $tab.find("header h3").eq(0).appendTo($tabs.find("header div.tabs").eq(0));
            $tab.find("header").eq(0).remove();
            if($tab.index()==1)
              $tabs.find("header div.tabs h3").eq(0).addClass("active");
            else
              $tab.hide();
          }
        );
      }
    );
    
    $("article section.tabs header div.tabs h3").bind
    (
      "click",
      function()
      {
        var $tab_heading=$(this);
        $tab_heading.addClass("active");
        $tab_heading.siblings("h3").removeClass("active");
        
        var index=$tab_heading.index();
        $(this).parents("section.tabs").children("section.tab").eq(index).siblings("section.tab").stop(true, true).slideUp(speed);
        $(this).parents("section.tabs").children("section.tab").eq(index).stop(true, true).slideDown
        (
          speed,
          function()
          {
            $("html, body").stop(true, true).animate
            (
              {
                scrollTop: Math.max(0, $tab_heading.parents("section.tabs").offset().top)+"px"
              },
              speed
            );
          }
        );
      }
    );
  }
);
