dojo.require("dojox.layout.FloatingPane");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.layout.StackContainer");
dojo.require("dojox.widget.Toaster");

/**
 * @author DREDroot
 *
 */
dojo.declare("dojom.classes.FloaterClass", null, 
{
	headerFloater: null,
	tabFloater: null,
	mySearchFloater: null,
	_floatersId:1,
	log: null,
	
	constructor: function ()
	{
		this.log = LOG.addClass('FloaterClass');
	},
	
	//create new floater
	createNewFloater: function(options, node)
	{
		var obj = this;
		if(options)
		{
			options.id = options.id != null ? options.id : "newFloater_"+_floatersId++;
			options.title = options.title != null ? options.title : "";
			options.dockable = options.dockable != null ? options.dockable : true;
			options.maxable = options.maxable != null ? options.maxable : true;
			options.closable = options.closable != null ? options.closable: options.closable;
			options.resizable = options.resizable  != null ? options.resizable : true;
			options.maxable = options.maxable != null ? options.maxable : false;
			options.resizeAxis = options.resizeAxis != null ? options.resizeAxis : "xy";
			options.dockTo = options.dockTo != null ? options.dockTo : "";
			options.duration = options.duration != null ? options.duration : 400;
			//options.style = options.style != null ? options.style : "position:absolute; ";
		}
		
		if(!node)
		{
			node = document.createElement('div');
			dojo.body().appendChild(node);
		}
				
		var tmp = new dojox.layout.FloatingPane(options,node);
		tmp.startup();
		/*
		if(options.dockable)
		{
			dojo.connect(tmp.dockTo,"addNode", function(){
					var r = obj.getGeometryOfFloater(tmp);
					if(r.t < 150)
					{
						tmp.resize({t:125});
					}
				});
		}*/
		
		if(options.resizable)
		{
			try{
				tmp.resize({t:250,l:250});
			}catch(ex){}
		}
		
		tmp.bringToTop();
		return tmp;
	},
	
	
	createFeedbackFloater: function(onSubmit,text)
	{	
		var obj = this;		
		try{
			return new dojom.widgets.FeedbackForm(onSubmit,text);
		}catch(ex){obj.log.error('createFeedbackFloater.'+ex)}
	},
	
	createSignInFloater: function(onSubmit, regWidget)
	{	
		var obj = this;	
		try{
			return new dojom.widgets.SignInForm(onSubmit,regWidget);
		}catch(ex){obj.log.error('createSignInFloater.'+ex)}
	},
	
	createRegistrationFloater: function(onSubmit)
	{	
		var obj = this;
		try{
			return new dojom.widgets.RegistrationForm(onSubmit);
		}catch(ex){obj.log.error('createRegistrationFloater.'+ex)}
	},
	
	createToaster: function()
	{
		try{
			var node = document.createElement('div');
			dojo.body().appendChild(node);
			var toaster = new dojox.widget.Toaster({id:'toast',positionDirection:'br-left',duration: 5000},node);		
			dojo.connect(toaster,'setContent',toaster,'show');

			
			return toaster;			
	   	}catch(ex){this.log.error('createToaster.'+ex)}
	},
	
	createEntityWindow: function()
	{
		try{
			var floater = dijit.byId('entityWindow');
			if(floater == null)
			{
				floater = new dijit.Dialog({
						id:"entityWindow",
						title:"Model",
						resizable: true
					},document.createElement('div'));				
				
				floater.setNewContent = function(object){
					var div = document.createElement('div');
				  	div.className='modalWindow';
				  	
					if(object.nodeName != null)		
						div.appendChild(object);
					else 
						div.appendChild(document.createTextNode(object));
					
					if(this.childDomNode != null)
						this.containerNode.replaceChild(div,this.childDomNode);
					else
						this.containerNode.appendChild(div);
					this.childDomNode = div;
					floater.show();
				};								
			}
			
			return floater;			
	   	}catch(ex){this.log.error('createEntityWindow.'+ex)}
	},
	
	createNewModalWindow: function(url,title)
	{
		try{
			floater = new dijit.Dialog({
				title:(title != null ? title : "Window"),
				resizable: true
			},document.createElement('div'));
			
			floater.containerNode.className = 'modalWindow';
			
			if(url != null && url !="")
				floater.setHref('lib/dojom/widgets/templates/'+url);
			
			floater.show();
			return floater;			
	   	}catch(ex){this.log.error('createNewModalWindow.'+ex)}
	},
	
	getGeometryOfFloater: function (floater)
	{			
		var tmp = {	t: parseInt(floater.domNode.style.top), 
					l: parseInt(floater.domNode.style.left), 
					h: parseInt(floater.domNode.style.height), 
					w: parseInt(floater.domNode.style.width)
					};		
		return tmp;
	},
	
	getWinSize: function () 
	{
		isNav = (document.all) ? false : true;
		isIE = (document.all) ? true : false;
		if (isNav && !isIE)
			return {w:window.innerWidth,h:window.innerHeight};
		else if (dojo.isIE)
			return {w:document.documentElement.clientWidth,h:document.documentElement.clientHeight};
		else if (dojo.isOpera)
			return {w:document.body.clientWidth,h:document.body.clientHeight};
		else 
			return({w:100,h:100});
	}
	
});
