jQuery.fn.UISlideBox = function(settings)
{
	settings = jQuery.extend({ width: null, height: null, speed: 500, boxSelector: '.box', leftBtnSelector: 'a:first', rightBtnSelector: 'a:last'}, settings);
	
	this.each(function(i, item)
	{
		item.UISlideBoxDo = function(dir)
		{
			var boxWidth = $(item).width();
			
			if (dir>0){ $(item).children(".box:eq("+item.UISlideBoxPos+")").animate({ left: boxWidth+'px' }, item.UISlideBoxSpeed); }
			if (dir<0){ $(item).children(".box:eq("+item.UISlideBoxPos+")").animate({ left: '-'+boxWidth+'px' }, item.UISlideBoxSpeed); }
		
			item.UISlideBoxPos += dir;
		
			if (item.UISlideBoxPos<0){ item.UISlideBoxPos = item.UISlideBoxMax; }
			if (item.UISlideBoxPos>item.UISlideBoxMax){ item.UISlideBoxPos = 0; }
		
			if (dir>0){ $(item).children(".box:eq("+item.UISlideBoxPos+")").css({left: '-'+boxWidth+'px'}); }
			if (dir<0){ $(item).children(".box:eq("+item.UISlideBoxPos+")").css({left: boxWidth+'px'}); }
			$(item).children(".box:eq("+item.UISlideBoxPos+")").animate({ left: '0px' }, item.UISlideBoxSpeed);
		}


		item.UISlideBoxPos = 0;
		item.UISlideBoxMax = $(item).children(settings.boxSelector).length-1;
		item.UISlideBoxSpeed = settings.speed;
		
		var w = settings.width;
		var h = settings.height;
		
		if (w==null){ w = $(item).width(); }
		if (h==null){ h = $(item).height(); }
		
		$(item).css({position: 'relative', overflow: 'hidden'});
		$(item).children(settings.boxSelector).css({position: 'absolute', top: '0px', left: '-'+w+'px', width: w+'px', height: h+'px'});

		$(item).children(settings.leftBtnSelector).click(function(){ item.UISlideBoxDo(-1); return false; });
		$(item).children(settings.rightBtnSelector).click(function(){ item.UISlideBoxDo(+1); return false; });
		
		item.UISlideBoxDo(0);
	}
	);
	
	return this;
}
