//Created by Adrian Hennelly
//The Little Bear Menu Version 1.04
//--------Version Changes-----------
//---------------1.03---------------
//Added close on click, so item can be closed with out having to open another item
//---------------1.04---------------
//Added functionality to add and remove class on click.
//This allows us to have a different image when item is open to when its closed.
//---------------1.05---------------
//Commented out redundant code
//Added support for direct linking to open item from URL
//No history support at this time
//Changed slide to hide / show to stop anchor confusion
//See afyf for demo
function initAccordion() {
  $('#accordion ul').hide();
  //$('#res-arrow').hide();
  //$('#accordion ul:first').hide();//Changed from show to hide so that the menu loads in a colapsed state
  $('#accordion li .groupA').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
      	 $('#accordion ul:visible').hide();//removed slide so that anchors don't get confused
		 //$('#accordion ul:visible').slideUp('normal');//Added this line so that an open menu can be closed with out having to open another one
      	 $('.res-group').removeClass('res-group-selected');
        
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        $('#accordion ul:visible').hide();
		//$('#accordion ul:visible').slideUp('normal');//removed slide so that anchors don't get confused
        checkElement.show();
		//checkElement.slideDown('normal');
        $('.res-group').removeClass('res-group-selected');
        $('.res-group', $(this)).addClass('res-group-selected');
		//window.location=$(this).find("a").attr("href"); return false;
        
        }
      }
    );
  }
$(document).ready(function() {
  
  initAccordion();
  //Opens the anchor that was passed
  var myFile = document.location.toString();
  if (myFile.match('#')) { // the URL contains an anchor
	// click the navigation item corresponding to the anchor
	var myAnchor = '#' + myFile.split('#')[1];
	$('#accordion li ' + myAnchor).click();
  } else {
	
  }

  
});