// -----------------------------------------------------------------------------------

//
//	WorkGallery Class Declaration
//
//	Structuring of code inspired by Scott Upton (http://www.uptonic.com/)
//
var Slideshow = Class.create();

Slideshow.prototype = 
{
	// Initialize class
	initialize : function(base_path, image_path, items)
	{
		this.image_path = base_path+image_path;
		this.preloader = 'preloader';
		this.container = 'slideshow';
		this.duration = '0.6';
		this.image = 'slideshow_photo';
		this.spacer = base_path+"/img/spacer.gif";
		this.items = items;
		this.total = items.length-1;
		this.frame = 0;
		this.hold = false;
		this.timeout = 3000;
		this.timer = null;
		this.buttons = new Array();
		this.buttons['prev'] = "showreel-nav-prev";
		this.buttons['next'] = "showreel-nav-next";
		this.buttons['stop'] = "showreel-nav-stop";
		this.buttons['play'] = "showreel-nav-play";
	},
	
	start : function()
	{	
		this.change_image(this.frame);
	},
	
	change_image : function(key) 
	{	
		this.frame = key;
		Element.show(this.preloader);
		Element.hide(this.container);
		Element.setSrc(this.image, this.spacer);
		loader = new Image();
		loader.onload = function()
		{
			Element.setSrc(myShow.image, myShow.image_path+myShow.items[key]);
			myShow.show();
		};
		loader.src = this.image_path+this.items[key];
	},
	
	show : function()
	{
		Element.hide(this.preloader);
		new Effect.Appear(this.container, { duration: this.duration, queue: 'end' });
		if(!this.hold)
		{
			if (this.frame == this.total) { next_frame = 0; } else { next_frame = this.frame+1; }
			this.timer = setTimeout("myShow.change_image("+next_frame+");", this.timeout);
		}
	},
	
	pause : function()
	{
		this.hold = true;
		clearTimeout(this.timer);
		Element.hide(this.buttons['stop']);
		Element.removeClassName(this.buttons['next'], 'off');
		Element.removeClassName(this.buttons['prev'], 'off');
	},
	
	play : function()
	{
		this.hold = false;
		if (this.frame == this.total) { next_frame = 0; } else { next_frame = this.frame+1; }
		this.change_image(next_frame);
		Element.show(this.buttons['stop']);
		Element.addClassName(this.buttons['next'], 'off');
		Element.addClassName(this.buttons['prev'], 'off');
	},
	
	prev : function()
	{
		if(this.hold)
		{
			if (this.frame == 0) { prev_frame = this.total; } else { prev_frame = this.frame-1; }
			this.change_image(prev_frame);
		}
	},
	
	next : function()
	{
		if(this.hold)
		{
			if (this.frame == this.total) { next_frame = 0; } else { next_frame = this.frame+1; }
			this.change_image(next_frame);
		}
	}
}