$.maxZIndex = $.fn.maxZIndex = function(opt) {
	var def = { inc: 10, group: "*" };
	$.extend(def, opt);    
	var zmax = 0;
	$(def.group).each(function() {
		var cur = parseInt($(this).css('z-index'));
		zmax = cur > zmax ? cur : zmax;
	});
	if (!this.jquery)
		return zmax;

	return this.each(function() {
		zmax += def.inc;
		$(this).css("z-index", zmax);
	});
}

$.cmglossary = $.fn.cmglossary = function() {
	this.each(function() {
		var _ground = this;
		
		_ground.init = function() {
			$('.box', _ground).hide().removeClass("active");
			$('.close', _ground).click(function() {
				$('.box', _ground).hide().removeClass("active");
				return false;
			});
			$('li', _ground).each(function() {
				var _self = $(this);
				$('a.glossary',_self).click(function() {
					var boxes = $('.box', _ground);
					var box = $('.box', _self);
					var active = $('.active', _self);
					
					if (active.length > 0) {
						boxes.removeClass("active").hide();
					} else {
						boxes.removeClass("active").hide();
						box.addClass("active").show().maxZIndex();
						$('a', _ground).maxZIndex();
					}
					return false;
				});
			});
		}

		_ground.init();
	});
}
