// dynMenu
// =====================================================
// author: jon hopewell [digitalsweetspot@gmail.com]
//
// - provides a dynamic menu, based on click action
// * depends on jQuery being installed
// =====================================================
$(document).ready(function(){

	var obj = '#block-menu-menu-store-nav ul.menu';				// sets the top level parent ul which will act as the main nav object
	var active = 'active';																// class identifier for active list item - used to trigger constant visibility of its child 'ul'
	var speed = '';																				// sets the speed at which the sub-menus are exposed/hidden

	if ($(obj)) {

		function dynMenu() {
			$(obj + ' ul').hide();														// hide all of the sub-menu ul's
		  $(obj + ' li.' + active + ' ul:first').show();		// now, show the active one
			$(obj + ' li a').click(function() {								// since we click on a link, do something
				var checkElement = $(this).next();							// check the next element from what we clicked
				var checkElementParent = $(this).parent();			// check the parent element of what we clicked
				if(checkElement.is('ul')) {											// if the next element is a 'ul'
					if (!checkElementParent.hasClass(active)) {		// and the clicked link's parent is not marked as 'active'
						checkElement.toggle(speed);									// toggle the display of the next element
						return false;																// return false so you don't actually visit a link
					} else {																			// otherwise...
						return false;																// simply return false, since we always want the 'active' element to be displayed
					}
				}
			});
		}
	
		dynMenu();
	
	}

});
