(function($){
	$.fn.scrollUl = function()
	{
		return this.each(function(){
			var _this = this;
			var li_width = ( $('li', _this).innerWidth());
			$($('.left', this).get(0)).click(function(){
				$($('ul', _this).get(0)).stop(true, true);
				var bottom = $($('.scroll-ul-container', _this).get(0)).offset().left - $($('ul', _this).get(0)).offset().left;
				if ( bottom > 0 )
				{
					var move = '+='+li_width+'px';
					if ( ( parseInt($($('ul', _this).get(0)).css('left')) + li_width ) > 0 )
					{
						var height = $('li', _this).innerWidth() + parseInt($(_this).attr('rel'));
						move = '+='+height+'px';
					}
					$($('ul', _this).get(0)).animate({"left": move}, 'fast', 'swing');
				}
				return false;
			});
			$($('.right', this).get(0)).click(function(){
				$($('ul', _this).get(0)).stop(true, true);
				var top = $($('.scroll-ul-container', _this).get(0)).offset().left - $($('ul', _this).get(0)).offset().left;
				var a = top + $($('.scroll-ul-container', _this).get(0)).innerWidth();
				var diff = $($('ul', _this).get(0)).innerWidth() - a ;
				if ( diff > 0 && diff >= $('li', _this).innerWidth() )
				{
					var move = '-='+li_width+'px';
					if ( diff < li_width )
					{
						var width = $('li', _this).innerWidth() + parseInt($(_this).attr('rel'));
						move = '-='+width+'px';
					}
					$($('ul', _this).get(0)).animate({"left": move}, 'fast', 'swing');
					if ( window.work_list !== undefined || window.work_list == [] ) {
						for ( var i = 0; i < 1; i++ )
						{
							if ( work_list.length > 0 )
							{
								var photo = work_list.shift();
								$('.scroll-list').append(''+photo.html+'');
								$('.scroll-list').css('width', parseInt($('.scroll-list').css('width'))+188+'px');
							}
						}
					}
				}
				return false;
			});
		});
	};
})(jQuery);

$(document).ready(function(){
	$('.scroll-ul').scrollUl();
});
