var currentDiv = 0;
var TotalDivs = -1;
window.addEvent('domready', function(){
	$$('[class=PhotosInner]').each(function(el){
			TotalDivs = TotalDivs + 1;	
			if(TotalDivs > 0){
				el.setStyle('left','236px');
			}
	});	
	
	if(TotalDivs == 0){
		$('Buttons').setStyle('display','none');
	}
	
	
	
	$$("a.prev").addEvent('click',function(){
		if(currentDiv == 0){
			SlideIt(currentDiv,TotalDivs,'left');			   
		}else{
				if(currentDiv+1 > TotalDivs){
						SlideIt(currentDiv,0,'left');	
				}else{
					SlideIt(currentDiv,currentDiv+1,'left');	
				}
		}
		return false;
		});
	
	$$("a.next").addEvent('click',function(){
		if(currentDiv == TotalDivs){
			SlideIt(currentDiv,0,'right');			   
		}else{
				if(currentDiv-1 < 0){
						SlideIt(currentDiv,TotalDivs,'right');	
				}else{
					SlideIt(currentDiv,currentDiv-1,'right');	
				}
		}
		return false;
		});
});

function SlideIt(slideout,slidein,direction){
	if(direction == 'left'){
		afrom = 0;
		ato = -237;
		bfrom = 237;
		bto = 0;
	}else{
		afrom = 0;
		ato = 237;
		bfrom = -237;
		bto = 0;
	}
	var e1 = $$('[rel=' + slideout + ']');
	var e2 = $$('[rel=' + slidein + ']');
	

	try{
		var FX1 = new Fx.Morph(e1[0], {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
		var FX2 = new Fx.Morph(e2[0], {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
	}catch(err){
			alert('cant find the elements');
			return;
	}
	
	FX1.start({
		'left': [afrom,ato]
			  });
	FX2.start({
		'left': [bfrom,bto]
			  });
	currentDiv = slidein;
		
}
