/* 
SlashC jQuery thumbs list plugin
hi@slashc.com, www.slashc.com
*/
(function($)
{	
	/* plugin methods */
	var methods =
	{
		/* intialization */
		init : function()
		{
			return this.each(function()
			{
				var $this = $(this), props = $this.data('props');				
				if(!props)
				{
					var list = $('ul', $this);
					var thumb = $('li', list);
					
					var offsetX = 0, border = -1;
					thumb.each(function()
					{
						var $thumb = $(this).slashcThumbnail();
						if (border == -1) border = ($thumb.outerWidth() - $thumb.width()) * 0.5;
						$thumb.css('left', offsetX);
						offsetX += $thumb.width() + border;
					});
					
					var visWidth = $this.width();
					var totWidth = offsetX + border;
					
					$this.data('props', 
					{
						list: list,
						visWidth: visWidth,
						totWidth : totWidth
					});
				}
			});
		},
		/* scroll to percentage method */
		scrollTo : function(p)
		{
			p = p < 0 ? 0 : (p > 1 ? 1 : p);
			return this.each(function()
			{
				var $this = $(this), props = $this.data('props');
				if (props)
				{
					props.list.stop(true, true).animate({ left: p * (props.visWidth - props.totWidth) }, { duration: 250, easing: 'easeOutQuad' });
					//props.list.css('left', p * (props.visWidth - props.totWidth));
				}
			});
		},
		/* get proprortion */
		getProportion : function()
		{
			var $this = $($(this)[0]), props = $this.data('props');
			return (props && props.totWidth > 0) ? props.visWidth / props.totWidth : 0;
		}
	};
	/* Thumbnails list plugin */
	$.fn.slashcThumbsList = function(method)
	{
		if(methods[method])
		{
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		}
		else if(!method)
		{
			return methods.init.call(this);
		}		
	};
})(jQuery);
