(function($){
$.fn.VMenu = function(options) {
	var settings = {
		prefix : 'VM',
		_id : 'VMenu'
	};
	if (options) {
		$.extend(settings,options);
	}
	var m = {
		disable_expand : 0,
		expand : function (o){
			var s = $(o).find("span:first"),u = $(o).find("ul:first"),p = $(o).parent();
			if ($(o).attr('class') == 'mItem' || $(o).attr('class') == 'mLabel'){
				$(u).show();
				this.remove_class($(s));
				this.class_expand($(s));
			}
			if ($(p).attr('id') != settings._id){
				this.expand(p);
			}
		},
		remove_class : function (o){
			$(o).removeClass(settings.prefix + '_expand');
			$(o).removeClass(settings.prefix + '_collapse');
		},
		class_expand : function (o){
			if ($(o).hasClass(settings.prefix + 'spacer')) return;
			$(o).addClass(settings.prefix + '_expand');
		},
		class_collapse : function (o){
			if ($(o).hasClass(settings.prefix + 'spacer')) return;
			$(o).addClass(settings.prefix + '_collapse');
		}
	};
	$("#" + settings._id + " span[class^='" + settings.prefix + "_']").click(function(){
		if (m.disable_expand == 1) return;
		$(this).parent().find("ul:first").toggle();
		m.remove_class($(this));
		if ($(this).parent().find("ul:first").is(":visible")){
			m.class_expand($(this));
		}else{
			m.class_collapse($(this));
		}
	});
	if ($("#" + settings._id + " a#thispage").length > 0){
		m.expand($("#" + settings._id + " a#thispage").parent());
	}
	$("#" + settings._id + " a.menu").click(function(){m.disable_expand = 1;});
}
})(jQuery);

