function hideasap()
{
	$('img').empty();
	$('caption').empty();
}

var slideShow = new Class({
	Implements: [Options, Events],
	options: {
		thumbs: [],
		controlBoxID : 'controls',
		imgBoxID : 'img',
		captionBoxID : 'caption',
		indexBoxID : 'index'
	},

	thumbs: [],
	index : 0,
	imgMorph : $empty,
	prev : $empty,
	next : $empty,
	
	initialize: function(options){
	  this.setOptions(options);
	  
	  // define our morph object
	  this.imgMorph = new Fx.Morph($(this.options.imgBoxID), {});
	  this.captionMorph = new Fx.Morph($(this.options.captionBoxID), {});
	  
	  this.addThumbs(this.options.thumbs);
	  
	  this.buildControls();
	  
	  this.changeImg();
	},


	addThumbs: function(thumbs){
		thumbs.each(function(element){
							this.thumbs.include($(element));
						 }, this);
	},


	addThumb: function(thumb){
		this.addThumbs($splat($(thumb)));
	},

	// behaviour to leave links as numerical listing	
/*	buildControls:function() 
	{
		this.thumbs.each(function(element, i){
				element.addEvent('click', function(e){
						var e = new Event(e).stop();
						this.index = i;
						this.changeImg();
				   }.bind(this));
			}, this);
	}, /* */
	// behaviour to remake controls in format < 1/9 >
	buildControls:function()
	{
		if(this.thumbs.length <= 1)
		{
			var emptyDiv = new Element('div');
			emptyDiv.set('html', '&nbsp;');
			
			$(this.options.controlBoxID).empty();
			$(this.options.controlBoxID).adopt(emptyDiv);
		}
		else
		{
			this.prev = new Element('a', { 'href':'', 'class': 'control' });
			this.prev.set('html', '<');
	
			this.next = new Element('a', {'href':'', 'class': 'control'});
			this.next.set('html', '>');
			
			this.prev.addEvent('click', function(e){
					var e = new Event(e).stop();
					
					if ((this.index - 1) >= 0)
					{
						this.index--;
						this.changeImg();
					}
					
					this.checkControls();
				}.bind(this));
			
			this.next.addEvent('click', function(e){
					var e = new Event(e).stop();
	
					if ((this.index + 1) <  this.thumbs.length)
					{
						this.index++;
						this.changeImg();
					}
					
					this.checkControls();
				}.bind(this));
			
			var indexBox = new Element('span', { id: this.options.indexBoxID });
			var spanBox = new Element('span').set('html', '/'+this.thumbs.length+' ');
			
			
	//		$(this.options.controlBoxID).empty(); // this line messes us up for some reason by adding about:blank to each link in IE
			$(this.options.controlBoxID).setStyles({'top':454,
												   	'width':70,
													'left': 580});
			$(this.options.controlBoxID).getElements('a').setStyles({'opacity' : 0, 'display' : 'none' }); // hide the elements instead of destroying them
			$(this.options.controlBoxID).grab(this.prev);
			$(this.options.controlBoxID).grab(indexBox);
			$(this.options.controlBoxID).grab(spanBox);
			$(this.options.controlBoxID).grab(this.next);
			
			this.checkControls();
		}
	},
	checkControls:function()
	{
		$(this.options.indexBoxID).set('html', ' ' + (this.index +1));
		
		if (this.index == 0)
			this.prev.set('opacity', .2);
		else
			this.prev.set('opacity', 1);
			
		if (this.index == (this.thumbs.length -1))
			this.next.set('opacity', .2);
		else
			this.next.set('opacity', 1);
	},
	changeImg:function()
	{
		if(this.thumbs.length > 0)
		{
			var ahref = this.thumbs[this.index];
	
			var img = new Asset.image(ahref, { 
											 });
			var caption = ahref.get('title');
	
			this.captionMorph.start({'opacity' : 0});
	//		$(this.options.captionBoxID).set('html', caption);
	
			this.imgMorph.start({'opacity' : 0}).chain(function(){
																	$(this.options.imgBoxID).empty();
																	$(this.options.imgBoxID).grab(img);
																	this.imgMorph.start({'opacity' : 1});
																	
																	$(this.options.captionBoxID).set('html', caption);
																	this.captionMorph.start({'opacity' : 1});
																}.bind(this));
		}
	}  
});
