/**
 * brand.pager
 * @memberOf brand
 */
brand.pager = Class.create( {

	list: [],
	current: 1,
	per_page: 10,

	initializer: function(args) {
		if (!args.list) { return; }
		Object.extend(this, [args]);
		this._init();
	},

	_init: function() {
		this.pages = Math.ceil(this.list.length / this.per_page);
		this.first = 1;
		this.last = this.pages;

		var self = this;
		this.from = (function() {
			return (self.current - 1) * self.per_page;
		})();
		this.to = (function() {
			var tmp = self.from + self.per_page;
			return (tmp <= self.list.length) ? tmp : self.list.length;
		})();

		this.prev = (function() {
			return self.hasPrev() ? self.current - 1 : self.current;
		})();
		this.next = (function() {
			return self.hasNext() ? self.current + 1 : self.current;
		})();
	},
	next: function() {
	    self = this; 
	    return self.hasNext() ? self.current + 1 : self.current;
	},
	previous: function() {
	     self = this;
	     return self.hasPrev() ? self.current - 1 : self.current;
	},
	setPage: function(p) {
		if (p && typeof(p) == "string") {
			p = parseInt(p);
		}
		if (p && p !== this.current) {
			this.current = p;
			this._init();
			return this.getPage();
		}
	},

	getPage: function() {
		return this.list.slice(this.from, this.to);
	},

	hasNext: function() {
		return (this.current < this.pages);
	},

	hasPrev: function() {
		return (this.current > 1);
	}

});

