$(document).ready(function() {

	$('#admin-panel').hide();
	$('#admin-panel').slideDown(600);
	$('#login-button').click(function() {
		$('#admin-panel').slideUp(600);
		$(this).parent().submit();
	});
	$('#admin-panel > #content > a').click(function() {
		$('#admin-panel').slideUp(600);
		document.location = $(this).attr('href');
	});
	
	$('.subnav').hide();
	$('.active').parent().find('.subnav').show();
	
	function activateMenu(name, href) {
		var sel = '.'+name;
		if(!$(sel).hasClass('active')) {
			$('#mm > a').removeClass('active');
			$('.lnav').removeClass('active').parent().find('.subnav').slideUp(300);
			$(sel).addClass('active').parent().find('.subnav').slideDown(300, function() { document.location = href; });
		}		
	}
	
	$('.lnav').click(function() { activateMenu($(this).attr('title'), $(this).attr('href')); });
	$('#mm > a').click(function() { activateMenu($(this).attr('title'), $(this).attr('href')); });
	
	// Expander
	
	$('.toexpand').hide();
	
	$('.expander').click(function() { $('.toexpand').fadeIn(); return false; });
	
	function getExpanderContent(c) { return $('#'+$(c).attr('id')+'_content'); }
	
	$('.expandable').each(function() {
		getExpanderContent(this).hide();
		$(this).css('cursor', 'pointer');
	});
	
	$('.expandable').click(function() {
		var c = getExpanderContent(this);
		if(c.hasClass('open')) {
			c.removeClass('open');
			c.slideUp();
		} else {
			c.addClass('open');
			c.slideDown();			
		}
	});
	
});
