/*
 * jQuery crawlLine v1.0.0 
 *
 * Copyright (c) 2008 Taranets Aleksey
 * email: aleks_tar@ukr.net
 * www: markup-javascript.com
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */

jQuery.fn.crawlLine = function(_options){
    // defaults options	
    var _options = jQuery.extend({
	    speed:1.5,
	    crawElement:'div',
	    textElement:'li',
	    hoverClass:'viewText'
    },_options);

    return this.each(function(){
	    var _THIS = jQuery(this);
	    var _el = jQuery(_options.crawElement, _THIS);
	    var _text = jQuery(_options.textElement, _THIS);
	    var _clone = _text.clone();
	    var _elHeight = 0;
	    var _k = 1;
	
		// set parametrs *******************************************************
		var _textHeight = _el.height();

		if (_THIS.height() >= _textHeight)	return false;

		var _duration = _textHeight*50 / _options.speed;
		_el.append(_clone);
	    _el.css('marginTop',-_textHeight);
	    function animate() {
			_el.animate({marginTop:0}, {queue:false, duration:_duration*_k, easing:'linear', complete:function(){
				_el.css('marginTop',-_textHeight);
				_k=1;
				animate();
			}})
	    }
		setTimeout(function(){
				animate();
				_THIS.hover(function() {
						_el.stop();
						_THIS.addClass(_options.hoverClass);
					}, function(){
						_THIS.removeClass(_options.hoverClass);
						_k = 1 - (_textHeight + parseInt(_el.css('marginTop')))/_textHeight;
						animate();
					})
		}, 1000);
	});
}
jQuery.noConflict();
jQuery(document).ready(function(){
    jQuery('.slide-holder').crawlLine({crawElement:'ul'});
});
