(function($){
    $.fn.carousel = function(){
        var element = this;
        var itemWith = 770;
        var position = 0;
        var total = $(element).children().size();
        var mainWidth = $(element).css("width",(total * itemWith) + "px");
        var itemId = 1;
        var pagination;
        var playing = 0;
        var t;

        $(".newsSlider .next img").bind("click", function(){

            if(playing) return false;
            
            playing = 1;
            position--;
            var timer = 1500;
            
            if(position + total == 0) {
                position = 0;
                timer = 200;
            }
            
            var newPos = position * itemWith;
            $(element).animate({left:newPos},timer,function(){playing = 0;});
            
        });
        
        $(".newsSlider .previous").bind("click", function(){
            
         //   stop();
            
            if(playing) return false;
            playing = 1;
            
            position++;
            var timer = 1500;
            
            if(position > 0) {
                position = 0;
                playing = 0;
                
                return false;
            }
            
            var newPos = position * itemWith;
            $(element).animate({left:newPos},timer,function(){playing = 0;}); 
            
        });  
        
      
       

     //   setTimeout(function(){playCarousel();},8000);
        
    }
 })(jQuery); 
