﻿

window.addEvent('domready', function() {
	
if($('SlideItMoo_outer')) {

	var totIncrement = 0;
	var increment = 140; // (slide width+ right margin)
				
	var sliders_count = $$('div#SlideItMoo_items div.SlideItMoo_element a').length;

	$('SlideItMoo_items').setStyle('width', increment*sliders_count);


	var maxRightIncrement = increment*(-(sliders_count-4));


	var fx = new Fx.Morph('SlideItMoo_items', {duration: 500, transition: 'back:out', wait:false});


	// Next Button
	$('SlideItMoo_forward').addEvents({
		'click' : function(event){
			e = new Event(event).stop();

			if(totIncrement>maxRightIncrement){
				totIncrement = totIncrement - increment;
				fx.start({
					'margin-left': totIncrement
				});
			} 
	
		}
	})



	// Previous Button
	$('SlideItMoo_back').addEvents({
		'click' : function(event){
			e = new Event(event).stop();

			if(totIncrement<0){
				totIncrement = totIncrement + increment;
				fx.start({
					'margin-left': totIncrement
				});
			}
		}
	})


}
























	  var showDuration = 2000;
	  var container = $('slider_foto');
	  var links = $$('#slider_menu ul li a');
	  var images = container.getElements('img');
	  var currentIndex = 0;
	  var interval;


	  images.each(function(img,i){ 
		if(i > 0) {
          img.setStyle('display','block');
		  img.set('opacity',0);
		}
	  });


	  var show = function() {
		images[currentIndex].fade('out');
		images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
		

		links.each(function(link,i){ 
			link.removeClass('menu_first_selected');
			link.removeClass('menu_last_selected');
			link.removeClass('menu_next_selected');
		 });

		
		if(currentIndex==0) {

			links[currentIndex].addClass("menu_first_selected");
		
		} else if(currentIndex==4) {

			links[currentIndex].addClass("menu_last_selected");
		
		} else  {
		
			links[currentIndex].addClass("menu_next_selected");
		
		}
	  
	  };



	  interval = show.periodical(showDuration);



		links.each(function(ele, k){

			ele.addEvent('mouseover', function(e) {

				$clear(interval);

				links.each(function(link,i){ 
					link.removeClass('menu_first_selected');
					link.removeClass('menu_last_selected');
					link.removeClass('menu_next_selected');
				 });
				
				j = k-1;
				images[currentIndex].fade('out');
				images[currentIndex = j < images.length - 1 ? j+1 : 0].fade('in');
				
				
				if(k==0) {
					links[k].addClass("menu_first_selected");
				} else if(k==4) {
					links[k].addClass("menu_last_selected");
				} else  {
					links[k].addClass("menu_next_selected");				
				}


			});

		});



/**/



});






