$(window).load(function(){
  //$(".drop").drop_shadow();
});

$(document).ready(function(){
 /* This is basic - uses default settings - Fancybox */
 	$(".fancybox").fancybox();
 	$(".fancybox-iframe").fancybox({type:'iframe'});
     jQuery('#mycarousel').jcarousel();
     attiva_stelle(); 	

 	$("#overflow div").each(function(){

          $(this).css("left",(l+offset-adjust)+"px");
      
          l+=w;

      });
 	

          $(window).scroll(function(){
          
          
               scrollamenu();
               
               if(ristorante && $(window).scrollTop()>$(document).height()-$(window).height()-50){
                    h=0;
                    toggle_login();
                    
                    //$('#login').effect("bounce", { times:3 }, 300);
               }
               
          });    



});





function scrollamenu(){

               $('#login').stop();
               $('#login').animate({"top":$(window).scrollTop()+50},500,'easeOutBack',function(){});

}

var ristorante=0;
var h=0;
 
function toggle_login(){

     if(!h){

          $('#login').width(209);
          $('#forml').show();
          h=1;
     }
     else {
          $('#login').width(130);
          $('#forml').hide(); 
          h=0;    
     
     }

} 

 
var adjust=10;    
var w=944;    
var l=0;
var offset=-w+($(window).width()-w)/2;
var semaforo=0;    
function scorri_right(){
                         
                    if(!semaforo){     
                         semaforo=1;
     
                         var ultimo=$('#overflow div:last').clone();
                         
                         $('#overflow').prepend(ultimo);  
                         $('#overflow div:first').css("left",(offset-w-adjust)+"px");
                          
                         $('#overflow div').animate({left:"+="+(w)},1000,'easeOutBack',function(){semaforo=0;});
                             
                         setTimeout(function(){$('#overflow div:last').remove(); },1000);   
                         
                         $('#centro').attr('href',$('.piatto:first').next().find('a').attr('href'));
                         
                    } 
                    
        }
function scorri_left(){
                    if(!semaforo){     
                         semaforo=1;
                         var ultimo=$('#overflow div:first').clone();
                         
                         $('#overflow').append(ultimo);  
                         $('#overflow div:last').css("left",(offset+w+w+w-adjust)+"px");
                          
                         $('#overflow div').animate({left:"-="+(w)},1000,'easeOutBack',function(){semaforo=0;});
     
                         setTimeout(function(){$('#overflow div:first').remove(); },1000);
                         
                         $('#centro').attr('href',$('.piatto:last').prev().find('a').attr('href'));

                    }   

        } 
        
        
				function attiva_stelle(){
					$('.stella').click(function(){
					
					       if(1){
					
                          var el=$(this);
                          var el2=$(this).parent('.voti');
                          $.ajax({
                                  url: "/ristorante.php?do=vota&prodotto="+el.attr("rel")+"&stelle="+el.attr("id"),
                                  global: false,
                                  type: "GET",
                                  dataType: "html",
                                  success: function(data){
                                      var stelle="";
                                      for(i=0;i<el.attr("id");i++){
												stelle+='<img src="/img/stella_voto.png" title="Hai dato '+el.attr("id")+' stelle" />';
                                          }
                						el2.after('<div class="voti">'+stelle+'</div>');
                						
                						el2.parent(".item").addClass("votata");
                						el2.remove();
                                  }
                               }
                            );
                            }
					});


					$('.stella').mouseover(function(){

							$(this).addClass('on');
							$(this).prevAll().addClass('on');
						
						});
					$('.stella').mouseout(function(){

						$(this).removeClass('on');
						$(this).nextAll().removeClass('on');
					
					});
					$('.voti').mouseout(function(){

						$('.stella').removeClass('on');
					
					});
				}           
