
var Slides = function(options) {

	var _i = document.getElementById('show_target');
	var _c = document.getElementById('show_caption');
	var _delay = options.interval * 1000;
	var _min = options.first || 1;
	var _max = options.last;
	var _captions = options.captions;
	var _index = 0;
	var _to = null;
	var _stopped = true;
	
	var _show = function() {
		_i.src = 'images/' + _index + '.jpg';
		//_c.innerHTML = '' + _index + '/' + _max + '' + ': ' + _captions[_index-1];
		_c.innerHTML = _captions[_index-1];
		
		
		// hack: set 'active' as classname of active link:
		if(ctl = document.getElementById('controls')) {
			if((as = ctl.getElementsByTagName('a')).length ) {
				for(var i=0;i<as.length;i++) as[i].className='';
				as[_index-1].className='active';
			}
		}
		// /hack
		
	}
	
	var _advance = function(step) {
		if(step == null) step = 1;
		_index+=step;
	
		if(_index > _max) _index = _min;
		if(_index < _min) _index = _max;

		_show();

		if(!_stopped) _to = window.setTimeout(_advance, _delay, 1);
	}

	this.pause = function() {
		if(!_stopped) {	
			window.clearTimeout(_to);
			_to = null;
			_stopped = true;
		}
	}
	
	this.play = function() {
		_stopped = false;
		_advance(1);
	}
	
	this.goto = function(index) {
		this.pause();
		_index = index;
		_show();	
	}
	
	this.advance = _advance;

}

