﻿// Depends on cookies.js for getCookie() & setCookie();
// Depends on JSON2.js for JSON.stringify();
// Container for persistence values. Starts empty.
// Keys are the text of the expander links. Values are "hide" or "show"
var phdmenus = { };

if (getCookie("menu") != "") {
	jQuery.extend(phdmenus,jQuery.parseJSON(getCookie("menu")));
} else {
	setCookie("menu",JSON.stringify(phdmenus),30);
}

var phdmenu_init = function(){
	jQuery('.menu a.expander').each(function(){
		// hide if not there or explicitly set
		if (phdmenus[jQuery(this).text()] != "show"){
			jQuery(this).next().hide();
		} else {
			jQuery(this).next().show();
		}
	});
};

jQuery(document).ready(function($) {
	// Bind to the expander links.
	$('.menu a.expander').bind('click',function(){
		var latestmenu = $.parseJSON('{ "' + $(this).text() + '" : "' + ($(this).next().is(":visible") ? "hide" : "show") + '" }');
		$(this).next().slideToggle();
		$(this).blur();	// Remove focus from clicked item.
		$.extend(phdmenus,latestmenu);
		setCookie("menu",JSON.stringify(phdmenus),30);
	});

});
