
function Accordion(container, options)
{	
	var showAccordion = null;
	var currentAccordion = null;	
	var animating = false;
    var option = options;
	var da = false;			
	var thisEvent = option.onEvent;
	var accordions = $('#'+container+' .'+option.classNames.toggle);
	
	accordions.each(function() 
	    {							  
			$(this).bind(thisEvent, activate);						
			$(this).next().css('height','0px');		
			$(this).next().css('display','none');						
		});	
	
	function activate(evnt)
	{	
		if (animating) 
		{
			return false;
		}		
		
		currentAccordion = $(this).next();		
		var a = currentAccordion.attr('name');
		var b = 'dummy';
		
		if(showAccordion != null)
		{
			b = showAccordion.attr('name');
		}		
		
		if (a==b) 
		{			
			
			deactivate(showAccordion);
		}
		else
		{			
			currentAccordion.css('display','block');
			_handleAccordion();
		}
	}
	
	function deactivate(showAccordion)
	{
		animating = true;
		da=true;
		showAccordion.animate({height:0},'slow','',AfterShrink);
		showAccordion.attr('name','');
	}
	
	function AfterExpand()
	{		
		showAccordion = currentAccordion;							
		animating = false;
	}
	
	function AfterShrink()
	{
		showAccordion.css('display','none');
		showAccordion = null;
		da=false;										
		animating = false;
	}
	
		
	function _handleAccordion()
	{
		animating = true;		
		
		if (showAccordion) 
		{			
			deactivate(showAccordion);						
		}				
		currentAccordion.animate({height:option.defaultSize.height},'slow','',AfterExpand);
				
		currentAccordion.attr('name','expanded');
	}
}
	
