// JavaScript Document

$(document).ready(function() {

     //alert('LZ Carousel v1'); 
     Width = 176;
     Push = Width*2;
     Visible = 3;
     
     CountItems = $("div.Wrapper ul > li").size(); 
     if (CountItems <= '3') {
          $("div.Carousel a.arrow").hide();
     }else{
          $("div.Wrapper ul").css("position","absolute");
          $("div.Wrapper ul").css("left","-"+Width+"px");
          $("div.Carousel a.arrow").show();
     }
     function Back(){
          // po kliknutí na LEFT naklonujeme Item nejvíc vpravo doleva
          $("div.Wrapper ul li:last").each(function(){
               $(this).clone(true).insertBefore("div.Wrapper ul li:first");
               $(this).replaceWith("");
          });
          // po naklonování posledního Itemu musím změnit napozicování, aby se mi celý blok neposunul
          $("div.Wrapper ul").css("left","-"+Push+"px");   
          $("div.Wrapper ul").animate({'left': -Width}, 'fast');     
     }
     function Forward(){
          $("div.Wrapper ul").animate({'left': -Push}, 'fast', function(){
               $("div.Wrapper ul li:first").clone(true).insertAfter("div.Wrapper ul li:last");
               $("div.Wrapper ul li:first").replaceWith("");
               $("div.Wrapper ul").css("left","-"+Width+"px");
          });  
     }
     $("a.left").click(function(){     
          Back();
     });
     $("a.right").click(function(){    
          Forward();
     });   
     
     // 
     if (CountItems > '3') {
          $("div.Wrapper, a.arrow").mouseover(function(){
               $("div.Wrapper").stopTime();
          });
          $("div.Wrapper, a.arrow").mouseleave(function(){
               $("div.Wrapper").everyTime(3000, 'controlled', function(){
                    Forward();   
               }); 
          });    
     }
      
     if (CountItems > '3') {
          $("div.Wrapper").everyTime(3000, 'controlled', function(){
               Forward();   
          });      
     }

});

