function PaginationDiv(container)
{
    this.container = (typeof container == "string") ? document.getElementById(container) : container;
    this.items = new Array();
    this.pages = new Array();
    this.currentPage = 0;
}

PaginationDiv.prototype.addPage = function()
{
    var page = document.createElement("ul");
    page.setAttribute("class", "page");
    //page.style.height = "5px";
    this.container.appendChild(page);
    this.pages.push(page);
    return page;
}

PaginationDiv.prototype.addItem = function(itemText, itemLink)
{
    var item = document.createElement("li");
    item.innerHTML = '<a href="' + itemLink + '">' + itemText + '</a>';
    this.items.push(item);
    return item;
}

PaginationDiv.prototype.addItemOnClick = function(itemText, itemLink)
{
    var item = document.createElement("li");
    item.innerHTML = '<a href="#" onClick="' + itemLink + '; return false">' + itemText + '</a>';
    this.items.push(item);
    return item;
}

PaginationDiv.prototype.canPlaceItem = function(page, item)
{
	//alert ("container " + this.container.offsetHeight)
    //alert("offsetHeight = " + page.offsetHeight);
    page.appendChild(item);
    var canPlace = (page.offsetHeight <= this.container.offsetHeight-5) ? true : false;
    page.removeChild(item);
    return canPlace;
}

PaginationDiv.prototype.render = function()
{
    var numItems = this.items.length;
    var currentPage = this.addPage();

    for (var i = 0; i < numItems; ++i)
    {
        var currentItem = this.items[i];
        if (!this.canPlaceItem(currentPage, currentItem))
        {
            currentPage.style.display = "none";
            currentPage = this.addPage();
        }
        currentPage.appendChild(currentItem);
    }
    currentPage.style.display = "none";
    this.pages[0].style.display = "block";
}

PaginationDiv.prototype.nextPage = function()
{
    this.pages[this.currentPage].style.display = "none";
    this.currentPage = (this.currentPage < this.pages.length - 1) ? (this.currentPage + 1) : 0;
    this.pages[this.currentPage].style.display = "block";
}

PaginationDiv.prototype.prevPage = function()
{
    this.pages[this.currentPage].style.display = "none";
    this.currentPage = (this.currentPage > 0) ? (this.currentPage - 1) : this.pages.length - 1;
    this.pages[this.currentPage].style.display = "block";
}
