
if (typeof isHomepage == 'undefined') isHomepage = false;

window.addEvent('domready', function() {

	//mhb added
	var menuItems = $$('#menu-navigation > li');
	for (var i=0; i<menuItems.length; i++) {
		var curMenuItem = menuItems[i];
		var hasSubmenu = false;
		for (var j=0; j<curMenuItem.childNodes.length; j++) {
			if (curMenuItem.childNodes[j].tagName == 'UL') {
				hasSubmenu = true;
				curMenuItem.firstChild.setAttribute('href', '#');
				break;
			}
		}
		if (hasSubmenu) curMenuItem.addClass('hasSubmenu');
	}
	
	var navMenuAccordion = new Fx.Accordion(
		$$('#menu-navigation > li.hasSubmenu'), $$('#menu-navigation > li.hasSubmenu > ul'),
		{
			opacity:true,
			display: -1,
			duration: 300,
			alwaysHide: true,

			onActive: function(menuheader, menucontent){
				menuheader.setStyle('font-weight', 'bold');
			},
			onBackground: function(menuheader, menucontent){
				menuheader.setStyle('font-weight', 'bold');
			}	
		}
	);

	$('menu').setStyle('display', 'block');

	//original code from template - still used for main body and links menu
	//modified to use newer version of MooTools

	var myAccordion = new Fx.Accordion($$('#menu > h2.menuheader'), $$('#menu > div.menucontent'), {
	opacity:true,
	display: -1,
	duration: 300,
	alwaysHide: true,

			onActive: function(menuheader, menucontent){
				menuheader.setStyle('font-weight', 'bold');
			},
			onBackground: function(menuheader, menucontent){
				menuheader.setStyle('font-weight', 'bold');
			}
	});

	//mhb added
	if (isHomepage && curPageNum==1) var displayID = 0;  //for the homepage, show the first item by default
	else var displayID = - 1; //collapse all accordion items by default

	if ($$('#maincol > .contentheader').length>0 && $$('#maincol > div.content').length>0) {
		var myAccordion2 = new Fx.Accordion($$('#maincol > .contentheader'), $$('#maincol > div.content'), {
		opacity:true,
		display: displayID,
		duration: 300,
		alwaysHide: true,

				onActive: function(contentheader, content) {
					//setAttribute('href', '#');
					contentheader.setStyle('font-weight', 'bold');
				},
				onBackground: function(contentheader, content){
					contentheader.setStyle('font-weight', 'bold');
					$$('#maincol .reveal').setStyle('display', 'none');
				}
		});
	}

	//mhb added
	$('maincol').setStyle('display', 'block');
	$('footer').setStyle('display', 'block');

	if (isHomepage) {
		//because the MooTools accordion provides no event for when it's done loading,
		//we set a timeout to change the heights of the posts (i.e. truncate them) and add read more links
		setTimeout(function() {
			initHomepage();
		}, 1200);
	}
//	else if (isWorksPage) {
//		setTimeout(function() {
//			initWorksPage();
//		}, 1200);
//	}

});
