Element.implement({
	addGreedyEvent : function(type, fnc){
		var target = this;
		this.addEvent(type,function(e){
			var a = new Event(e);
			a.target=target;
			fnc(a);
		})
	}
})
var Menu = new Class({
	initialize: function(url){
		
		$$( '.sub_menu' ).each(function( item, index )
		{			
			item.setStyle('display','none');
			item.getParent().addGreedyEvent( 'mouseenter', this.showMouseOverEffect.bind( this ) );
			item.getParent().addGreedyEvent( 'mouseleave', this.hideMouseOverEffect.bind( this ) );
		}.bind(this));
	},
	showMouseOverEffect : function ( e ) {
		e = e.target;
		e.getChildren('ul')[0].setStyle('display','block');


		// THIS IS JUST A HACK TO GET AROUND IE 6
		// IT LOOKS UP PARENT AND THENTHE NEXT CHILD AND DOES A MARGIN TOP

		if (Browser.Engine.trident && Browser.Engine.version <= 4) {
			var pntParentChildren = e.getParent().getChildren();
			pntParentChildren[pntParentChildren.indexOf(e)+1].setStyle('margin-top','-3px');
		}

	},
	hideMouseOverEffect : function ( e ) {
		e = e.target;
		e.getChildren('ul')[0].setStyle('display','none');
		
		// THIS IS JUST A HACK TO GET AROUND IE 6
		// AS ABOVE BUT IT REVERTS BACK TO NO MARGIN ONT HE NEXT CHILD

		if (Browser.Engine.trident && Browser.Engine.version <= 4) {
			var pntParentChildren = e.getParent().getChildren();
			pntParentChildren[pntParentChildren.indexOf(e)+1].setStyle('margin-top','0');
		}

	}
});


