(function() {

    YAHOO.namespace("OPS");
    YAHOO.OPS.popup = {};

    var Dom = YAHOO.util.Dom,
	Event = YAHOO.util.Event;

    opsPopupInit();

    YAHOO.OPS.popup.init = function(opts) {
	popupopts = {
	      btnID: 'ops_popup_toggle'
	    , name: 'ops_popup'
	    , overlayCorner: 'tl'
	    , contextCorner: 'bl'
	};

	var debugout = 'popup=';
	for(var opt in popupopts) {
	    if(typeof opts[opt] != 'undefined') {
		debugout += opt+'='+opts[opt]+"\n";
		popupopts[opt] = opts[opt];
	    }
	}
	opsDebug(debugout);

	var btnID = popupopts['btnID'];
	var popupName = popupopts['name'];
	if(typeof(YAHOO.OPS.popup[popupName]) == 'undefined') {
	opsDebug('make '+popupName);
	    YAHOO.OPS.popup[popupName] = new YAHOO.widget.Panel(popupName, {
		  visible:false
		, draggable:false
		, constraintoviewport:true
		, context:[btnID,popupopts['overlayCorner'],popupopts['contextCorner'], ["beforeShow", "windowResize"]] } );
	    YAHOO.OPS.popup[popupName].render();
	}
	YAHOO.util.Event.addListener(btnID, "click", opsPopupToggle, YAHOO.OPS.popup[popupName]);
    }

}());

