
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;

/*
	////////////
	// let's get ourselves some controls:
	////////////
	var link_arr = [
		{ 	text: '&laquo;', 
			onclick: function() { me.pause(); advance(-1); return false; }, 
			after: '&nbsp;'},
		{ 	text: 'play', 
			onclick: function(){ me.play(); return false; },
			after: '&nbsp;| ' },
		{ 	text: 'pause', 
			onclick: function(){ me.pause(); return false; },
			after: '&nbsp;' },
		{ 	text: '&raquo;', 
			onclick: function() { me.pause(); advance(1); return false; },
			after: '' }
	]
	
	var sc = document.getElementById('show_controls');

	for(i=0;i<link_arr.length;i++) {
	
		var a = document.createElement('a');
		a.innerHTML = link_arr[i].text;
		a.href = '#';
		a.onclick = link_arr[i].onclick;
		sc.appendChild(a);
		var span = document.createElement('span');
		span.innerHTML = link_arr[i].after;
		sc.appendChild(span);
	}

	advance(0);
*/
}

