 $(document).ready(function(){
 $('#scrollbar1').tinyscrollbar();
 var c=1;

/* CONTROLLA IL BOTTONE VEDI GALLERY */
$('#vedi_gallery').live('click', function() {
gallery=$("#"+c+" .gallery").html();
//COMMENTANDO TITOLO l'ERRORE SU IE SCOMPARE...
//titolo=$("#"+c+" .titolo").html();
idgallery=$("#"+c+" .idgallery").html();
Shadowbox.open({
		content: gallery,
		gallery:    idgallery,
		player:     'img'
		//title: titolo
    });
});
 
/* CONTROLLA IL BOTTONE 'RIGHT' */ 
$('#right').live('click', function() {
  c++;

  conttitolo=$("#"+c+" .titolo").html();
  colore=$("#"+c+" .colore").html();
  conttext=$("#"+c+" .testo").html();
  //gallerytext=$("#"+c+" .gallery").html();
  
  if ($("#"+(c+1)+" .titolo").html()==null){
  $('#right').fadeOut();
  }
  
    if ($("#"+(c-1)+" .titolo").html()!=null){

    if ($('#left').css('display')=='none')
  $('#left').fadeIn();
  }

  
  $("#slide").animate({ 
        marginLeft: "-=670px"
    }, 1000 );
    
  $("#titolo").fadeOut('fast',function(){
  $("#titolo").html("<h2>"+conttitolo+"</h2>").css('color',colore).fadeIn();
  Cufon.refresh();
  });
  $("#gallery_bt").fadeOut('fast',function(){
  //$("#vedi_gallery").html(gallerytext);
  $("#gallery_bt").fadeIn();
  Cufon.refresh();
  });  

  $("#scrollbar1").fadeOut('fast',function(){
  $("#contentest").html(conttext);

  $("#scrollbar1").fadeIn('fast',function(){
  $('#scrollbar1').tinyscrollbar_update(); 
  });

  });
  


});


/* CONTROLLA IL BOTTONE 'LEFT' */ 
$('#left').live('click', function() {
c--;

  if ($("#"+(c-1)+" .titolo").html()==null){
  $('#left').fadeOut();
  }
  
   if ($("#"+(c+1)+" .titolo").html()!=null){

    if ($('#right').css('display')=='none')
  $('#right').fadeIn();
  }



  $("#slide").animate({ 
        marginLeft: "+=670px"
    }, 1000 );
     conttitolo=$("#"+c+" .titolo").html();
     colore=$("#"+c+" .colore").html();
  $("#titolo").fadeOut('fast',function(){
  $("#titolo").html("<h2>"+conttitolo+"</h2>").css('color',colore).fadeIn();
  Cufon.refresh();
  });
  conttext=$("#"+c+" .testo").html();
  $('#gallery_bt').fadeOut('fast').fadeIn('fast');
  $("#scrollbar1").fadeOut('fast',function(){
  $("#contentest").html(conttext);
  
   $("#scrollbar1").fadeIn('fast',function(){
  $('#scrollbar1').tinyscrollbar_update(); 
  });
  
  
  });  
  


});


/* CONTROLLA IL CLICK DELLA SOTTOVOCE DI MENU SHOWREEL */ 
$('.voce_menu2').click(function(){



$('#menu2').find('.active').removeClass('active');
Cufon.refresh();
$(this).css({backgroundPosition: "230px 0px"});
$(this).addClass('active');
Cufon.replace('.active', {
	color: '-linear-gradient(white, #f0f0f0)'
});
pos = this.id;
$('#contenuto2').fadeOut('fast',function(){
$('#contenuto2').html('');
c=1;
 $("#slide").css('marginLeft','0px');
 
 $("#titolo").hide();
 $("#gallery_bt").hide();
 $("#scrollbar1").hide();
 
$('#contenuto2').load('pagine/'+pos+'.php', function(){

  conttitolo=$("#"+c+" .titolo").html();
  colore=$("#"+c+" .colore").html();
  conttext=$("#"+c+" .testo").html();
  //gallerytext=$("#"+c+" .gallery").html();
  

  $("#titolo").html("<h2>"+conttitolo+"</h2>").css('color',colore).fadeIn();
  Cufon.refresh();


  //$("#vedi_gallery").html(gallerytext);
  $("#gallery_bt").fadeIn();
  Cufon.refresh();
 


  $("#contentest").html(conttext);

  $("#scrollbar1").fadeIn('fast',function(){
  $('#scrollbar1').tinyscrollbar_update(); 
  

  });
$("#left").fadeOut();
$("#right").fadeIn();

Cufon.refresh();
$('#contenuto2').fadeIn('fast',function(){
$('#scrollbar1').tinyscrollbar();
});
});

});


});


/* CONTROLLA IL CLICK DELLA VOCE DEL MENU PRINCIPALE */ 
$('.voce_menu').click(function(){
$('#menu').find('.active').removeClass('active');
Cufon.refresh();
$(this).css({backgroundPosition: "230px 0px"});
$(this).addClass('active');
Cufon.replace('.active', {
	color: '-linear-gradient(white, #f0f0f0)'
});
pos = this.id;



if (pos!='showcase'){

if ($('.pagina_nera').css('display')!='none'){
$('.firma_white').fadeOut().fadeIn();
$('.pagina_nera').slideUp().slideDown();
$('#contenuto').fadeOut('fast',function(){
$('#contenuto').load('pagine/'+pos+'.php', function(){
Cufon.refresh();
}).delay(500).fadeIn();
});


}else{
if ($('.pagina_bianca').css('display')!='none'){
 $("#titolo").hide();
 $("#gallery_bt").hide();
 $("#scrollbar1").hide();
 $("#right").hide();
 $("#left").hide();
$('.pagina_bianca').slideUp();
$('#contenuto2').html('');
}

$('.firma_white').delay(200).fadeIn();
$('#contenuto').load('pagine/'+pos+'.php', function(){
Cufon.refresh();
$('.pagina_nera').slideDown();
});


}

}else{
if ($('.pagina_nera').css('display')!='none')
$('.pagina_nera').slideUp();
$('.pagina_bianca').slideDown();



}


});
/* EFFETTO GRAFICO AL PASSAGGIO DEL MOUSE */ 
	$('.voce_menu')
		.css( {backgroundPosition: "230px 0px"} )
		.mouseover(function(){
		if (!$(this).hasClass('active')){
			$(this).stop().animate({color:"#FFFFFF"}, {duration:500});
			$(this).stop().animate({color:"#FFFFFF"}, {duration:500});
			$(this).stop().animate({backgroundPosition:"(690px 0px)"}, {duration:500});
			}
		})
		.mouseout(function(){
			if (!$(this).hasClass('active')){
			$(this).stop().animate({color:"#f9bb2c"}, {duration:200});
			$(this).stop().animate({color:"#333333"}, {duration:200});
			$(this).stop().animate({backgroundPosition:"(230px 0px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "230px 0px"});
				$(this).css({color: "#f9bb2c"});
				$(this).css({color: "#333333"});
			}});
			}else{
			$(this).css({backgroundPosition: "230px 0px"});
			}
		})
		$('.voce_menu2')
		.css( {backgroundPosition: "230px 0px"} )
		.mouseover(function(){
		if (!$(this).hasClass('active')){
			$(this).stop().animate({color:"#FFFFFF"}, {duration:500});
			$(this).stop().animate({color:"#FFFFFF"}, {duration:500});
			$(this).stop().animate({backgroundPosition:"(690px 0px)"}, {duration:500});
			}
		})
		.mouseout(function(){
			if (!$(this).hasClass('active')){
			$(this).stop().animate({color:"#f9bb2c"}, {duration:200});
			$(this).stop().animate({color:"#333333"}, {duration:200});
			$(this).stop().animate({backgroundPosition:"(230px 0px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "230px 0px"});
				$(this).css({color: "#f9bb2c"});
				$(this).css({color: "#333333"});
			}});
			}else{
			$(this).css({backgroundPosition: "230px 0px"});
			}
		})



});

