// jq_popup.js

var gPopupDiv;

//------------------------------------------------------------
$.fn.popup = function(o)
	{
	var popup = $(this);
	popup.bind("contextmenu", function(e){
		popup.popupKill();
		gPopupDiv = $(_div).addClass("popup")
		.css({top:e.pageY, left:e.pageX});

		for (i=0; i<o.items.length; ++i)
			{
			var itm = o.items[i];
			$(_div).addClass("popupItem")
			.css({top:i*17}).html(itm.label)
			.attr("i",i)
			.hover(function(){$(this).addClass("popupHilite");},
				function(){$(this).removeClass("popupHilite")})
				.bind("mousedown",function(){return false;})
			.bind("click", function()
				{
				o.items[$(this).attr("i")].click();
				$(".cover").remove();
				popup.popupKill();
				return false;
			})
				.appendTo(gPopupDiv);
			$("<br>").appendTo(gPopupDiv);
			}
		if (o.width) gPopupDiv.css({width:o.width});
		gPopupDiv
		.css({height:o.items.length*16})
		.appendTo($(_div).cover());
		return false;
	});
	return $(this);
	}
//------------------------------------------------------------
$.fn.popupKill = function()
	{
	if (gPopupDiv) {
		gPopupDiv.remove();
		gPopupDiv = undefined;
	}
	}