var hmenu = $.Class.create({

	node: null,
	wait: 0,

	initialize: function( node ) {

		this.node = node;
		this.wait = 0;

	},

	start: function () {

		var mthis = this;

		this.node.find('a').mouseover( function( event ) {

			mthis.show($(event.currentTarget.parentNode));

		});

		this.node.find('a').mouseout( function( event ) {

			mthis.wait = setTimeout(function(){mthis.hide()}, 500);

		});

	},

	show: function ( option ) {

		clearTimeout(this.wait);

		option.parent('ul').find('ul').css('visibility','hidden');
		option.parent('ul').find('ul').hide();

		if ( option.parent('ul').is(':first-child') ) {

			option.parent('ul').children('li.open').removeClass('open');
			option.addClass('open');

		}

		option.children('ul').css('visibility','visible');
		option.children('ul').show();

	},

	hide: function () {

		this.node.children('ul').find('ul').css('visibility','hidden');
		this.node.children('ul').find('ul').hide();
		this.node.children('ul').children('li.open').removeClass('open');

	}

});

