var UlPaginate = Class.create();

UlPaginate.prototype = {
	initialize : function(pagination_div,panels,ref) {
		this.ref = ref;
		this.pagination_div = $(pagination_div);
		this.panels = panels;
		this.index = 0;
		this.hideall();
		this.show(this.panels[0]);
	},
	hideall: function()
	{
		this.panels.each(function(panel){
								Element.hide($(panel));
							});	
	},
	buildnav: function()
	{
		var nav_prev = "";
		if (this.index == 0){
			nav_prev += "PREV &nbsp;&nbsp;";
		} else {
			nav_prev += "<a href=\"#\" onclick=\"" + this.ref + ".show('" + this.panels[this.index-1] + "')\"; return false;\">PREV</a> &nbsp;&nbsp;";
		}
		var nav_next = "";
		if (this.index >= this.panels.length-1){
			nav_next += "&nbsp;&nbsp; NEXT";
		} else {
			nav_next += "&nbsp;&nbsp; <a href=\"#\" onclick=\"" + this.ref + ".show('" + this.panels[this.index+1] + "')\"; return false;\">NEXT</a>";
		}
		var innerpages = new Array()
		for (var i=0; i<this.panels.length; i++){
			if (i != this.index){
				innerpages.push("<a href=\"#\" onclick=\"" + this.ref + ".show('" + this.panels[i] + "')\"; return false;\">" + (i+1) + "</a>");
			} else {
				innerpages.push(i+1);	
			}
		}
		Element.update(this.pagination_div,nav_prev + innerpages.join(" ") + nav_next);
	},
	show: function(which)
	{
		this.index = this.panels.indexOf(which);
		this.panels.each(function(panel){
								Element.hide($(panel));
							});
		Element.show($(which));
		this.buildnav();
	}
}
