// JavaScript Document
// image showroom
ShowRoom.index;
ShowRoom.array;
ShowRoom.isAuto;
ShowRoom.obj;
ShowRoom.delay;
ShowRoom.interval;

function ShowRoom(html_image_array, imgParent, auto, auto_delay, this_obj_name) {
 
	this.index = 0;
	this.array = html_image_array;
	this.isAuto = auto;
	this.delay = auto_delay;
	this.obj = this_obj_name;
	var me = this;
	
	this.showImage = function() {
		var parent = document.getElementById(imgParent);
		var old = document.getElementById('temp');
		if(old != null)
			parent.removeChild(old);
		var tmp = document.createElement('DIV');
		tmp.id = 'temp';
		tmp.innerHTML = me.array[me.index];
		
		parent.appendChild(tmp);
	}
	
	this.rotateLeft = function() {
		var max = me.array.length;
		if(me.index - 1 < 0)
			me.index = max - 1;
		else
			me.index = me.index - 1;
		me.showImage();
	}
	
	this.rotateRight = function() {
		var max = me.array.length;
		if(me.index + 1 == max)
			me.index = 0;
		else
			me.index = me.index + 1;
		me.showImage();
	}
	
	this.automatic = function() {
		if(!me.isAuto){
			me.interval = setInterval(me.obj+'.rotateRight()',me.delay);
			me.isAuto = true;
		}
		else {
			clearInterval(me.interval);
			me.isAuto = false;
		}
	}
}

