﻿Event.observe(window, 'load', loadAccordions, false);
		var menuAccordion;
		function loadAccordions() {		
		
		if (typeof Effect == 'undefined') 
			alert('effects could not be found');			
			menuAccordion = new accordion('menuContainer', {
				// The speed of the accordion
				resizeSpeed : 8,
				// The classnames to look for
				classNames : {
					// The standard class for the title bar
					toggle : 'menuToggle',
					// The class used for the active state of the title bar
					toggleActive : 'menuToggleActive',
					// The class used to find the content
					content : 'submenu'
				},
				// If you don't want the accordion to stretch to fit 
				// its content, set a value here, handy for horixontal examples.
//				defaultSize : {
//					height : null,
//					width : null
//				},
				// The direction of the accordion
				direction : 'vertical',
				// Should the accordion activate on click or say on mouseover? (apple.com)
				onEvent : 'click'
			});		
//			bottomAccordion.activate($$('#sessionContainer .accordion_toggle')[0]);	

            initializeMenuItems();

		}
		
		function initializeMenuItems()
		{		    	    
		    var accIndex = 0;
			var menuItemArr = $$('.menuToggle');
	        menuItemArr.each(function(accordion) {

                var itemIx = '' + accIndex + '';
		        $(accordion).observe('mouseover', function(event) { activateMenuItem(itemIx) }, true);
		        accIndex++;
	        });		
		}
				
		var menuItem;
		var mtid = -1;
		var transitioning = false;
		
		function activateMenuItem(item)
		{
			if(mtid != -1)
				clearTimeout(mtid);
	
			menuItem = item;
			
			if(!transitioning)	
				mtid = setTimeout('executeMenuActivation()', 300);
		}
		
		function executeMenuActivation()
		{
			try
			{
				transitioning = true;
				if(menuItem)
					menuAccordion.activate($$('#menuContainer .menuToggle')[menuItem]);
					
				if(menuItem == 0)
					menuAccordion.activate($$('#menuContainer .menuToggle')[0]);
				transitioning = false;								
			}
			catch(e)
			{
				alert('Woops... something went wrong! Please try again ' + e);
			}
		
		}