/***********************************************************************************************************************
DATE: 3/26/2009
UPDATED: 3/25/2010
DESCRIPTION: This is the JavaScript required to create the accordion style menu.  Requires jQuery library
NOTE: Because of a bug in jQuery with IE8 we had to add an IE stylesheet hack to get the system to work in all browsers. I hate hacks but had no choice :(.
************************************************************************************************************************/
$(document).ready(function() {
	 
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.accordionButton').removeClass('on');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.accordionContent').slideUp('normal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
		  
	 });
	  
	
	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
		
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('over');										
	});
	
	/*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	
	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/	
	//put class on on accordion header first element
	$(".accordionButton:first").addClass('on');
	
	//setup scroller before content will be resized
	$(".accordionContent").jScrollPane();
	
	$('.accordionContent').hide();
	
	//show first accordion element on page load
	$(".accordionContent:first").show();
	
	
	
	//arrow up show on mouse over and arrow down show on mouse out
	$('.accordionButton').mouseover(function() {
		$('span',this).removeClass('iconDown');
		$('span',this).addClass('iconUp');
	}).mouseout(function() {	
		$('span',this).removeClass('iconUp');
		$('span',this).addClass('iconDown');	
	});
	
	//arrow up show on click 
	$('.accordionButton').click(function() {
		//take out icon up from first accordion element as it is added on page load
		$('span',".accordionButton:first").removeClass('iconUp');
		$('span',".accordionButton:first").addClass('iconDown');
		
		//remove iconUp_on from all elements
		$('.ui-icon').removeClass('iconUp_on');
		
		//remove icon down from clicked element
		$('span',this).removeClass('iconDown');
		
		//add  iconUp_on on clicked element
		$('span',this).addClass('iconUp_on');		
	});

});

