﻿
jQuery.fn.liScroll = function(settings) {
	settings = jQuery.extend({
		travelocity: 0.05
	}, settings);
	return this.each(function(){
		var $strip = jQuery(this);
		$strip.addClass("newsticker");//do ul dodaje klase
		var $mask = $strip.wrap("<div class='mask'></div>");//obejmuje ul div z klasa mask
		var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");//obejmuje div z klasa mask div z klasa tickercontainer
		var stripWidth = 0;//deklaruje dlugosc/szerokosc paska
		var containerWidth = $strip.parent().parent().width();//declaruje i przypisuje szerokośc div z klasa tickercontainer
		$strip.find("li").each(function(i){
			stripWidth += jQuery(this, i).width();//sumuje li dla okreslenia dlugosci paska
		});
		$strip.width(stripWidth);//przypisuje obliczona szerokosc do ul
		var defTiming = stripWidth/settings.travelocity;
		var totalTravel = stripWidth;//+containerWidth;
		scrollnews(totalTravel, defTiming);
		
		function scrollnews(spazio, tempo){
			$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", totalTravel); scrollnews(totalTravel, defTiming);});
		}
		
		$strip.hover(
		    function(){
			    jQuery(this).stop();
		    },
		    function(){
			    var offset = jQuery(this).offset();
			    var residualSpace = offset.left + stripWidth;
			    var residualTime = residualSpace/settings.travelocity;
			    scrollnews(residualSpace, residualTime);
		    }
		);
	});
};
