var PaginatorClassesLoaded = Array();

function PaginatorHandleEvent(Element)
{
	ClassName = Element.parentNode.id;
	LoadedClass = false;
	for (var key in PaginatorClassesLoaded) {
		if (key == ClassName) {
			LoadedClass = ClassName;
			break;
		}
	}
	if (!LoadedClass) {
		PaginatorClassesLoaded[ClassName] = new Paginator(ClassName,0);
		LoadedClass = ClassName;
	}
	if (Element.name == "nextPage")
		PaginatorClassesLoaded[LoadedClass].showNext(Element,1);
	else
		PaginatorClassesLoaded[LoadedClass].showNext(Element,0);
}

var Paginator = function(paginator_id, loop) {
	this.potentialPages = document.getElementById(paginator_id).childNodes;
	potPageIndex = 0;
	this.pages = new Array();
	for (i=0;i<this.potentialPages.length;i++)
	{
		if (this.potentialPages[i].nodeName=='DIV')
		{
			this.pages[this.pages.length] = this.potentialPages[i];
		}
	}

	this.next = true;
	this.prev = false;
	this.index = 0;
	this.setVisibility = function(b){this.pages[this.index].style.display = (b)?'block':'none'; }
	this.nextIndex = function(b) {
		var old_index = this.index;
		this.index = this.index + ((b)?1:(-1));
		if (this.index == this.pages.length)
			if(loop)
				this.index = 0;
			else
				this.index = old_index;
		if (this.index < 0)
			if(loop)
				this.index = this.pages.length-1;
			else
				this.index = old_index;
	}

	this.showButtons = function(element) {
		var nextImage = document.getElementById("arrow_down");
		var prevImage = document.getElementById("arrow_up");

		if(this.index == 0){
		 	var butUp = new Image();
  			butUp.src = '/templates/images/arrow_up_lightgray.gif';
			prevImage.src = butUp.src;
		} else {
			var butUp = new Image();
  			butUp.src = '/templates/images/arrow_up_white.gif';
			prevImage.src = butUp.src;
		}

		if(this.index == (this.pages.length-1)){
		 	var butDown = new Image();
  			butDown.src = '/templates/images/arrow_down_lightgray.gif';
			nextImage.src = butDown.src;
		} else {
			var butDown = new Image();
  			butDown.src = '/templates/images/arrow_down_white.gif';
			nextImage.src = butDown.src;
		}
	};
	this.showNext = function(element, b) {
		this.setVisibility(0);
		this.nextIndex(b);
		this.setVisibility(1);
		this.showButtons(element); }
}