/*
 *  Minis Gallery
 *  Copy 2007 Andy | 3cky, s.r.o.
 *
 */

var Gallery = function( total, itemsPerPage, itemPrefix )
{
	this.total = total;
	this.itemsPerPage = itemsPerPage;
	this.startPage = 1;
	this.itemPrefix = itemPrefix;
	
	this.totalPages = Math.ceil( this.total / this.itemsPerPage );
	this.actualPage = 1;
	this.prevPage = 1;
}

Gallery.prototype.displayActual = function ()
{
		this.handlePage(this.prevPage, 'none');
		this.handlePage(this.actualPage, 'block');
		this.prevPage = this.actualPage;
		if (this.totalPages > 1 )
		{
			document.getElementById('galleryControler').style.display = 'block';
			document.getElementById('galleryPage').innerHTML = this.actualPage;
			document.getElementById('galleryTotal').innerHTML = this.totalPages;
		}
}

Gallery.prototype.handlePage = function ( page, display )
{
		endItem = page * this.itemsPerPage;
		if (endItem > this.total)
			endItem = this.total;
			
		for (index = (((page-1) * this.itemsPerPage) + 1 ) ;
			 index <= endItem ;
			 index++
			 )
		{
			document.getElementById(this.itemPrefix + index).style.display = display;
		}
}

Gallery.prototype.next = function ()
{
	if (this.actualPage  < this.totalPages)
	{
		this.actualPage++;
		this.displayActual();
	}
}

Gallery.prototype.end = function ()
{
	if (this.actualPage  != this.totalPages)
	{
		this.actualPage = this.totalPages;
		this.displayActual();
	}
}

Gallery.prototype.prev = function ()
{
	if (this.actualPage > 1)
	{
		this.actualPage--;
		this.displayActual();
	}
}

Gallery.prototype.begin = function ()
{
	if (this.actualPage > 1)
	{
		this.actualPage = 1;
		this.displayActual();
	}
}