/*
 * Comment: Text scroller for Taket
 * Author: AutomatWeb
 */
(function($)
{
    var scrollingText = "";

    $.fn.scrollText = function()
    {
		setStyles = function() {
			$(that)
				.css("overflow", "hidden")
				.css("position", "relative")
				.css("height", "15px");
			
			$("div", that)
				.css("width", "5000px")
				.css("position", "absolute")
				.css("top", "0")
				.css("left", "0");
		}
		
		function createScroller() {
			tmp = $(that).text();
			for(i=0;i<20;i++)
			{
        		scrollingText = scrollingText + tmp + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			}
			$(that).html("<div id='AWScrollMe'>"+scrollingText+"</div>");
		}
		
		function initAnimation() {
			var leftPos = 0;
			var scrollMe = document.getElementById("AWScrollMe"); // maby this is fater than $("div", that)
			
			function animate() {
				leftPos = leftPos - 1;
				scrollMe.style.left = leftPos+"px";
				
				/*
							var animateFadeIn = function() {
				leftPos = leftPos - 1;
				scrollMe2.css("left", leftPos+"px");
				scrollMe2.animate({"opacity": "1.0"}, animationSpeed, "linear");
				scrollMe1.animate({"opacity": "1.0"}, animationSpeed, "linear", function() {
					scrollMe1.css("left", leftPos+"px");
					animateFadeOut();
				});	
			}
			
			var animateFadeOut = function() {
				leftPos = leftPos - 1;
				scrollMe1.css("left", leftPos+"px");
				scrollMe1.animate({"opacity": "1.0"}, animationSpeed, "linear");
				scrollMe2.animate({"opacity": "0.0"}, animationSpeed, "linear", function() {
					scrollMe2.css("left", leftPos+"px");
					animateFadeIn();
				});
			}
			
			animateFadeIn();
			*/
			}
			
			this.timer = setInterval(animate, 200); 
		}
		
        return this.each(function()
        {
			that = this;
			createScroller();
			setStyles();
			initAnimation();
			
			//alert(scrollingText);
            //alert(this.vari);    // would output `undefined`
            //alert($(this).vari); // would output `$.fn.vari`
        });
    };
	
	
})(jQuery);
