define([
	"dojo/_base/array", // array.forEach
	"dojo/_base/declare", // declare
	"dojo/dom", // dom.setSelectable
	"dojo/dom-construct",
	"dojo/dom-attr", // domAttr.set or get domAttr.remove
	"dojo/dom-class", // domClass.replace
	"dojo/dom-geometry", // domGeometry.setMarginBox domGeometry.getMarginBox
	"dojo/_base/event", // event.stop
	"dojo/fx", // fxUtils.wipeIn fxUtils.wipeOut
	"dojo/_base/kernel", // kernel.deprecated
	"dojo/keys", // keys.DOWN_ARROW keys.ENTER
	"dijit/_CssStateMixin",
	"dijit",
	"dijit/_WidgetBase",
	"dijit/TooltipDialog",
	"dijit/popup",
	"dijit/form/Button",
	"dojo/query"
], function(array, declare, dom, domConstruct, domAttr, domClass, domGeometry, event, fxUtils, kernel, keys,
			_CssStateMixin, dijit, _WidgetBase, TooltipDialog, popup, Button, query){


return declare("obno.widgets.DetailsDialog", [_WidgetBase], {
		isPopupContent : true,
		
		constructor: function(params){
			var tooltipDialog = new TooltipDialog({
			});
			var closeBtn = new Button({
				'class' : 'buttonLink', 
				style: 'float:right; font-size:x-small;', 
				title: 'close', 
				tabIndex: 0,
				label: "[close]",
				onClick : function(){
					popup.close(tooltipDialog);
				}
			});
		
			//find dijitTooltipContainer and append button node
			var container = null;
			query(".dijitTooltipContainer", tooltipDialog.domNode).forEach(function(node){
				container = node;
			});
			if (container){
				domConstruct.place(closeBtn.domNode, container, "first");
			}
			this.detailsDialog = tooltipDialog;
			this.currentController = null;
		},
		
		setContents : function(controller, view){
			if (this.detailsDialog.open){
				popup.close(detailsDialog);				
			}
			if (this.currentController)
			{
				this.currentController.destroy();
			}
			this.currentController = controller;
			if (!view._started){
				view.startup();
			}
			this.detailsDialog.set('content', view);
		},
		
		show : function(node){
			popup.open({
                popup: this.detailsDialog,
                around: node
            });
		}
	});
});