﻿//my first jqurey plug-in
//izak coen
//18.5.2010

(function($){  
 $.fn.simpleScroll = function(options) {  
 
   var defaults = {  
        scrollDuration : 1400,
        scrollPause : 3000,
        animationType : "swing"
    };  
    
   var options = $.extend(defaults, options);  
  
    return this.each(function() {  
    
        obj = $(this);
        
        obj.mouseenter(function(){
            obj.stop();
        })
        obj.mouseleave(function(){
            scrollMe();
        })
        
        scrollMe();
        
        function scrollMe(){
            itemHeight = (obj.find('li:first').outerHeight(true));
            itemHeight = (-1)*itemHeight;
            objTop = obj.css("top").replace("px","")*1;
            
            if (objTop == 0){
                sTime = options.scrollDuration;
            }
            else {
                sTime = options.scrollDuration*(itemHeight-objTop)/itemHeight;
            }
            
            obj.animate({left:0}, options.scrollPause, function(){
                obj.animate({top:itemHeight}, sTime, options.animationType, function(){
                    obj.css("top", 0);
                    obj.append(obj.find('li:first'));
                    
                    scrollMe();
                });
                
            });
            
        }
      
    });  
 };  
})(jQuery); 
