var Imtech = {};
Imtech.Pager = function() {
    this.paragraphsPerPage = 3;
    this.currentPage = 1;
    this.pagingControlsContainer = '#pagingControls';
    this.pagingContainerPath = '#userList';

    this.numPages = function() {
        var numPages = 0;
        if (this.paragraphs != null && this.paragraphsPerPage != null) {
            numPages = Math.ceil(this.paragraphs.length / this.paragraphsPerPage);
        }
        
        return numPages;
    };


		var renderControls = function(container, currentPage, numPages) {
        var pagingControls = '<br class="clear"/><div style="margin-top:-15px;"><ul>';
        for (var i = 1; i <= numPages; i++) {
            if (i != currentPage) {
                pagingControls += '<li><a href="#" style="width:20px;height:20px;border:1px solid #aaa;padding:3px;background-color:#fff;text-decoration:none;" onclick="pager.showPage(' + i + '); return false;">' + i + '</a></li>';
            } else {
                pagingControls += '<li>' + i + '</li>';
            }
        }

        pagingControls += '</ul></div>';

        $(container).html(pagingControls);
    }


    this.showPage = function(page) {
        this.currentPage = page;
        var html = '';

        this.paragraphs.slice((page-1) * this.paragraphsPerPage,
            ((page-1)*this.paragraphsPerPage) + this.paragraphsPerPage).each(function() {
            html += '<div class="aUser">' + $(this).html() + '</div>';
        });

        $(this.pagingContainerPath).html(html);

        renderControls(this.pagingControlsContainer, this.currentPage, this.numPages());
        
        
        // re-initialise the gallery overlay once a page has been clicked - otherwise it wont trigger
        $(function() {
		
					  $('.nyroModal').nyroModal();

					
					});    
        
        

			  
    }


    
}
