	/*
	
		Paginator Class
		
		# @Author	Maximiliano Canestro
		# @Email	maximiliano.canestro@gameloft.com
		# @Studio	Buenos Aires - Argentina
		# @Date		April 9º 2010
		
		# @Parameters:
			
			1 > object 	: the array object with all results
			2 > start	: initial page
			3 > callback: the function will be called 
			
			Example to use:
			
				var myPager = new pagerFunction(returnData, 1, 'setFriendsList'); --> Constructor with the 3 parameters
				myPager.setByPage(5); --> Amount of results by page (default is 10)
				myPager.setAmount(68); --> Amount of total results
				myPager.setPagerButtons('', 'pagerPrev2', 'pagerNext2'); --> If have pagers buttons, can be declarated here by yours ids
				myPager.init(); --> Initializator method
				
			The only required is: object['resultAmount'] because in a multidimensional array or Json object is not posible know 
			the amount of result need pager
	
	*/
	
	
	function pagerFunction(object, start, callback){
		
		var me 			= this;		
		this.amount 	= parseInt(object['resultAmount']);
		
		this.byPage		= 10;
		this.actual		= (start != 0) ? start : 0;;
		
		this.ini		= 0;
		this.end		= 0;
		
		this.boxPager	= undefined;
		this.btnPrev	= undefined;
		this.btnNext	= undefined;
		
		this.btnPager	= false;
		
		
		
		// Method: Setting results by page
		this.setByPage = function(newByPage){
			this.byPage = newByPage;
		}
		
		// Method: If is needed setting de amount result
		this.setAmount = function(newAmount){
			this.amount = newAmount;
		}
		
		// Method to know the actual page
		this.getActual = function(){
			return this.actual
		}		
		
		// Method: Setting the pager buttons
		this.setPagerButtons = function(pBox, prev, next){
			
			me.boxPager = pBox;
			me.btnPrev = prev;
			me.btnNext = next;
			
			if(this.btnPrev != undefined && this.btnNext != undefined){
				$("#" + me.btnPrev).hide();
				$("#" + me.btnNext).hide();
			
				$('#' + prev).click(function(){
					me.pagerPrev();
				});
				
				$('#' + next).click(function(){
					me.pagerNext();
				});
				me.btnPager = true;
			}
			
			if(this.amount > this.byPage){ $('#' + this.boxPager).show(); }
		}
		
		// Method: initializator 
		this.init = function(){
		
			if(this.amount != 0 && this.amount != undefined){
								
				this.maxPage = Math.ceil( this.amount / this.byPage ) -1;
				
				// Method: internal method for prev page
				this.pagerPrev = function(){
					if(this.actual > 0){
						this.actual--;
						this.setInfo();
					}
				}
				
				// Method: internal method for next page
				this.pagerNext = function(){
					if(this.actual < this.maxPage){
						this.actual++;
						this.setInfo();
					}
				}
				
				// Method: internal method for set the info
				this.setInfo = function(dir){
					
					if(this.actual <= this.maxPage){
						this.ini = this.actual * this.byPage;
					}
					
					this.end = this.ini + this.byPage;
					
					if(this.end > this.amount){
						this.end = this.amount;	
					}
					
					
					if(this.btnPager){
						if(this.actual == 0){
							$("#" + me.btnPrev).hide();
						}else{
							$("#" + me.btnPrev).show();
						}
					
						if(this.amount > this.maxPage && this.actual < this.maxPage){
							$("#" + me.btnNext).show();
						}else{
							$("#" + me.btnNext).hide();
						}
					}
					
					call_user_func(callback, this.ini, this.end, object);
				}
				
				this.setInfo();
				
			}else{
				if(this.amount == undefined){
					alert('Parameter resultAmount is not defined');
				}		
			}
		}		
	}

	