/**
  simpleCarousel
  Developped By: Nyamagana Butera Ignace -> http://nyams.planbweb.com/
Version: 1.0
Copyright: Feel free to do whatever you like with this file as long as you leave my infos at the top.
 **/

(function($){
	$.fn.simpleCarousel = function(options) {
		var d = {'btnLeft' : 'move-left', 'btnRight' : 'move-right', 'nbViewItems' : 1, 'nbScrollItems' : 1, 'imgWidth' : 160, 'speed' : 1.5E3};
		var p = $.extend(d, options), action = false, start;
		$('.' + p.btnLeft).click(function(){
			if (action === false) {
				start = parseInt(ul.css('left'), 10);
				if (start >= 0) {
					ul.css('left','0px');
				} else {
					action = true;
					ul.animate({'left': ((start + s > 0) ? 0 : start + s) + 'px'}, p.speed, 'swing', function(){action = false;});
				}
			}
		});
		
		$('.' + p.btnRight).click(function(){
			if (action === false) {
				start = parseInt(ul.css('left'), 10);
				if (start <= -w) {
					ul.css('left', -w + 'px');
				} else {
					action = true;
					ul.animate({'left': ((start - s <= -w) ? -w : start - s) + 'px'}, p.speed, 'swing', function(){action = false;});
				}
			}
		});
		$(this).find('img').each(function(){
			$(this).css({'width':p.imgWidth + 'px', 'margin':'0 auto', 'padding':'1px'}).parent().append('<em>' + $(this).attr('title') + '</em>');
			$(this).attr('title','');
		});
		var li = $(this).find('li');
		li.css({'float':'left', 'margin':'0', 'padding':'1px', 'overflow':'hidden'});
		var liW = li.width() + 2;
		var ul = $(this).find('ul').css({'position':'relative', 'left':'0px', 'margin':'0', 'padding':'0', 'overflow':'hidden', 'list-style':'none'}).width(li.length * liW);
		var w  = (li.length - p.nbViewItems) * liW;
		var s  = p.nbScrollItems * liW;
		$(this).css({'position':'relative', 'margin':'0', 'overflow':'hidden', 'width': (p.nbViewItems * liW) + 'px'});
	};
})(jQuery);


$(document).ready(function() {
	var params = {
			'imgWidth' : 400, 
			'btnLeft' : 'move-left', 
			'btnRight' : 'move-right', 
			'nbViewItems' : 1, 
			'nbScrollItems' : 1	,
			'speed' : 1.5E3
	};
	
	$('#onepiece').simpleCarousel(params);
});