	if(typeof Slidey != 'object') {
		Slidey = {}
	}

    if(typeof slides == 'undefined') {
		var slides = [];
	}

    Object.extend(Slidey, {
	    currentSlide : 0,
		userConf : null,
		playInd : null,
		imageId : 'currentImage',
		captionId : 'imageDescription',
		idToScroll : 'galThumbsInner',
		slideDuration: 3,
		loopSlideshow: 0,

		buttonPlay : '../images/play_button.gif',
		buttonStop : '../images/stop_button.gif',

		left : function() {

			t_width =  $('thumb0').getWidth() + 8;
			t_left = $('galThumbsInner').style.left ? parseInt($('galThumbsInner').style.left) : -5;
			
			if(t_left < -5 ) {
				$('scrollRightButton').setOpacity(1);
				new Effect.Move( $('galThumbsInner'), { x: t_width*2, 
														y: 0, 
														mode: 'relative', 
														duration: 0.75,
														afterFinish : function() {
															t_width =  $('thumb0').getWidth() + 8;
															t_left = $('galThumbsInner').style.left ? parseInt($('galThumbsInner').style.left) : -5;
															//console.log('t_left: ' +t_left);
															max_right_pos = (-5 + (slides.length*t_width) - (t_width * 4) ) * -1;
															if(t_left >= -5 ) {
																$('scrollLeftButton').setOpacity(0.3);
															}
														}
													   });
			}

		},
		right : function() {

			t_width =  $('thumb0').getWidth() + 8;
			t_left = $('galThumbsInner').style.left ? parseInt($('galThumbsInner').style.left) : -5;

			max_right_pos = (-5 + (slides.length*t_width) - (t_width * 4) ) * -1;
			
			if(t_left > max_right_pos) {
				$('scrollLeftButton').setOpacity(1);
				new Effect.Move( $('galThumbsInner'), { x: (t_width*-1)*2, 
														y: 0, 
														mode: 'relative', 
														duration: 0.75,
														afterFinish : function() {
															t_width =  $('thumb0').getWidth() + 8;
															t_left = $('galThumbsInner').style.left ? parseInt($('galThumbsInner').style.left) : -5;
															max_right_pos = (-5 + (slides.length*t_width) - (t_width * 4) ) * -1;
															if(t_left <= max_right_pos) {
																$('scrollRightButton').setOpacity(0.3);
															}
														}
													   });
			}
		},
		showImage : function(index) {
			this.loadUserConf();
			this.currentSlide = index;
			
			bleh = window.setTimeout('$(\'loading\').show();',250);
			
			$( this.imageId ).onload = function() {
				window.clearTimeout( bleh );
				$( 'loading' ).hide();
			}
			
			//- Load current slide
			$( this.imageId ).src = slides[ index ]['slideUrl'];
			
			//- Update image caption
			caption = slides[ index ]['slideCaption'] ? slides[ index ]['slideCaption'] : '<em>No Caption</em>';			
			$( this.captionId ).update( caption );
			
			//- Hilight selected thumb
			for(var i=0; i<slides.length; i++) {
				$('thumb' + i).className = 'thumb';
			}			
			$('thumb' + index).className = 'thumb_selected';
		},
		nextSlide : function() {		
			this.loadUserConf();
			index = this.currentSlide + 1;
			if(index >= slides.length) {
				index = 0;
				if(this.playInd && !this.loopSlideshow) {
					this.stopShow()	;
				}
			}		
			this.showImage( index );
		},
		prevSlide : function() {		
			this.loadUserConf();
			index = this.currentSlide - 1;
			if(index < 0 ) {
				index = slides.length - 1;
			}		
			this.showImage( index );
		},
		playShow : function(ctrlObj) {
			this.loadUserConf();
			if($(ctrlObj)) {
				//$(ctrlObj).update('Stop');
				//$(ctrlObj).setStyle({color:'#800000',borderColor:'#800000'});
				$(ctrlObj).src = this.buttonStop;
				$(ctrlObj).alt = '[Stop]';
				$(ctrlObj).title = 'Stop';
				$(ctrlObj).onclick = null;
				$(ctrlObj).stopObserving('click');
				$(ctrlObj).observe('click', function(event) { Slidey.stopShow(this) });
				//$(ctrlObj).onclick = function(event) { galScroll.stopShow(this) }
			}

			this.nextSlide();		
			this.playInd = window.setInterval('Slidey.nextSlide()', this.slideDuration*1000 );
		},
		stopShow : function(ctrlObj) {
			if($(ctrlObj)) {
				//$(ctrlObj).update('Play');
				//$(ctrlObj).setStyle({color:'#008000',borderColor:'#008000'});
				$(ctrlObj).src = this.buttonPlay;
				$(ctrlObj).alt = '[Play]';
				$(ctrlObj).title = 'Play';
				$(ctrlObj).onclick = null;
				$(ctrlObj).stopObserving('click');
				$(ctrlObj).observe('click', function(event) { Slidey.playShow(this) });
				//$(ctrlObj).onclick = function(event) { galScroll.playShow(this) }
			}
			window.clearInterval( this.playInd );
			this.playInd = null;
		},
		userConfLoaded : false,
		loadUserConf : function() {
			if(typeof this.userConf == 'object' && !this.userConfLoaded) {
				//console.log('here');
				Object.extend(this, this.userConf);
			}
			this.userConfLoaded = true;
		},
		outputThumbnails : function() {
			this.loadUserConf();

			$(this.idToScroll).setStyle({width:(slides.length*123)});

			for(var i=0; i < slides.length; i++) {

				out = '<img src="'+slides[i]['slideThumb']+'" '
				    + (i==this.currentSlide ? ' class="thumb_selected" ' : ' class="thumb" ')
					+ 'id="thumb'+i+'" onclick="Slidey.showImage('+i+')" />';

				document.write( out );
			}

			Event.observe( window
				 , 'load'
				 , function(e) {
					 $('scrollLeftButton').setOpacity(0.2);
                     if($('controlButton')) {
                        Slidey.stopShow( $('controlButton') );
                     }
                 });
		}
	});
	
	//if(typeof slideConf == 'object') {
	//	Object.extend(Slidey, slideConf);
	//}