// JavaScript Document
window.addEvent('domready', function() {
			 
	//CREO L'ARRAY DEGLI ITEM DEL MENU								 
	var items = $$('.thumb');
	var items_big = $$('.img_g');
	var cur_item = 0;
	var total_items = items.length;
	
	//CREO L'ANIMAZIONE PER LO SLIDE DELLE IMMAGINI
	var scroll_img = new Fx.Scroll('wrap_img', {
		wait: false,
		duration: 500,
		offset: {'x': -0, 'y': -0},
		transition: Fx.Transitions.Quad.easeInOut
	});
	var scroll_thumb = new Fx.Scroll('wrap_thumb', {
		wait: false,
		duration: 300,
		offset: {'x': -0, 'y': -0},
		transition: Fx.Transitions.Quad.easeInOut
	});
	
	
	var goTo = function (index,delta,scroll_obj)
	{
		if(index<total_items){
			var pos = delta*index;
			scroll_obj.start(pos);
		}
	}
	
	var next_thumb = function ()
	{
		if((cur_item+5)<total_items){
			cur_item++;
			goTo(cur_item,120,scroll_thumb);
		}	
	}
	var prev_thumb = function ()
	{
		if(cur_item>0){
			cur_item--;
			goTo(cur_item,120,scroll_thumb);
		}	
	}
	
	//CICLO LE THUMB E ASSEGNO LA FUNZIONE CLICK
	items.each(function(el,i){
		el.addEvent("click", function(event){new Event(event).stop();goTo(i,712,scroll_img)});
		
	})
	items_big.each(function(el,i){
		el.addEvent("click", function(event){new Event(event).stop();goTo(i+1,712,scroll_img)});
		
	})
	$("next_btn").addEvent("click", next_thumb);
	$("prev_btn").addEvent("click", prev_thumb);
	
	
});