window.addEvent("domready",function(){
	
	if(!$('spotlight'))
	return;
	
	var init = 0;
	var covers = [];
	var coversEl = [];
	var marge = 0;
	var Fxiz = [];
	var Pmax = 420;
	var Pcur = 110;
	var Pmin = 0;

	var imgz = [];
	var Eh2 = new Element('h2').injectInside($('spotlight'));
	var Ep = new Element('p').injectAfter(Eh2);
	var Aprev = new Element('a').setProperty('id','prev').injectTop($('spotlight')).addEvent('click',function(){ lauchSpot(SgetPrev()) });
	var Anext = new Element('a').setProperty('id','next').injectAfter(Aprev).addEvent('click',function(){ lauchSpot(SgetNext()) });
	
	
	
	
	
	$$('#spotlight ul li').each(function(el,i){
		
		var titre = el.getChildren()[1];
		var excerpt = el.getChildren()[2];
		
		
			covers[i]=[el.getProperty('rel'),el.getProperty('title'),excerpt.getText()];		
			coversEl[i]=el;
			excerpt.remove();
			titre.remove();
			
			
			Fxiz[i] = new Fx.Styles(el,{duration:500,wait:false,transition:Fx.Transitions.Cubic.easeOut}).set({'margin-left':marge});
			imgz[i] = new Fx.Styles(el.getChildren()[0],{duration:500,wait:false,transition:Fx.Transitions.Cubic.easeOut});
			
			marge = marge+Pcur;
	
			el.addEvent('click',function(e){ lauchSpot(i) });	
			
		
			
			});
			
	function SgetNext()
	{
		var res;
		coversEl.each(function(cover,pos){
			
	if(cover.getStyle('margin-left').toInt()==Pmax)
	{
	res = pos;
	}		
			
			});
		return(res);
	}	
	
	
	function SgetPrev()
	{var res;
		coversEl.each(function(cover,pos){
			
	if(cover.getStyle('margin-left').toInt()==Pmin)
	{
	res = pos;
	}		
			
			});
		return(res);
	}		
			
function lauchSpot(i){
	if((coversEl[i].getStyle('margin-left').toInt()==Pcur) && (init==1))
	{
		window.location.href=covers[i][0];
				return;
	}		
			if(coversEl[i].getStyle('margin-left').toInt()>Pcur)
			var dif = -Pcur;
			else
			var dif = Pcur;
			Eh2.setHTML(covers[i][1]);
			Ep.setHTML(covers[i][2]);
			
			Eh2.addEvent('click',function(e){window.location.href=covers[i][0]});
			Ep.addEvent('click',function(e){window.location.href=covers[i][0]});
			
		Fxiz.each(function(fx,j){
				
				
				
				if(j==i)
				{
				imgz[j].start({'width':380,'height':220});
				coversEl[j].setStyle('z-index','1000');
				fx.start({'width':380,'height':220,'margin-top':0,'margin-left':[coversEl[j].getStyle('margin-left').toInt(),Pcur]});
				}
				else
				{
				
					
					if(dif<0)
					{
						
						if(coversEl[j].getStyle('margin-left').toInt()==Pcur)
						{
							imgz[j].start({'width':180,'height':120});
				
							fx.start({'width':180,'height':120,'margin-top':35,'margin-left':[coversEl[j].getStyle('margin-left').toInt(),Pmin]})
							coversEl[j].setStyle('z-index','1');
						}
						else
						{
							imgz[j].start({'width':180,'height':120});
				
							fx.start({'width':180,'height':120,'margin-top':35,'margin-left':[coversEl[j].getStyle('margin-left').toInt(),Pmax]})
							coversEl[j].setStyle('z-index','0');
						}
						
					}
					else
					{
						
						if(coversEl[j].getStyle('margin-left').toInt()==Pcur)
						{
							imgz[j].start({'width':180,'height':120});
				
							fx.start({'width':180,'height':120,'margin-top':35,'margin-left':[coversEl[j].getStyle('margin-left').toInt(),Pmax]})
							coversEl[j].setStyle('z-index','1');
						}
						else
						{
							imgz[j].start({'width':180,'height':120});
				
							fx.start({'width':180,'height':120,'margin-top':35,'margin-left':[coversEl[j].getStyle('margin-left').toInt(),Pmin]});
							coversEl[j].setStyle('z-index','0');
						}
						
						
					}
					
				}
					
				
				
				
				
				});
	
	init = 1;
	}/* fin func */
	lauchSpot(0);
	if(coversEl[1])
	coversEl[1].setStyle('z-index','2');
	
	
	
	
	
	
	
	
	});
