/*!
Custom dialog
 */
$(function() {
	PrimeFaces.widget.Dialog.prototype.setupDraggable = function() {
		var a = this;
		this.jq.draggable({
			cancel : ".ui-dialog-content, .ui-dialog-titlebar-close",
			handle : ".ui-dialog-titlebar",
			containment : a.cfg.absolutePositioned ? "document"
					: "window",
			stop : function(d, e) {
				if (a.hasBehavior("move")) {
					var b = a.cfg.behaviors.move;
					var c = {
						params : [ {
							name : a.id + "_top",
							value : e.offset.top
						}, {
							name : a.id + "_left",
							value : e.offset.left
						} ]
					};
					b.call(a, c)
				}
			}
		})
	}
}),
$(function() {
	PrimeFaces.widget.Dialog.prototype.setupResizable = function() {
		var $this = this;
		this.jq.resizable({
			handles : 'n,s,e,w,ne,nw,se,sw',
			minWidth : this.cfg.minWidth,
			minHeight : this.cfg.minHeight,
			alsoResize : this.content,
			containment : 'document',
			start : function(event, ui) {
				$this.jq.data('offset', $this.jq.offset());

				if ($this.cfg.hasIframe) {
					$this.iframeFix = $(
							'<div style="position:absolute;background-color:transparent;width:100%;height:100%;top:0;left:0;"></div>')
							.appendTo($this.content);
				}
			},
			stop : function(event, ui) {
				var offset = $this.jq.data('offset');

				$this.jq.css('position', 'fixed');
				$this.jq.offset(offset);

				if ($this.cfg.hasIframe) {
					$this.iframeFix.remove();
				}
				
				var headerH = $this.jq.find('.ui-dialog-titlebar.ui-widget-header').outerHeight(true);				
				var contentH = $this.jq.find('.ui-dialog-content.ui-widget-content').outerHeight(true);
				var footerH = $this.jq.find('.ui-dialog-footer.ui-widget-content').outerHeight(true);				
				var contentMarginAndPadding = contentH - $this.jq.find('.ui-dialog-content.ui-widget-content').height();				
				var contentHeight = $this.jq.outerHeight(true) - headerH - contentMarginAndPadding - footerH;				
				$this.jq.find('.ui-dialog-content.ui-widget-content').css('height', contentHeight + 'px');				
			}
		});
		
		this.resizers = this.jq.children('.ui-resizable-handle');		
	}
});