// JavaScript Document

function slideshow(elem_id, img_array, start_img, timeout, offset_time){
	
	//Required vars
	this.img_array = img_array;
	this.elem_id = elem_id;
	
	//Set defaults for optional vars				
	start_img==null ? this.cur_index = 0 : this.cur_index = start_img ;
	timeout==null ? this.timeout = 5000 : this.timeout = timeout ;
	offset_time==null ? this.offset_time = 0 : this.offset_time = offset_time ;
	
	this.curry = function(method){
		var curried = [];
		for (var i = 1; i < arguments.length; i++) {
			curried.push(arguments[i]);
		}
		return function() {
			var args = [];
			for (var i = 0; i < curried.length; i++) {
				args.push(curried[i]);
			}
			for (var i = 0; i < arguments.length; i++) {
				args.push(arguments[i]);
			}
			return method.apply(null, args);
		}
	}
	
	this.start_show = function(){
		document.getElementById(this.elem_id).src = this.img_array[this.cur_index];
		this.next_img();
		curfunc = this.curry(this.chg_img,this);
		t=setTimeout(curfunc,(this.timeout + this.offset_time));
	}

	this.chg_img = function(this_arg){
		document.getElementById(this_arg.elem_id).src = this_arg.img_array[this_arg.cur_index];
		this_arg.next_img();
		curfunc = this_arg.curry(this_arg.chg_img,this_arg);
		t=setTimeout(curfunc,this_arg.timeout);
	}

	this.next_img = function(){
		var i = this.cur_index + 1;
		this.img_array[i] == null ? this.cur_index = 0 : this.cur_index++ ;					
	}
}
