var imgScroll = null;

Event.observe(window, 'load', imgScrollInit, false);

function imgScrollClass(options){
	this.currImg = 0;
	this.imgSetLength = $$('div#imgBrwsThumbs img').length;
	this.options = (options == null) ? {} : options;
	this.onComplete = this.options.onComplete;
	
	this.goNext = function(){
		if((this.currImg + 1) < this.imgSetLength){
			this.pointA = "img" + this.padDigit(this.currImg) + this.currImg;
			this.pointB = "img" + this.padDigit((this.currImg + 1)) + (this.currImg + 1);
			new Effect.Move('imgBrwsThumbs',{x:this.getRange(this.pointA,this.pointB),y:0, mode:'relative', afterFinish: this.onComplete});
			this.currImg++;
		}
	}
	
	this.goBack = function(){
		if(this.currImg > 0){
			this.pointA = "img" + this.padDigit(this.currImg) + this.currImg;
			this.pointB = "img" + this.padDigit((this.currImg - 1)) + (this.currImg - 1);
			new Effect.Move('imgBrwsThumbs',{x:this.getRange(this.pointA,this.pointB),y:0, mode:'relative', afterFinish: this.onComplete});
			this.currImg--;
		}
	}
	
	this.jumpTo = function(destImgIdx){
		this.pointA = "img" + this.padDigit(this.currImg) + this.currImg;
		this.pointB = "img" + this.padDigit(destImgIdx) + destImgIdx;
		new Effect.Move('imgBrwsThumbs',{x:this.getRange(this.pointA,this.pointB),y:0, mode:'relative', afterFinish: this.onComplete});
		this.currImg = destImgIdx;
	}
	
	this.getCurrImgIdx = function(){
		return this.currImg;
	}
	
	this.getCurrImg = function(){
		this.imgId = "img" + this.padDigit(this.currImg) + this.currImg;
		return $(this.imgId);
	}
	
	this.padDigit = function(refDigit){
		if(refDigit > 9){
			return '';
		}else{
			return 0;
		}
	}
	
	this.getRange = function(a,b){
		return ($(a).offsetLeft - $(b).offsetLeft);
	}
}

function imgScrollInit () {
    imgScroll = new imgScrollClass({ onComplete: initScrollButtons });
    initScrollButtons();
}

