var JQ = jQuery.noConflict();

function initMenus() {
	JQ('ul.menu ul').hide();
	JQ.each(JQ('ul.menu'), function(){
		var cookie = JQ.cookie(this.id);
		if(cookie === null || String(cookie).length < 1) {
			JQ('#' + this.id + '.expandfirst ul:first').show();
		}
		else {			
			JQ('#' + this.id + ' .' + cookie).next().show();
		}
	});
	JQ('ul.menu li a').click(
		function() {

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

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


