	
	/************************************
	*	Class slideShow   				*
	*	@author: Making Ideas Work !	*
	*************************************/
	
	
	var go = "true"; 	
	var slideShow = Class.create();
		
	slideShow.prototype = {
	
				initialize: function(aElems)
		{
					
			
			/* Configuration */
			this.bDebug 	= false;		// if Firebug is installed
			this.delay 		= 7;			// time between switches in sec
			this.bEffects 	= true;			// activates effects during transition
			this.transition = 0.5;			// animation duration in sec
			this.imagePath	= '/lib/yhst-51054734648456/';	// path to image folder
						
			
			/* Configuration end */
	
			this.aElems 	= aElems;
			this.aPicIds 	= new Array();
			this.currentKey;
					
						
			
			var i = 0;
			
			for (var key in this.aElems) {
	
				$('slideShow').innerHTML += '<img src="'+this.imagePath+key+'" id="pic_'+i+'" style="display:none" width="605" alt="" onclick="window.location.href=\''+this.aElems[key]+'\'" />'; // pre-loads images
				
				this.addToPager(i);			// paginates
				
				this.aPicIds.push('pic_'+i);
				
				i++;
			}
												
			
			if (this.aPicIds.length > 0) {
				this.currentKey = 0;
				this.show(this.currentKey);
			}
	
		},
		
		next: function()
		{
			if (this.currentKey == this.aPicIds.length-1) { 	// if end of the array...
				var nextPicKey = 0; 							//... back to the beginning
			} else { 
				var nextPicKey = parseInt(this.currentKey)+1;
				nextPic = nextPicKey;
				
				
			}
			
			if (this.aPicIds[nextPicKey]) {
				if(go == "true"){
					this.show(nextPicKey);
				}	
				
			}
		},
		
		previous: function()
		{
			if (this.currentKey == 0) {  						// if beginning of the array...
				var previousPicKey = this.aPicIds.length-1; 	//... back to the end
			} else { 
				var previousPicKey = parseInt(this.currentKey)-1;
			}
			
			if (this.aPicIds[previousPicKey]) {
				this.show(previousPicKey);
			}
	
		},
		
		show: function(picKey)
		{
			if ($(this.aPicIds[picKey])) {
			
				this.loop('stop');
				
				this.hide(this.aPicIds[this.currentKey]);
				$('a' + (this.currentKey)).className = '';
				
				this.currentKey = picKey;
				$('a' + (this.currentKey)).className = 'selected';
				
				if (this.bEffects) {
					new Effect.Appear(this.aPicIds[this.currentKey], {
						queue: 'end',
						duration: this.transition
					})
				} else {
					$(this.aPicIds[this.currentKey]).show();	// show() is a built-in function of the prototype library, not the method of this class
				}
				
				this.loop('start');
				
			}
			this.sendConsole('current pic: ' + this.aPicIds[this.currentKey]);
			
		},
		
		hide: function(picId)
		{
			if ($(picId)) {
				if (this.bEffects) {
					new Effect.Fade(picId, {
						queue: 'end',
						duration: this.transition
					})
				} else {
					$(picId).hide();
				}
			}
		},
		
		loop: function(action)
		{
			if (action == 'start') {
				this.timeoutId = setTimeout("slideshow.next()", this.delay*1000);
				this.sendConsole('loop start');
				
			} else if (action == 'stop') {
				if (this.timeoutId) clearTimeout(this.timeoutId);
				this.sendConsole('loop stop');
				
			}
		},
				
		addToPager: function(id)
		{
			var element	= '<li><a href="javascript: slideshow.show(\''+ id +'\')" id="a'+ id +'" >'+ (id+1) +'</a></li>';
			var controls = $("controls");
			Element.insert(controls, { bottom: element });
			
			
		},
		
		sendConsole: function(elem)
		{
			if (this.bDebug) console.debug(elem);
		}
		
	
		
	};

Event.observe(window, 'load', function() {


	function button(){
			var butt = $("button");
			butt.onclick = function(){
				if(butt.className == "pause"){
					butt.className = "play";
					go = "false";
				}else{
					butt.className = "pause";
					go = "true";
					slideshow.show(slideshow.currentKey + 1);
					
					
				}
			}
			
		
		}
if(document.getElementById("controlBar")){	
  button();
}	
	
});	

