var menu = Class.create();

menu.prototype = {
	initialize: function(menuID) {
		this.menu = $(menuID);
		this.main = $A(this.menu.getElementsByTagName('a'));
		this.sub = $A(this.menu.getElementsByTagName('dd'));
		this.main.each(this.setup.bind(this));
		this.sub.each(this.hide.bind(this));
	},
	hide: function(elm) {
		$(elm).addClassName('hidden');
	},
	show: function(elm) {
		if($(elm).hasClassName(this.className)) {
			$(elm).removeClassName('hidden');
		}
	},
	setup: function(elm) {
		if(elm.hasClassName('drop')) {
			Event.observe(elm,'click',this.activate.bindAsEventListener(this),false);
		}
	},
	activate: function(ev) {
		var elm = Event.findElement(ev,"a");
		Event.stop(ev);
		this.className = $(elm).href.match(/#(\w.+)/)[1];
		this.sub.each(this.hide.bind(this));
		this.sub.each(this.show.bind(this));
	}
}
var popup = Class.create();

popup.prototype = {
	initialize: function() {
		this.links = $A(document.getElementsByTagName('a'));
		this.links.each(this.setup.bind(this));
	},
	setup: function(elm) {
		if($(elm).hasClassName('external')) {
			Event.observe($(elm),'click',this.pop.bindAsEventListener(this),false);
		}
	},
	pop: function(ev) {
		var elm = Event.findElement(ev,'a');
		Event.stop(ev);
		window.open(elm.href,'_blank');
	}
}
if(window.attachEvent) {
	Event.observe(window,'load',function() {new popup(); new menu('menu');},false);
}
else {
	Event.observe(window,'DOMContentLoaded',function() {new popup(); new menu('menu');},false);
}