// JavaScript Document


/*
* Ricordati!!!!!
* Per implementare il player conti il numero di link di navigazione
* var count = Cint($$('#thumbnails a.cross-link').length) -1 ; cosė sappiamo direttamente l'ultimo
* e quindi determinare da dove far ripartire lo scorrimento
*/



function scorri(element,ranking){
		    
    $$('#thumbnails a.cross-link').each(function(ancor){ancor.removeClass('active-thumb');});
    
    element.addClass('active-thumb');
    
    var spostamento = 209;
    var spostamentoPX = '-'+(ranking * spostamento)+'px';
    
    var myEffect = new Fx.Morph($('scorri'), {duration: 'short', transition: Fx.Transitions.Sine.easeOut});			 
	myEffect.start({'margin-top': spostamentoPX}); // Visualizzo l'immagine successiva	con effetto scorrimento
    	    
}

function NewsReader(LastSlideNumber){
	
	var ActiveID;
	var nextIndex;
	
	if ($('thumbnails').hasClass('play')){
		
		$$('#thumbnails a.cross-link').each(function(el){
			
			if (el.hasClass('active-thumb')) {
				el.removeClass('active-thumb');
				ActiveID = el.get('id');
			}
		});
		
		var myNews_array = ActiveID.split("_");
		var activeIndex = parseInt(myNews_array[1]);
		
		(activeIndex == LastSlideNumber) ? nextIndex = 0 : nextIndex = activeIndex+1 ;
	 	//alert(nextIndex);
		var nextEl = $('news_'+nextIndex);
		nextEl.addClass('active-thumb');
		scorri(nextEl,nextIndex);
	}
}




window.addEvent('domready', function() {
	
	var LastSlideNumber = parseInt($$('#thumbnails a.cross-link').length) -1 ;
	
	$('thumbnails').addEvents({
	    'mouseover': function(){
	        this.removeClass('play');
	    },
	    'mouseout': function(){
	        this.addClass('play');
	    }
	});
		
	
	$$('#thumbnails a.cross-link').each(function(ancor,index){
	    
	    ancor.addEvent('click',function(){scorri(this,index);});
		   	    
	});
		
	var TimerID = NewsReader.periodical(4000, null,LastSlideNumber);
	
});	

