// JavaScript Document
$(document).ready(function () {
	// Hide all of the sub-menus
	$("ul[title='navigation'] li ul").hide();
	
	// Apply the heading styling
	$("ul[title='navigation'] li:has(ul)").attr("class", "nav-heading");
	$("ul[title='navigation'] li:has(ul) a").attr("class", "unexpanded");
	// Apply the normal styling
	$("ul[title='navigation'] li:not(:has(ul))").attr("class", "nav-normal");
	
	// Set the heading expansion behavior
	$("ul[title='navigation'] li:has(ul)").click(function() { 
		// Expand the clicked list.
		$(this).children("ul").slideDown("slow");
		$(this).children("a").attr("class", "expanded");
		
		// Get a list of all previously expanded lists at the same level.
		var idx = $(this).parent().children().index(this);
		var query = "li:not(:eq(" + idx + ")):has(ul)";
		var prevExpList = $(this).parent().children(query);
		// Hide them and their children.
		for (var i = 0; i < prevExpList.length; i++) {
			$("li:eq(" + $("li").index(prevExpList[i]) + ") ul").slideUp("slow");
			$("li:eq(" + $("li").index(prevExpList[i]) + ") a").attr("class", "unexpanded");
		}
	});
	
	// Scan the navigation to see if there is a submenu which should be
	// opened for this page.
	var modPath = window.location.pathname;
	if (modPath[modPath.length - 1] == '/')
		modPath += "index.shtml";
	var results = $("ul[title='navigation'] li a[href$='" + modPath + "']");
	if (results.length > 0) {
		var curParent = results.parent().parent();
		// Iterate through it's parents making them visible.
		while (curParent.attr('title') != 'navigation' || curParent[0].tagName != "UL"){ 
			curParent.show();
			// If the current parent is a list which should be expanded change its style.
			if (curParent.attr('class') == 'nav-heading')
				curParent.children("a").attr("class", "expanded");
			// Go to the next parent up.
			curParent = curParent.parent();
		}
		// Make its children visible and expand this link
		results.attr("class", "expanded");
		results.parent().children("ul").show();
	}
	
// C O D E   FOR Drawer Sliders on h3 class="slider" and div class="drawer"	
	  // hide all divs inside   except the first one
  		$('div.drawer:not(:first)').slideUp('slow');   
		//$('div.drawer').slideUp('slow');   
  // apply the open class
  		$('div.drawer:first').addClass('open'); 
  		$('h3.slider').click(function () {
    // hide the currently visible drawer contents
    	  $('div.drawer:visible').slideUp('slow');    
    // remove the open class from the currently open drawer
    	  $('h3.open').removeClass('open').removeClass('expanded').addClass('unexpanded');    
    // show the associated drawer content to 'this' (this is the current H3 element)
    // since the drawer content is the next element after the clicked H3, we find
    // it and show it using this:
    	  $(this).next().slideDown('slow');
    
    // set a class indicating on the H3 that the drawer is open
    	  $(this).addClass('open expanded');
  });
});