jQuery(document).ready(function() {
	// main menu
	jQuery("ul#menu li a").each(function() {
		jQuery(this).click(function() {
			if(jQuery(this).next('ul').css("display") == "none")
				closeAllMenus();
			
			jQuery(this).next('ul').toggle();
		});
	});
	jQuery("ul#menu ul li a").each(function() {
		jQuery(this).unbind("click");
		jQuery(this).click(function() {
			closeAllSubMenus();
			jQuery(this).next('ul').toggle();
		});
	});
	

	// contact expandable	
	var contactHeight = jQuery('#content').height() - jQuery('#sidebarTop').height() - 71 - jQuery('#contact').height();
	if(contactHeight < 0){
		contactHeight = 0;
	}
	jQuery('#sidebarBottom').css('margin-top',contactHeight+'px' );
	jQuery('h2.expand').parent('#sidebarBottom').css('margin-top', (contactHeight + jQuery('#contact').height()) + 'px')
	jQuery("h2.expand").each(function() {
		jQuery(this).click(function() {
			jQuery(this).next('.hide').toggle();
			
			if(jQuery(this).next('.hide').css('display') == 'block'){
				jQuery(this).parent('#sidebarBottom').css('margin-top', contactHeight +'px');
			}
			else{jQuery(this).parent('#sidebarBottom').css('margin-top', (contactHeight + jQuery('#contact').height()) + 'px')}
			//alert(jQuery('#contact').height());
			
		});
	});
	jQuery('div#content').css('height',jQuery('#sidebar').height() + 'px');
});

function closeAllMenus() {
	jQuery("ul#menu ul").each(function() {
		jQuery(this).hide();
	});
}
function closeAllSubMenus()
	{
		jQuery("ul#menu ul ul").each(function() {
		jQuery(this).hide();
	});
}
