var menus = new Array();

function toggleMenuState(identity) {
	var menuLinks = document.getElementById('menuContent_'+identity);
	if (menuLinks.style.display == 'none') {
		menuLinks.style.display = 'block';
		document.getElementById('menuButton_'+identity).src = root_path+'_images/content_menu_collapse.png';
	} else {
		menuLinks.style.display = 'none';
		document.getElementById('menuButton_'+identity).src = root_path+'_images/content_menu_expand.png';
	}
}

function menuItem(url,caption) {
	this.url = url;
	this.caption = caption;
}

function addItem (url,caption) {
	this.menuItems[this.menuItems.length] = new menuItem(url,caption);
}

function render(currentPage) {
	
	var html = '';
	var link;
	var i;

	// Sections relating to the current page should be expanded, others collapsed
	// For default pages, all menu sections are expanded
	// Exception: The News and Features menu is too long to show fully expanded, so all sections on the default page are collapsed 
	
	var expanded = false;
	if (currentPage != 'features/default.php') {
		for (i = 0; i < this.menuItems.length; i++ ) {
			if ((this.menuItems[i].url == currentPage) || (currentPage.indexOf('default.php') != -1)) {
				expanded = true;
			}
		}
	} else {
		expanded = false;
	}
	
	html += '<div class="contentMenu">';
	html += '<h1>'+this.caption+'<img src="'+root_path+'_images/content_menu_'+((expanded) ? 'collapse' : 'expand' )+'.png" width=12 height=11 class="menuTreeButton" id="menuButton_'+this.identity+'" onclick="toggleMenuState(\''+this.identity+'\')" /></h1>';
	html += '<div class="contentMenuLinks" id="menuContent_'+this.identity+'" style=display:'+((expanded) ? 'block' : 'none' )+' />';
	
	for (i = 0; i < this.menuItems.length; i++ ) {
		link = this.menuItems[i].caption;
		if (i != this.menuItems.length-1) {
			linkClass = 'contentMenuLinkBordered'; 
		} else {
			linkClass = 'contentMenuLink'; 
		}
		if (this.menuItems[i].url == currentPage) {
			link = '<span style=color:black>'+link+'</span>';
		}
		link = '<div class="'+linkClass+'"><a href="'+root_path+this.menuItems[i].url+'">'+link+'</a></div>';
		html += link;
	}
	
	html += '</div>';
	html += '</div>';
	
	return html;

}

function menuSection(caption,identity) {
	this.caption = caption;
	this.identity = identity;
	this.menuItems = new Array();
	this.addItem = addItem;
	this.render = render;
}


