
/**
 * State
 */
function State(cfg) {
	
	this._index = -1;
	this._set = null;
	this._config = cfg;
	
	this.getSet = function() {
		return this._set;
	}
	
	this.setSet = function(set) {
		this._set = set;
	}
	
	this.setIndex = function(index) {
		this._index = index;
	}
	
	this.getIndex = function() {
		return this._index;
	}
	
	///////////////////////////
	
	this.reset = function() {
		this._index = -1;
		this._set = null;
	}
	
	this.numPages = function() {
		if (null != this._set) {
			return Math.ceil(this.numPhotos() / cfg.photosPerPage);
		}
		return -1;
	}
	
	this.numPhotos = function() {
		if( null != this._set ) {
			return parseInt(this._set.total);
		}
		return -1;
	}
	
	this.getPage = function() {
		if( null != this._set ) {
			return parseInt(this._set.page);
		}
		return -1;
	}
	
	this.getNextPhoto = function() {
		return this.getPhoto(this._index + 1);
	}
	
	this.getPrevPhoto = function() {
		return this.getPhoto(this._index - 1);
	}
	
	this.getPhoto = function(index) {
		if(null != this._set && index > -1 && index < this.numPhotos() ) {
			return this._set.photo[index-((this.getPage()-1)*cfg.photosPerPage)];
		}
		return null;
	}
	
	this.getCurrentPhoto = function() {
		return this.getPhoto( this.getIndex() );
	}
	
	this.getMinIndex = function() {
		if( null != this._set ) {
			return (this.getPage()-1)*cfg.photosPerPage;
		}
		return -1;
	}
	
	this.getMaxIndex = function() {
		if( null != this._set ) {
			var minIndex = this.getMinIndex();
			return Math.max(minIndex + cfg.photosPerPage, numPhotos);
		}
		return -1;
	}
}

