/**
 * jBlink
 * At last, a standards-compliant way to replicate the MARQUEE tag
 * 
 * Version 0.9
 * Author: Chris Patterson
 *
 * License: GPL 3 http://www.gnu.org/licenses/gpl-3.0.html
 * 
 **/
(function($){
	$.fn.jMarqueeify = function(options) {

	var defaults = {
	 scrollDelay: 0, /* time to wait between scrolls (in milliseconds) */
	 scrollTime: 150000 /* milliseconds - fewer is faster here */
	};

	var options = $.extend(defaults, options);
	
	function inlineWidth(obj) {
      var el = $('<i/>').css('display','inline').appendTo(obj);
      var pos = el.offset();
      el.remove();
      return pos;
  };
  
  function setGo(obj, innerWidth) {
    obj.css({'text-indent': ''}).animate({textIndent: -(innerWidth)}, options.scrollTime, function() {setGo(obj, innerWidth);}).animate({opacity: 1.0}, options.scrollDelay);
  };

	return this.each(function() {
		var obj = $(this).wrapInner('<span style="white-space: nowrap;"></span>').children(':first');
		var innerWidth = inlineWidth(obj).left;
		
		$(this).css({'text-indent' : $(this).width(), 'overflow' : 'hidden'});
		
		obj.css({'display': 'block'}); // Has to be done after getting the width if we want an accurate value
		
		setGo(obj, innerWidth);
	});

	};
})(jQuery);
