var BD = BD || {};

BD.AccordionSlideController = function(element, smallWidth, largeWidth, duration)
{
	element = $(element);
	var small = element.find('.small');
	var large = element.find('.large');
	
	function open(callback)
	{
		// Move out & fade out .small
		small.animate(
			{
				left: -smallWidth+'px',
				opacity: 0
			},
			{
				duration: duration,
				step: function(n, fx)
				{
					if (fx.prop=='opacity')
					{
						var total = smallWidth + largeWidth;
						var delta = largeWidth - smallWidth;
						var current = smallWidth + Math.round(delta*(1-n));

						element.css('width', current+'px');
						callback(total - current);
					}
				}
			}
		);
		
		// Fade in .large
		large.animate({opacity: 1}, duration);
	}
	
	function close()
	{
		small.animate(
			{
				left: 0,
				opacity: 1
			},
			duration
		);
		
		// Fade out .large
		large.animate({opacity: 0}, duration);
	}
	
	function close_callback(width)
	{
		element.css('width', width+'px');
	}
	
	return {
		open: open,
		close: close,
		close_callback: close_callback
	};
}
