var imgViewer = Class.create();

imgViewer.prototype = {

	imgCount : 1,
	curidx : 1,
	nextHandle : null,
	content : null,
	roll : false,
	interval : 3.5,
	pe : null,
	
	initialize: function(ctrlId, imgCount, roll, nextHandle, previousHandle, interval) {
		this.content = ctrlId;
		this.imgCount = imgCount;
		this.nextHandle = nextHandle;
		
		if (interval) {
			this.interval = interval;
		}
		
		if (nextHandle) {
			Event.observe(nextHandle, 'click', this.onClickNext.bindAsEventListener(this));
		}
		
		if (previousHandle) {
			Event.observe(previousHandle, 'click', this.onClickPrevious.bindAsEventListener(this));
		}
		
		if (roll && roll == true && imgCount > 1) {
			this.roll = true;
			this.pe = new PeriodicalExecuter(this.onClickNext.bindAsEventListener(this), this.interval);
		}
	},
	
	onClickNext: function() {
		if (this.roll)
			this.pe.stop();
			
		Effect.Fade(this.content+this.curidx, {duration: 1.0, afterFinish: this.clickNextPrivate(this), queue: { position: 'end', scope: 'imgscope', limit: 1 }});
	},
	
	onClickPrevious: function() {
		if (this.roll)
			this.pe.stop();
			
		Effect.Fade(this.content+this.curidx, {duration: 1.0, afterFinish: this.clickPreviousPrivate(this), queue: { position: 'end', scope: 'imgscope', limit: 1 }});
	},
	
	clickNextPrivate: function() {
		this.curidx++;
		if (this.curidx > this.imgCount)
			this.curidx = 1;
		
		Effect.Appear(this.content+this.curidx, {duration: 1.0});
		
		if (this.roll)
			this.pe = new PeriodicalExecuter(this.onClickNext.bindAsEventListener(this), this.interval);
	},
	
	clickPreviousPrivate: function() {
		this.curidx--;
		if (this.curidx < 1)
			this.curidx = this.imgCount;
		
		Effect.Appear(this.content+this.curidx, {duration: 1.0});
		
		if (this.roll)
			this.pe = new PeriodicalExecuter(this.onClickNext.bindAsEventListener(this), this.interval);
	}
	
}