/*!
 * liScroll 1.0
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2009 Gian Carlo Mingati
 * Version: 1.0.1 (07-DECEMBER-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 * 
 */
/* 
	customized Netyear Group inc. Any tag version(not only li)
*/
jQuery.fn.ticker = function(target_jquery_obj,settings) {
		settings = jQuery.extend({
		travelocity: 0.07,
		prefix: ""
		}, settings);
		return this.each(function(i){
				var $strip = jQuery(this);
				$strip.parent().hide();
				var containerWidth = $strip.parent().width();
				if((jQuery.browser.msie  || jQuery.browser.mozilla || jQuery.browser.safari) ){
					//marqueeタグを利用
					var $seed=$strip.find(":eq(0)");
					var html = $seed.html();
					jQuery(target_jquery_obj).each(function(i){
						var ahtml=jQuery(this).html();
						html = settings.prefix +ahtml + html;
					});
					$strip.html('<marquee scrolldelay="100" scrollamount="4">' + html+ '</marquee>');
				}else{
					var $seed = $strip.find(":eq(0)");
					$seed.css("display","block");
					$seed.css("float","left");
					$seed.css("white-space","nowrap");
					//$seed.css("height","11");
					var seedwidth=$seed.width();
					//var stripWidth = $strip.width();
					var stripWidth=seedwidth;
					var seedhtml=$seed.html();
					seedhtml = "<wbr>" + seedhtml + "</wbr>";
					$seed.html(seedhtml);
					var $mask = $strip.wrap("<div class='mask' style='position:relative;overflow: hidden;'></div>");
					var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer' style='position:relative;overflow: hidden;'></div>");
					$strip.css("position","relative");
					//var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 
					$tickercontainer.width(containerWidth);
					$mask.width(containerWidth);
					//$strip.hide();
					jQuery(target_jquery_obj).each(function(i){
						//var width = jQuery(this).width();
						var html=jQuery(this).html();
						var html = '<wbr id>' + settings.prefix + html + '</wbr>';
						var seedclone=$seed.clone();
						seedclone.attr("id","ticker-part"+i);
						jQuery(seedclone).html(html);
						$seed.before(seedclone);
						var width=jQuery("#ticker-part"+i).width();
						stripWidth += width;
						$strip.width(stripWidth*1.1);
						
					});
					//$strip.show();
					var totalTravel = stripWidth;
					//var totalTravel = stripWidth+containerWidth;
					//var defTiming = Math.min(containerWidth,seedwidth)/settings.travelocity;	// thanks to Scott Waye
					var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye
					function scrollnews(spazio, tempo){
						$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel+containerWidth, Math.max(totalTravel,containerWidth)/settings.travelocity);});
					}
					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);
						}
					);	
				}
				$strip.parent().show();
		});	
};