window.addEvent('domready',function(){
	
	var rotater = new Rotater('.slide',{ 		//Class of elements that should rotate.
		slideInterval:5000, 					//Length of showing each element, in milliseconds
		transitionDuration:1000				//Length crossfading transition, in milliseconds
	});
	
	//start and stop rotater on control click
	
	$('stop').addEvent('click',function(){
		this.set('styles',{
			'display':'none'
		});
		$('play').set('styles',{
			'display':'block'
		});
		rotater.stop();
	});
	
	$('play').addEvent('click',function(){
		this.set('styles',{
			'display':'none'
		});
		$('stop').set('styles',{
			'display':'block'
		});
		rotater.rotate();
		rotater.autoplay('true');
	});

	//thumbnails border effects	
	$$('.photo').each(function(el){
		el.addEvent('mouseover',function(e){
			e.stop();
				el.tween('border-color','#ebdbba');			
		});
		el.addEvent('mouseout',function(e){
			e.stop();
			el.tween('border-color','#403c3c');			
		});
		el.addEvent('click',function(e){
				//show the correct slide clicking on thumbnail
			new Event(e).stop();	
			el.tween('border-color','#ebdbba').addClass('clicked');	
			var rel = this.getProperty('rel');
			rotater.showSlide(rel);
			rotater.stop();
			$('stop').set('styles',{
				'display':'none'
			});
			$('play').set('styles',{
				'display':'block'
			});
		});

	
	});
	
	$$('.photo img').each(function(el){
		el.set('styles',{	'opacity':'0.5'	});
		el.addEvent('mouseover',function(){
			//this.get('tween',{property:'opacity'}).start(1);
		});
		el.addEvent('mouseout',function(){
		 //	this.get('tween',{property:'opacity'}).start(0.5);
		});
		el.addEvent('click',function(){
			this.set('opacity','1');
		});
	});
		
});
