var cookieOptions = {path: '/', domain: 'wyrmouroboros.com', secure: false};

function initMenus() {
	$('ul.menu ul').hide();
	
	$.each($('ul.menu'), function(){
		var cookie = $.cookie(this.id);
		var expandedMenu = $('a.expanded', $(this));
		if(expandedMenu.length>0)
			expandedMenu.next().show();
		else if(cookie!=null && String(cookie).length>0)
			$('#' + this.id + ' .' + cookie).next().show();
	});
	
	$('ul.menu li a').click(
		function() {

			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				if((String(parent).length > 0) && (String(this.className).length > 0)) {
					if($(this).next().is(':visible')) {
						$.cookie(parent, null, cookieOptions);
					}
					else {
						$.cookie(parent, this.className, cookieOptions);
					}
					$(this).next().slideToggle('fast');
				}				
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('fast');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('fast');
				if((String(parent).length > 0) && (String(this.className).length > 0)) {
					$.cookie(parent, this.className, cookieOptions);
				}
				checkElement.slideDown('fast');
				return false;
			}
		}
	);
}
$(document).ready(function() {
	try {
		initMenusLocal();
	} catch(ex) {
		initMenus();
	}
	
});

	function collapseAllMenu1SlideToggles()
{
	$('#menu1 > li > a').each(function(){
		var checkElement = $(this).next();
		var parent = this.parentNode.parentNode.id;

		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$('#' + parent + ' ul:visible').slideUp();
		}
	});
}





