function ImageSlider()
{
	this.root = null;
	this.images = new Array();
	this.currentIndex = 0;
}

ImageSlider.prototype.init = function()
{
}

ImageSlider.prototype.addImages = function( images )
{
	for (var i=0; i<images.length; i++) {
		this.images.push(images[i]);
	}
}

ImageSlider.prototype.buildFromHtml = function( rootNode )
{
	this.root = rootNode;
	var refs = this.extractDhtmlRefs(rootNode);
	this.sliderImage = refs.sliderImage;
	this.buttonPrevious = refs.buttonPrevious;
	this.buttonNext = refs.buttonNext;
	this.labelCurrent = refs.labelCurrent;
	this.labelTotal = refs.labelTotal;
	var _this = this;
	
	this.buttonPrevious.onclick = function ( evt ) { 
		_this.showPrevious(); 
	}
	
	this.buttonNext.onclick = function ( evt ) { 
		_this.showNext(); 
	}
}

ImageSlider.prototype.show = function ( index )
{
	this.currentIndex =  Math.max(0, Math.min(this.images.length-1, index));
	this.sliderImage.src = this.images[this.currentIndex];
	this.labelCurrent.innerHTML = (1+this.currentIndex);
	this.labelTotal.innerHTML = this.images.length;
}

ImageSlider.prototype.showFirst = function ()
{
	this.show(0);
}

ImageSlider.prototype.showPrevious = function ()
{
	this.show(this.currentIndex-1);
}

ImageSlider.prototype.showNext = function ()
{
	this.show(this.currentIndex+1);
}

ImageSlider.prototype.showLast = function ()
{
	this.show(this.images.length-1);
}

ImageSlider.prototype.extractDhtmlRefs = function ( htmlNode )
{
	if (!htmlNode || !htmlNode.tagName) return null;
	
	var res = new Object();		
	var aux, node, name;
	for (var i=0; i<htmlNode.childNodes.length; i++) {
		node = htmlNode.childNodes[i];
		if (!node.tagName || !node.attributes) continue;
		name = node.attributes.dhtmlId;
		if (name && name.value) 
			res[name.value] = node;
		aux = this.extractDhtmlRefs(node);
		if (aux) 
			for (var k in aux) {
				res[k] = aux[k];
			}
	}	
	return res;
}
