jQuery.fn.crawlLine = function(_options){
    // defaults options	
    var _options = jQuery.extend({
	    speed:1,
	    crawElement:'div',
	    textElement:'ul',
	    hoverClass:'viewText'
    },_options);

    return this.each(function(){
	    var _THIS = jQuery(this);
	    var _el = $(_options.crawElement, _THIS);
	    var _text = $(_options.textElement, _el);
	    var _clone = _text.css('whiteSpace','nowrap').clone();
	    var _elWidth, _duration, _timer = false;
	    var _k = 1;
	    
	    _text.after(_clone);
	    setParam();
	    _timer = setTimeout(function(){animate()}, 1000);
	    
	    function setParam() {
			_textWidth = _text.outerWidth(true);
			_el.css('width',_textWidth*2);
			_duration = (_textWidth*20)/(_options.speed);
	    }
	    function animate() {
			_el.animate({marginLeft:-_textWidth}, {queue:false, duration:_duration*_k, easing:'linear', complete:function(){
				_el.css('marginLeft','0');
				_k=1;
				animate();
			}})
	    }
	    _THIS.hover(function() {
			if (_timer) clearTimeout(_timer);
				_el.stop();
				_THIS.addClass(_options.hoverClass);
				_k = (_textWidth + parseInt(_el.css('marginLeft')))/_textWidth;
	    }, function(){
			_THIS.removeClass(_options.hoverClass);
			_timer = setTimeout(function(){animate()}, 100);
	    })
		
		_THIS.bind('wheel',function(event,delta){
			if (delta>0) {
				_el.animate({marginLeft:parseInt(_el.css('marginLeft')) + 20}, {queue:false, duration:100, easing:'linear', complete:function(){
					_k = (_textWidth + parseInt(_el.css('marginLeft')))/_textWidth;
				}})
			} else {
				_el.animate({marginLeft:parseInt(_el.css('marginLeft')) - 20}, {queue:false, duration:100, easing:'linear', complete:function(){
					_k = (_textWidth + parseInt(_el.css('marginLeft')))/_textWidth;
				}})				
			}
		});		
	});
}

$(document).ready(function(){
	$('.submenu2').crawlLine();
});