var firstRun = true;
var path = "";

function initMenu(theMenu, thePath) 
{
	path = thePath;
		
  $(theMenu + ' ul').hide();
 
	addArrows( theMenu );
 
	var currentPage = $(theMenu + ' li li.accordSelected').parent();
	
	if( currentPage.length == 0 ) currentPage = $(theMenu + ' ul:first' );
 
	openList( currentPage );
	
	
  
  $(theMenu + ' li a').click
  (
		function() 
		{
			  var checkElement = $(this).next();
			  
			  var openListParentLink;
			  
			  if((checkElement.is('ul')) && (checkElement.is(':visible'))) 
			  {			  
				closeList( checkElement );	
				
				return false;
			  }
			  
			  if((checkElement.is('ul')) && (!checkElement.is(':visible'))) 
			  {								
				var currentOpenList = $(theMenu + ' ul:visible');
				// close currently open list //
				closeList( currentOpenList );
				// open new list //
				openList( checkElement );
				
				return false;
			  }
		}
	);
	
	
	
};

function addArrows( theMenu )
{
	var theTitle = $(theMenu + ' ul').siblings('a');
	theTitle.css( "background" , "#0354A0 url('" + path + "images/accordianMenu/downArrow.gif') no-repeat 160px center" );
	//theTitle.addClass( ".listClosed" );
	
	var top = $(theMenu + ' .accordTop a')[0];
	
	$(top).css( "background" , "transparent url('" + path + "images/accordianMenu/accordianTopDeSelected.png') no-repeat top" );
	
}

function indentText( element )
{	
	if(firstRun)
	{
		firstRun = false;
		$(element).css( "paddingLeft", "30px" );
		return;
	}	
	
	$(element).animate( { paddingLeft:"30px" } );
}

function unIndentText( element )
{
	$(element).animate( { paddingLeft:"12px" } );
}

function openList( theList )
{
	var theTitle = theList.siblings('a');
	var theParentList = theList.parent();


	if( theParentList.hasClass("accordTop") )
	{
		theTitle.css( "background" , "transparent url('" + path + "images/accordianMenu/accordianTopSelected.png') no-repeat top left" );
	}
	else
	{
		theTitle.css( "background" , "#0354A0 url('" + path + "images/accordianMenu/upArrow.gif') no-repeat 160px center" );	
	}
	
	if( firstRun )
	{
		theList.show();
	}
	else
	{
		theList.slideDown( 'normal' );
	}
	
	// indent open title text //
	indentText(theTitle);
}

function closeList( theList )
{
	var theTitle = theList.siblings('a');
	var theParentList = theList.parent();
	
	if( theParentList.hasClass("accordTop") )
	{
		theTitle.css( "background" , "transparent url('" + path + "images/accordianMenu/accordianTopDeSelected.png') no-repeat top left" );
	}
	else
	{
		theTitle.css( "background" , "#0354A0 url('" + path + "images/accordianMenu/downArrow.gif') no-repeat 160px center" );	
	}
	
	

	theList.slideUp('normal', function(){ unIndentText( theTitle ); } );
}







