Submenu = function()
{
	this.menus=null;

	this.init();
}
Submenu.isBlubath = true;
$pr = Submenu.prototype;
$pr.init=function()
{
	// set up the variables
	this.menus = $('ul.submenu');
	
	// set up the click callback
	this.menus.click(function(e)
	{
		var rtn = blubathobj.getObject('Submenu').clickCallback(e);
		return rtn;
	});
}
$pr.clickCallback = function(e)
{
	var tar = $(e.target);
	var ownerli = null;
	var ownerul = null;
	
	// check if the target is an anchor
	if(tar.attr('nodeName').toLowerCase() == 'a')
	{
		ownerli = $(tar.parent('li'));
		ownerul = $(ownerli.parent());
		
		// check if the ownerul is actually a ul (and the correct UL)
		if(ownerul.attr('nodeName').toLowerCase() == 'ul' && ownerul.hasClass('submenu'))
		{
			// check the type of submenu
			// if we're an accordion submenu
			if(ownerul.hasClass('accordion'))
			{
				// if the selected li element is already selected, do nothing
				if(ownerli.hasClass('unhandled'))
				{
					return true;
				}/* else if(ownerli.hasClass('sel'))
				{
					return false;
				}*/
				// if the currently selected li element does not contain a submenu, just go to the page (return true)
				if($('ul',ownerli).length == 0 && !ownerli.hasClass('handled'))
				{
					return true;
				}
				// slide up any previously selected items
				var toopen = $('>div.tertiary',ownerli);
				var toclose = $('>li.sel div.tertiary',ownerul);
				
				toopen.slideDown(0);
				var deptha = toopen.height() * 4;
				var depthb = toclose.height() * 4;
				toopen.slideUp(0);
				
				toclose.slideUp(depthb, 'easeInOutCirc');
				// also close any menus further down the chain
				$('li.sel div.tertiary',toclose).slideUp({duration: depthb, easing: 'easeInOutCirc', queue: false, complete: function() { $(this).parent('li.sel').removeClass('sel').children('.sel').removeClass('sel'); }});
				
				// finally, slide down the submenu and set the menu item to selected
				toopen.slideDown(deptha, 'easeInOutCirc');
			} else
			{
				return true;
			}
			
			$('>li.sel',ownerul).removeClass('sel');
			$('>li.sel a.sel',ownerul).removeClass('sel');
			ownerli.addClass('sel');
			$('>a',ownerli).addClass('sel');
		} else
		{
			return true;
		}
	} else
	{
		return true;
	}
	
	// blur the target
	tar.blur();
	
	return false;
}

delete $pr;