function DDropMenu() {
	this.lists = new Array;

	this.addList = function(list) {
		this.lists.push(list);
	}
}

function DDropList(link, name) {
	this.link = link;
	this.name = name;
	this.links = new Array;

	this.addLink = function(link) {
		this.links.push(link);
	}
}

function DDropLink(link, name) {
	this.link = link;
	this.name = name;
}

window.onload = function() {
		var nav = document.getElementById('navigation');

		var fnMouseOver = function() {
			for (j=0; j<this.childNodes.length; j++) {
				subdiv = this.childNodes[j];
				//if (subdiv.nodeName=='DIV') {
				//	subsubdiv = subdiv.childNodes[0];
				if (subdiv.nodeName=="UL") {
					subdiv.style.display = 'block';
				}
			}
		}

		var fnMouseOut = function() {
			for (j=0; j<this.childNodes.length; j++) {
				subdiv = this.childNodes[j];
				//if (subdiv.nodeName=='DIV') {
				//	subsubdiv = subdiv.childNodes[0];
				if (subdiv.nodeName=="UL") {
					subdiv.style.display = 'none';
				}
			}
		}

		for (var i = 0; i < menu.lists.length; i++) {
			var div = document.createElement('div');
			div.onmouseover = fnMouseOver;
			div.onmouseout = fnMouseOut;
			var link = document.createElement('a');
			link.setAttribute('href',menu.lists[i].link);
			link.setAttribute('id','link'+i);
			link.appendChild(document.createTextNode(menu.lists[i].name));

			if (menu.lists[i].links.length > 0) {
				var ul = document.createElement('ul');
				for (var j = 0; j < menu.lists[i].links.length; j++) {
					var li = document.createElement('li');
					var lnk = document.createElement('a');
					lnk.setAttribute('href', menu.lists[i].links[j].link);
					lnk.appendChild(document.createTextNode(menu.lists[i].links[j].name));
					li.appendChild(lnk);
					ul.appendChild(li);
				}
				div.appendChild(ul);
			}

			div.appendChild(link);
			document.getElementById('navigation').appendChild(div);
		}
	}

var menu = new DDropMenu();
var lstHome = new DDropList('index.html','Home');
menu.addList(lstHome);

var lstProgramme = new DDropList('#','Programme');
lstProgramme.addLink(new DDropLink('lrb_programme.html','Buddhist Centre'));
lstProgramme.addLink(new DDropLink('cwh_programme.html','Centre for Whole Health'));
lstProgramme.addLink(new DDropLink('events_programme.html','Other Events'));
menu.addList(lstProgramme);

var lstNews = new DDropList('lrb_news.html','News');
menu.addList(lstNews);

var lstDownloads = new DDropList('#','Downloads');
lstDownloads.addLink(new DDropLink('downloads.html','Texts'));
lstDownloads.addLink(new DDropLink('publications.html','Publications'));
menu.addList(lstDownloads);

var lstAbout = new DDropList('#','About');
lstAbout.addLink(new DDropLink('lrb_history.html','History'));
lstAbout.addLink(new DDropLink('lrb_info.html','Buddhist Centre'));
lstAbout.addLink(new DDropLink('cwh_info.html','Centre for Whole Health'));
lstAbout.addLink(new DDropLink('dtt_info.html','Dharma Therapy Trust'));
lstAbout.addLink(new DDropLink('gya_house.html','Gya House'));
lstAbout.addLink(new DDropLink('btg_info.html','Bristol Tibet Group'));
menu.addList(lstAbout);

var lstCentres = new DDropList('#','Centres');
lstCentres.addLink(new DDropLink('http://www.lamrim.org.uk/','All Centres'));
lstCentres.addLink(new DDropLink('http://www.lamrim.org.uk/wales/','Wales'));
lstCentres.addLink(new DDropLink('http://www.lamrimwg.org.uk/','Wilts & Glos'));
lstCentres.addLink(new DDropLink('http://lamrim.co.za/','South Africe'));
menu.addList(lstCentres);

var lstContact = new DDropList('lrb_contact.html','Contact');
menu.addList(lstContact);

