$(document).ready(function(){
	mintext = "Minimize";
	maxtext = "Expand";
	$("div.lever > span.hlink").click(function(){
		$this = $(this);
		$thisparent = $this.parent();
		boxname = $thisparent.siblings("h3").text();
		if ($thisparent.is(".up")) $this.text(maxtext).after(' <span class="boxname">'+boxname+'</span>');
		else $this.text(mintext).siblings("span.boxname").remove();
		$thisparent.toggleClass("up").siblings().slideToggle();
		$thisparent.parent().toggleClass("maximized");
	});
	$expander = $("span.hlink:contains("+maxtext+")");
	if ($expander.length && !$expander.siblings("span.boxname").length) {
		exptext = $expander.parent().siblings("h3").text();
		$expander.after(' <span class="boxname">'+exptext+'</span>');
		$expander.parent().parent().slideDown();
	}
	$("ul.menulist > li").bind("mouseenter", m_open).bind("mouseleave", m_timer);
	$("ul.dropdown > li").bind("mouseenter mouseleave", function(){$(this).toggleClass("over");});
});
$(window).resize(function(){
	
});

var timeout = 500;
var closetimer = null;
var dropbox = null;
function m_open(){
	m_item = $(this);
	m_canceltimer();m_close();
	m_item.addClass("droped");
	dropbox = m_item.children(".dropdown")
	dropbox.css('left',20+m_item.children("a:first-child").width()).show();
}
function m_close(){
	if(dropbox) {
		m_item.siblings().removeClass("droped");
		dropbox.hide();
	}
}
function m_timer(){
	closetimer = window.setTimeout(m_close, timeout);
}
function m_canceltimer(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
