function DialogInterface(params) { // CPopupInterface
	var	self = this,
		uiWindowContainer = (this.uiWindowContainer = $('#' + params['container'])),
		uiWindowTitlebar = $('#' + params['titlebar']),
		uiWindowTitlebarClose = $('#' + params['closebutton']),
		uiWindowContent = $('#' + params['content']),
		coord = (this.coord = [0, 0]),
		containerClass = params['containerClass'];
		isOpen = (this.isOpen = false),
		deltaX = (this.deltaX = params['dx']),
		deltaY = (this.deltaY = params['dy']);
				
    ((typeof(params['dx'])=='undefined') && (this.deltaX = 15));
    ((typeof(params['dy'])=='undefined') && (this.deltaY = 15));		
    
		
	(containerClass && uiWindowContainer.addClass(containerClass));
	
	if(uiWindowTitlebarClose.length > 0) {
		uiWindowTitlebarClose.click(function(){
								self.close();
								return false;
							}).mousedown(function(ev) {
								ev.stopPropagation();
							});
	}	
}

DialogInterface.prototype = {	
	open : function(align) {
		this._position(align);
		this.uiWindowContainer.css({ display: 'block' });
		this.isOpen = true;
	},

	close : function() {
		this.uiWindowContainer.css({ display: 'none' });
		this.isOpen = false;
	},
	
	setCoord : function(x, y) {
		this.coord[0] = x;
		this.coord[1] = y;
		return this;
	},
	
	_position: function(pos) {
		var wnd = $(window), doc = $(document),
			pTop = doc.scrollTop(), pLeft = doc.scrollLeft(),
			minLeft = pLeft, maxLeft = minLeft + ($.browser.opera ? window.innerWidth : wnd.width()), 
			minTop = pTop, maxTop = minTop + ($.browser.opera ? window.innerHeight : wnd.height()),
			containerWidth = this.uiWindowContainer.outerWidth(), containerHeight = this.uiWindowContainer.outerHeight();

		if ($.inArray(pos, ['center','top','right','bottom','left']) >= 0) {
			pos = [
				pos == 'right' || pos == 'left' ? pos : 'center',
				pos == 'top' || pos == 'bottom' ? pos : 'middle'
			];
		}
		
		pLeft += this.coord[0];
		switch (pos[0]) {
			case 'left':
				pLeft -= containerWidth;
				break;
			case 'right':
				pLeft += 0;
				break;
			default:
			case 'center':
				pLeft -= containerWidth / 2;
			break;
		}

		pTop += this.coord[1];
		switch (pos[1]) {
			case 'top':
				pTop -= containerHeight;
				break;
			case 'bottom':
				pTop += 0;
				break;
			default:
			case 'middle':
				pTop -= containerHeight / 2;
		}
		
		if(pLeft + containerWidth > maxLeft)
			pLeft = maxLeft - containerWidth - this.deltaX;
		
		if(pTop + containerHeight > maxTop)
			pTop = maxTop - containerHeight - this.deltaY;

		pTop = Math.max(pTop, minTop);
		pLeft = Math.max(pLeft, minLeft);
		this.uiWindowContainer.css({top: pTop, left: pLeft});
	}
}
