

var iCurrentPage   = 1;
var sPageParameter = getParameter('page');
var bIsFullPage    = ( sPageParameter == "fullpage" ) ? true : false;
var sPagination    = "";
var sPagePath      = window.location.pathname;


if ( sPageParameter != '' ) {
	var iPageParameter = Number(sPageParameter);
	if ( iPageParameter > 0 ) {
		iCurrentPage = iPageParameter;
	}
}
if ( iCurrentPage > iNumberOfPages ) {
	iCurrentPage = iNumberOfPages;
}
var iPreviousPage = iCurrentPage - 1;
var iNextPage     = iCurrentPage + 1;



// Only show pagination if there is actually more than 1 page
if (iNumberOfPages > 0)
{
	sPagination = '<p class="pagination">';
	// Add 'previous' link:
	if ( iCurrentPage > 1 ) {
                sPagination += '<a href="' + sPagePath + '?page=1#entries" rel="nofollow" title="" class="next-prev">&laquo; First</a>&nbsp;';
                sPagination += '<a href="' + sPagePath + '?page=' + iPreviousPage + '#entries" rel="nofollow" title="" class="next-prev">&lsaquo; Previous</a>';

	} else {
		sPagination += '<span class="next-prev">&laquo; First</span>&nbsp; ';
                sPagination += '<span class="next-prev">&lsaquo; Previous</span> ';
	}

	// Add page links:
	var startInx = Math.floor((iCurrentPage/6));
	if(iCurrentPage <= 5)
		startInx = 1;
	else
        	startInx = (startInx * 6);
	// for ( var i=startInx; i<=iNumberOfPages; i++ ) {
	for ( var i=startInx; i<=((iNumberOfPages < (startInx+5) ) ? iNumberOfPages : (startInx+5)); i++ ) {

		if ( iCurrentPage == i ) {
			sPagination += ' <strong>'+i+'</strong>';
		} else {
			sPagination += ' <a href="' + sPagePath + '?page=' + i + '#entries" rel="nofollow">'+i+'</a>';
		}
	}

	// Add 'next' link:
	if ( iCurrentPage < iNumberOfPages ) {
		sPagination += ' <a href="' + sPagePath + '?page=' + iNextPage + '#entries" title="" class="next-prev">Next &rsaquo;</a>';
                sPagination += '&nbsp;<a href="' + sPagePath + '?page=' + iNumberOfPages + '#entries" title="" class="next-prev">Last &raquo;</a>';
	} else {

		sPagination += ' <span class="next-prev">Next &rsaquo;</span>';
                sPagination += '&nbsp;<span class="next-prev">Last &raquo;</span>';
	}
	sPagination += '</p>';
}



function getParameter(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return '';
}

function content_swap(currpage, totalpages) {
	for (var i=1; i<=totalpages; i++) {
		if(currpage == i) {
			var telement = document.getElementById("contentSwap"+i);
            if(telement) {
               	telement.style.display = "";
            }
        } else {
			var telement = document.getElementById("contentSwap"+i);
            if(telement) {
               	telement.style.display = "none";
            }
        } // if
	} // for
}
