/**
 * 2009-12-15

  <div style="width:800px;overflow:hidden;">
     <div style="width:32766px;zoom:1;">
          <div style="float:left;">
                 ......................
          </div>
     </div>
  </div>

 * 2009-10-01
 * http://www.zhaipeng.cn/
 *
 */
(function ($)
{


	$.fn.maquee=function (options)
	{

		options=$.extend(
		{

			target:'',
			direction:'left',
			x:10,
			time:10,
			timer:false,
			stop:false,
			create:false

		},options);



		options.target=$(options.target).get(0);
		$(options.target).css("overflow","hidden");

		if(options.create==true)
		{

			$(options.target).wrapInner('<div style="float:left;"></div>').wrapInner('<div style="width:32766px;zoom:1;"></div>');

		}

		options.width=$(options.target).width();
		options.offsetWidth=$(options.target).children(0).children(0).width();
		// offsetWidth

		if(options.direction=='right')
		{

			$(this).mousedown(function ()
			{

				try
				{
					clearTimeout(options.timer);

				}catch(e)
				{

				}
				$(options.target).maquee_right(options);

			});

		}else
		{

			$(this).mousedown(function ()
			{

				try
				{
					clearTimeout(options.timer);

				}catch(e)
				{

				}
				$(options.target).maquee_left(options);

			});

		}
		$(this).mouseup(function ()
		{
			clearTimeout(options.timer);

		});

		$(this).click(function ()
		{
			return false;

		});




	}

	$.fn.maquee_right=function (options)
	{

		var $this=this;
		if(this.scrollLeft()+options.x>options.offsetWidth-options.width)
		{


			$this.scrollLeft(options.offsetWidth-options.width);
			try
			{
				clearTimeout(options.timer)
			}catch(e)
			{

			}
			return ;

		}else
		{

			this.scrollLeft(this.scrollLeft()+options.x);

		}

		function runRight()
		{

			$this.maquee_right(options);

		}
		options.timer=setTimeout(runRight,options.time);

	}

	$.fn.maquee_left=function (options)
	{

		var $this=this;
		if(this.scrollLeft()-options.x<0)
		{

			try
			{
				clearTimeout(options.timer);

			}catch(e)
			{

			}
			return ;

		}else
		{

			this.scrollLeft(this.scrollLeft()-options.x);

		}

		function runLeft()
		{

			$this.maquee_left(options);

		}
		options.timer=setTimeout(runLeft,options.time);

	}


})(jQuery);
