 //********** MENU *******
 
 
 $(document).ready( function()
	{
		var index=-1;
		index= fotoswitcher(index);
		initScroller(-1);
		
		
	// chiudo interno se chiudo esterno
	$(".menuitem").click(function(){
		$(".intheader").children('.intmenu').fadeOut('fast');
	});
    
	// chiudo interno se apro altro interno	
	$(".intheader").click(function(){	
		$('.intheader').children('.intmenu').fadeOut('fast');
		$(this).children('.intmenu').fadeIn('slow');
	});
	
	$('#next').click(function (){
	 fotoswitcher(++index);});
	
	$('#prev').click(function (){
	 fotoswitcher(--index);
	});
		
	/*$("#prova").hover(
	
	function (){
		$("#prova1").fadeIn("fast");},
		
		function (){
		$("#prova1").fadeOut("fast");}
			
	);*/
	
	$(".intmenu li").hover(
	
		function (){	
		$("img", this).fadeIn("fast");},
		
		function (){
		//$("img", this).fadeOut("fast");});
		$("img", this).hide();}
	);

 });
 
 
 
 function fotoswitcher(index)
 {
	// carico numero foto
	var numimg = 0;
	$('.holder').each(function(){ numimg++; })
	//metto bottoni
	$('.button').show();
	
	
	if (index!=-1)
	{
	
	$('.holder').fadeOut(300);
	$('#holder'+index).fadeIn(300);
	if (index==1) $('#prev').hide();
	if (index == numimg) $('#next').hide();
	return index;
	
	}
	else
	{
	index = 1;
	$('#holder'+index).fadeIn('fast');
	$('#prev').hide();
	return index;
	}
	
	
 }
 
function initScroller( id){

	 var numimg = 0;
	 $('.scroller').each(function(){ numimg++; });
	
	if( id != -1 )
	{
		var objUsed = $( ".active" ).attr( 'id' );
		$( "#" + objUsed ).fadeOut( 1800 );
		$( "#" + objUsed ).removeClass( 'active' );
		$( "#scroller" + id ).fadeIn( 1800 );
	} 
	
	else id = 0;
	$( "#scroller" + id ).addClass( 'active' );
	
  /* numero di scroller*/
	var toPass = ( ( id * 1 ) + 1 ) % numimg;
	setTimeout( 'initScroller( ' + toPass + ',' + numimg +' )', 3400 );
  
 }
 
 
 
 

