var Menu = {
	init: function() {
		$$("#mainmenu ul li + ul").each(function(el) {
			link = new Element('a', {'href':'javascript:;', 'class':'expandable', 'html':el.getPrevious().get('text')});
			link.inject(el.getPrevious().set('html',''));
			el.addClass('expandable');
			el.getPrevious().addEvent('click', function() {
				el.toggle();
			});
			el.hide();
		});
		
		loc = window.location.toString().replace(new RegExp("http://[^/]*","g"), '');
		links = $$("#mainmenu ul li a[href="+loc+"]");
		
		while(links.length == 0 && loc.length > 0) {
			loc = loc.replace(new RegExp("/[^/]*$","g"), '');
			links = $$("#mainmenu ul li a[href="+loc+"]");
		}
		
		links.each(function(link) {
			path = [link];
			
			link.getParent("li").addClass("currentpath");
			link.getParents("ul.expandable").each(function(list) {
				path.push(list.getPrevious().getElement('a'));
				list.getPrevious().addClass("currentpath");
				list.show();
			});
			
			var head = $('topleftmenu');
			path.reverse().each(function(l) {
				head.appendText(' » ');
				l.clone().inject(head);
			});
		});
	}		
}

var Blogmenu = {
	init: function() {
		$$("div.blogmenu>ul>li").each(function(elem) {
			var list = elem.getElement('ul');
			var myFx = new Fx.Slide(list, {duration:200}).hide();
			elem.addEvents({
				'mouseenter' : function(){
					myFx.cancel();
					myFx.slideIn();
				},
				'mouseleave' : function(){
					myFx.cancel();
					myFx.slideOut();
				}
			});
		});
	}		
}

 
window.addEvent('domready', function() {
	if(window.location.toString().indexOf('admin') < 0) Menu.init();
	Blogmenu.init();
});

