var Imtech = {};
Imtech.Pager = function() {
    this.paragraphsPerPage = 1;
    this.currentPage = 1;
    this.pagingControlsContainer = "#pagingControls";
    this.pagingContainerPath = "#conteudo_paginas";
    
    this.numPages = function() {
        var numPages = 0;
        if (this.paragraphs != null && this.paragraphsPerPage != null) {
            numPages = Math.ceil(this.paragraphs.length / this.paragraphsPerPage);
        }
        
        return numPages;
    };
    
    this.showPage = function(page) {
        this.currentPage = page;
        var html = "";
        for (var i = (page-1)*this.paragraphsPerPage; i < ((page-1)*this.paragraphsPerPage) + this.paragraphsPerPage; i++) {
            if (i < this.paragraphs.length) {
                var elem = this.paragraphs.get(i);
                html += "<" + elem.tagName + ">" + elem.innerHTML + "</" + elem.tagName + ">";
            }
        }
        
        $(this.pagingContainerPath).html(html);
        
        renderControls(this.pagingControlsContainer, this.currentPage, this.numPages());
		Cufon.replace("h1, h2, h3, h4, h5, h6, span.port_4_title, a.cycle_cta, .sc_button, blockquote, .portfolio_item_4_col span.portfolio_title, a.blog_button, a.tagline_button, .testimonial_quote", {hover: true});
    }
    
    var renderControls = function(container, currentPage, numPages) {
        var pagingControls = "";
		
		var prev = currentPage-1;
		if(prev>=1)
			pagingControls += "<a href='#' onclick='pager.showPage(" + prev + "); return false;' class=\"page nextpostslink\" >&laquo;</a>";
		
        for (var i = 1; i <= numPages; i++) {
			if(numPages!=1){
            if (i != currentPage) {
                pagingControls += "<a href='#' onclick='pager.showPage(" + i + "); return false;' class=\"page\" >" + i + "</a>";
            } else {
                pagingControls += "<span class=\"current\">" + i + "</span>";
            }
			}
        }
        var next = currentPage+1;
		if(next<=numPages)
        	pagingControls += "<a href='#' onclick='pager.showPage(" + next + "); return false;' class=\"page nextpostslink\" >&raquo;</a>";
        
        $(container).html(pagingControls);
    }
}

/*****************************/

var Imtech2 = {};
Imtech2.Pager2 = function() {
    this.paragraphsPerPage = 10;
    this.currentPage = 1;
    this.pagingControlsContainer = "#pagingControls2";
    this.pagingContainerPath = "#conteudo_paginas2";
    
    this.numPages = function() {
        var numPages = 0;
        if (this.paragraphs != null && this.paragraphsPerPage != null) {
            numPages = Math.ceil(this.paragraphs.length / this.paragraphsPerPage);
        }
        
        return numPages;
    };
    
    this.showPage = function(page) {
        this.currentPage = page;
        var html = "";
        for (var i = (page-1)*this.paragraphsPerPage; i < ((page-1)*this.paragraphsPerPage) + this.paragraphsPerPage; i++) {
            if (i < this.paragraphs.length) {
                var elem = this.paragraphs.get(i);
                html += "<" + elem.tagName + ">" + elem.innerHTML + "</" + elem.tagName + ">";
            }
        }
        
        $(this.pagingContainerPath).html(html);
        
        renderControls(this.pagingControlsContainer, this.currentPage, this.numPages());
		Cufon.replace("h1, h2, h3, h4, h5, h6, span.port_4_title, a.cycle_cta, .sc_button, blockquote, .portfolio_item_4_col span.portfolio_title, a.blog_button, a.tagline_button, .testimonial_quote", {hover: true});
    }
    
    var renderControls = function(container, currentPage, numPages) {
        var pagingControls = "";
		
		var prev = currentPage-1;
		if(prev>=1)
			pagingControls += "<a href='#' onclick='pager2.showPage(" + prev + "); return false;' class=\"page nextpostslink\" >&laquo;</a>";
		
        for (var i = 1; i <= numPages; i++) {
			if(numPages!=1){
            if (i != currentPage) {
                pagingControls += "<a href='#' onclick='pager2.showPage(" + i + "); return false;' class=\"page\" >" + i + "</a>";
            } else {
                pagingControls += "<span class=\"current\">" + i + "</span>";
            }
			}
        }
        var next = currentPage+1;
		if(next<=numPages)
        	pagingControls += "<a href='#' onclick='pager2.showPage(" + next + "); return false;' class=\"page nextpostslink\" >&raquo;</a>";
        
        $(container).html(pagingControls);
    }
}
