$(document).ready(
  function()
  {
    $('.scroll_area').each(
      function ()
      {
        var cur   = parseInt($(this).attr('current_page'));

        $('.scroll_item', $(this)).addClass($(this).attr('class_normal'));

        $('.scroll_item', $(this)).hover(
          function()
          {
            $(this).addClass($(this).parent().attr('class_hover'));
          },
          function()
          {
            $(this).removeClass($(this).parent().attr('class_hover'));
          }
        );

        $('.scroll_item', $(this)).each(
          function(index)
          {
            if (index == cur)
              $(this).addClass($(this).parent().attr('class_selected'));
            $(this).attr('id','s'+index);
            $(this).parent().attr('items_count',index+1);
          }
        );

        var count = parseInt($(this).attr('items_count'));

        if (count > parseInt($(this).attr('visible_count')))
        {
          if (cur >= 4)
          {
            $('#s2',$(this)).text('..');
          }
          if (cur < count - 4)
          {
            $('#s'+(count - 3),$(this)).text('..');
          }

          var min_cur = cur + 1;
          var max_cur = count - 5;

          if (cur < 3)
          {
            min_cur = 4;
          }
          if (cur < max_cur)
          {
            max_cur = count - 3;
          }

          $('.scroll_item', $(this)).each(
            function(index)
            {
              if (
                    (index > 2 && index < cur - 1 && index < max_cur) ||
                    (index > min_cur && index < max_cur)
              )
              {
                $(this).html('');
                $(this).hide();
              }
            }
          );
        }

        var show_speed = $(this).attr('show');
        if (show_speed)
          if (show_speed.length > 0)
            $(this).fadeIn(show_speed);
      }
    );
  }
);




