// JavaScript Document By Angel Adrian Retali.



/* -------------------- Start class -------------------- */

function PaginatorManager(args)
{	
	// Vars	      		
	this.window_size = args[1];
	
	this.class_name = args[2];
	
	this.index = 0;
	
	this.tags = new Array()
		
		NAME = args[0];
		
		foo = document.getElementsByTagName("div");
	
		n = foo.length;
	
		tags = new Array();
		
		for (i = 0, j = 0; i < n; i++) 
		{	
			if(foo.item(i).getAttribute('name') == NAME) { tags[j] = foo.item(i); j++; } 
		}
				        
	this.back = tags[0];
	
	this.next = tags[j -1];
			
		for (i = 1, k = 0; i < j -1; i++, k++) this.tags[k] = tags[i];
		
	this.n = k;
		
	this.min = 0;
	
	if(this.window_size > this.n) 
	{
		this.window_size = this.n;
		
		this.max = this.n -1;
	}
	
	else this.max = this.window_size -1;
		
	// Methods
	this.goBack = function ()
	{	
		this.index--;
		
		if(this.index < 0) this.index = 0; 
				
		foo = this.tags[this.index].getAttribute('onClick');
		
		try { foo (); }
 		
		catch(err) { foo = foo.replace(' ',''); eval(foo); }
	}

	this.goNext = function ()
	{
		this.index++;
		
		if(this.index > this.n -1) this.index = this.n -1;
		
		foo = this.tags[this.index].getAttribute('onClick');
		
		try { foo (); }
				
		catch(err) { foo = foo.replace(' ',''); eval(foo); }		
	}

	this.goTo = function (index)
	{	
		if(this.n == 1) return;
				
		this.index = index; 
		
		if(this.index < 0) this.index = 0;
		
		if(this.index > this.n -1) this.index = this.n -1;
		 
		if(this.index == this.min)
		{          
			if(this.min != 0)
			{
				this.min = (this.min % (this.window_size -1)) + this.min;
					
				this.max = this.min;
					
				this.min = this.max - (this.window_size -1);
			}
		}
			
		else if(this.index == this.max)
		{  
			if(this.max + (this.window_size -1) < this.n -1) this.min = this.max; 
				
			else this.min = this.n - this.window_size; 
					
			this.max = this.min + (this.window_size -1);
		}
			
		if(this.min < 0)
		{
			this.min = 0;
							
			this.max = this.window_size -1; 						
		}
			
		for (i = 0; i < this.n; i++) 
		{	
			this.tags[i].style.display = 'none';
				
			this.tags[i].className = '';
		
			this.tags[i].innerHTML = i +1;
		}	
		
		for (i = this.min; i < this.max +1; i++) 
		{	
			this.tags[i].style.display = 'inline';
			
			if(i < this.max) this.tags[i].innerHTML = this.tags[i].innerHTML+'-';
		}
		
		this.tags[this.index].className = this.class_name;			
		
		if(this.index == 0) this.back.style.visibility = 'hidden';
		
		else  this.back.style.visibility = 'visible';
		
		if(this.index == this.n -1) this.next.style.visibility = 'hidden';
		
		else this.next.style.visibility = 'visible';		
	}
}

/* -------------------- End class -------------------- */




