// JavaScript Document
if(WEBSITE_LANG==undefined)
{
	var WEBSITE_LANG = 'en';
}

var Paginator = Class.create({
	initialize: function(container, linkHolderClass){
		var PaginatorLangText = {
			en:{ prev_page:'Prev page', next_page:'Next page', pages:'pages', of:'of' },
			bg:{ prev_page:'Назад', next_page:'Напред', pages:'страници', of:'от' },
			ru:{ prev_page:'Предыдущая', next_page:'Следующая', pages:'страниц', of:'из' }
		}
		if(PaginatorLangText[WEBSITE_LANG] == undefined)
		{
			alert('Paginator.class Error: PaginatorLangText['+WEBSITE_LANG+'] missing!');
		}
		this.textHash = PaginatorLangText[WEBSITE_LANG];
		this.pContainer = container;
		this.pagesCount = Number();
		this.activePage = Number();
		this.pageHolder = [];
		this.linkHolder = false;
		var childs =  this.pContainer.childElements();
		for (var i = 0; i < childs.length; i++ )
		{
			if(childs[i].className == linkHolderClass)
			{
				this.linkHolder = childs[i];
			}
			else
			{
				if(	this.pagesCount != 0 )
					childs[i].hide();
				this.pageHolder.push(childs[i]);
				this.pagesCount++;
			}
		}
		if(this.pagesCount < 2)
		{
			return false;
		}
		this.buildNavigation(1);
	},
	buildNavigation: function(activePage){
		if(!this.linkHolder)
		{
			alert('Paginator.class Error: linkHolder missing!');
			return false;
		}
		var _linkHolder = this.linkHolder;
		$A(_linkHolder.childNodes).each(function(node){_linkHolder.removeChild(node)});
		
		if(activePage != 1)
		{
			var aEL = document.createElement('a');
			aEL.className = 'paginator_p';
			aEL.appendChild(document.createTextNode(this.textHash.prev_page));
			aEL.href="javascript:void(1)";
			aEL.onclick = this.prevPage.bindAsEventListener(this);
			this.linkHolder.appendChild(aEL);
		}
		var spanEl = document.createElement('span');
		
		spanEl.appendChild(document.createTextNode(activePage+' '+this.textHash.of+' '+this.pagesCount+' '+this.textHash.pages));

		this.linkHolder.appendChild(spanEl);
		if(activePage != this.pagesCount)
		{
			var aEL = document.createElement('a');
			aEL.appendChild(document.createTextNode(this.textHash.next_page));
			aEL.className = 'paginator_n';
			aEL.href="javascript:void(1)";
			aEL.onclick = this.nextPage.bindAsEventListener(this);
			this.linkHolder.appendChild(aEL);
		}
		this.activePage = activePage;
	},
	nextPage: function(){
    //new Effect.BlindUp(this.pageHolder[this.activePage-1], {duration:2.0,queue:'start'});
		//new Effect.BlindDown(this.pageHolder[this.activePage], {duration:2.0,queue:'end'});
		this.pageHolder[this.activePage-1].hide();
		this.pageHolder[this.activePage].show();
		this.buildNavigation(this.activePage+1);
	},
	prevPage: function(){
		this.pageHolder[this.activePage-1].hide();
		this.pageHolder[this.activePage-2].show();
    //new Effect.BlindUp(this.pageHolder[this.activePage-1], {duration:2.0, queue:'start'});
		//new Effect.BlindDown(this.pageHolder[this.activePage-2], {duration:2.0, queue:'end'});
		this.buildNavigation(this.activePage-1);
	}
});
