document.observe('dom:loaded', function () {
	if ($$('#side_content .areas').first()) {
		var areas = $$('#side_content .areas').first(),
			menu = areas.down('ul'),
			items = menu.select('li > a'),
			submenu = menu.select('ul');
	
		submenu.invoke('wrap', 'div', { className: 'submenu' }).invoke('hide');
		
		var window_location, window_folder, window_file, window_location_regex = /\/([^\/]+?)\/([^\/]+?)\.asp/;
		window.location.href.gsub(window_location_regex, function (match) {
			window_location = match[0];
			window_folder = match[1];
			window_file = match[2];
		});
		
		items.each(function (item) {
			item.readAttribute('href').gsub(window_location_regex, function (match) {
				if (window_folder === match[2]) {
					if (item.next('div.submenu')) {
						item.next('div.submenu').show();
					}
				}
				
				if (window_folder === match[1] && window_file === match[2]) {
					if (item.up('div.submenu')) {
						item.up('div.submenu').show();
					} else if (item.next('div.submenu')) {
						item.next('div.submenu').show();
					}
					item.addClassName('selected');
				}
			});
		});
		
	
		/*items.invoke('observe', 'click', function (event) {
			// ‘this’ means the link we have clicked on
			Try.these(
				function () { Effect.toggle(this.next('div.submenu'), 'blind', { duration: 0.5 }); event.stop(); }.bind(this),
				function () { this.next('div.submenu').show(); }.bind(this)
			);
		});*/
	}
});
