//~OPTIONS
{
  clientRendering:  true,
  lockTemplate:     false,
  autoUpdate:       true,
}

//~ARGUMENTS
{
    page:             1,
    pageCount:        10,
    outputPageCount:  5,
    urlParamenter:    fcf.argProg(),
    showOne:          true,
}

//~TEMPLATE
%{{
  var pageCount         = fcf.range(args.pageCount, 0);
  var outputPageCount   = fcf.range(args.outputPageCount, 0, pageCount);
  var page              = fcf.range(args.page, 1, pageCount);
  var startPage         = page <= Math.floor(outputPageCount / 2)              ? 1 :
                          page > (pageCount - Math.floor(outputPageCount / 2)) ? pageCount - outputPageCount + 1 :
                                                                                 page - Math.floor(outputPageCount / 2);
  if (args.showOne || pageCount > 1) {
}}%
  <div class="${{decor.paginationClass}}$">
%{{
    if (startPage != 1) {
      var r = fcf.append({}, route);
      r.urlArgs = fcf.cloneArgs(route.urlArgs, true, false);
      var switchPage = fcf.range(page - outputPageCount-1, 1, pageCount);
      if (!fcf.empty(args.urlParamenter))
        r.urlArgs[args.urlParamenter] = switchPage;
      var link = fcf.link(r);
}}%
      <div class="${{decor.paginationItem}}$">
        <a class="${{decor.paginationLink}}$" value="@{{switchPage}}@" fcfEventClick="wrapper.onClick(event)" href="@{{link}}@">&laquo;</a>
      </div>
      %{{
        }
        for(var i = 0; i < outputPageCount; ++i) {
          var n           = startPage + i;
          var activeClass = n == page ? "active" : "";
          var r = fcf.append({}, route);
          r.urlArgs = fcf.cloneArgs(route.urlArgs, true, false);
          if (!fcf.empty(args.urlParamenter))
            r.urlArgs[args.urlParamenter] = n;
          var link = fcf.link(r);
      }}%
        <div class="${{decor.paginationItem}}$  @{{activeClass}}@">
          <span class="${{decor.paginationLink}}$ @{{activeClass}}@"  fcfEventClick="wrapper.onClick(event)" value="@{{n}}@" href="@{{link}}@">@{{n}}@</span>
        </div>
      %{{
        }

        if (startPage + outputPageCount <= pageCount) {
          var r = fcf.append({}, route);
          r.urlArgs = fcf.cloneArgs(route.urlArgs, true, false);
          var switchPage = fcf.range(page + outputPageCount+1, 1, pageCount);
          if (!fcf.empty(args.urlParamenter))
            r.urlArgs[args.urlParamenter] = switchPage;
          var link = fcf.link(r);
      }}%
      <div class="${{decor.paginationItem}}$">
        <a class="${{decor.paginationLink}}$"  value="@{{switchPage}}@" fcfEventClick="wrapper.onClick(event)"  href="@{{link}}@">&raquo;</a>
      </div>

    %{{
      }
    }}%
  </div>
%{{ } }}%
