jQuery( document ).ready( function()
{
	var icons =
	{
  	header: "ui-icon-circle-arrow-e",
    activeHeader: "ui-icon-circle-arrow-s"
  };

	var level2Present = $('.level2').length > 0;

	var top = $( "#root" ).accordion(
	{
		autoHeight: false,
		autoWidth: false,
		heightStyle: "content",
		icons: icons,
		saveState: true,
		collapsible: true,
		active: false

	} );

	$( '#root' ).children().each( function( index )
  {
  	var top = $(this);

  	var level2Present = $('.level2', top ).length > 0;

  	if( level2Present )
  	{
  		$( ".level1", top ).accordion(
  		{
  			autoHeight: false,
  			autoWidth: false,
  			heightStyle: "content",
				icons: icons,
				collapsible: true,
				active: false
  		} );
  	}

  	});

    $('#root a').click( function( eventObject )
  	{
  		  $('#root a').removeClass('selected');
		  	$(this).addClass('selected');
		});

	$('#root a').mouseover( function()
		{
	  $(this).addClass('active');
	});

	$('#root a').mouseout( function()
	{
	  $(this).removeClass('active');
	});

});

