
	// mode = {'standard', 'transparent'}
	function dialog(caption, mode)
	{
		if(mode == undefined) mode = 'standard';
		
		dialog.parentClass.constructor.apply(this, arguments);
		
		var protoElement = document.getElementById('window_'+ mode +'_prototype');
		this.element = protoElement.cloneNode(true);
		this.element.removeAttribute('id');
		protoElement.parentNode.appendChild(this.element);

		this.window = $(this.element).find(".dialog").get(0);
		this.window.dialog = this;
		
		this.closeButton = $(this.window).find(".closeButton").get(0);
		this.captionContainer = $(this.window).find(".captionContainer").get(0);
		this.contentContainer = $(this.window).find(".contentContainer").get(0);

		if(caption !== undefined) this.setCaption(caption);
		else $(this.captionContainer).addClass('hidden');
		
		this.closeButton.dialog = this;
		this.closeButton.onclick = function() {this.dialog.close(); };

		this.captionContainer.onmousedown = function(event)
		{
			this.dialog.oldX = (window.event) ? window.event.clientX : event.pageX;
			this.dialog.oldY = (window.event) ? window.event.clientY : event.pageY;
		};

		this.captionContainer.onmouseup = function(event)
		{
			this.dialog.oldX = undefined;
			this.dialog.oldY = undefined;
		};		
		
		this.captionContainer.onmousemove = function(event)
		{
			if(this.dialog.oldX && this.dialog.oldY)
			{
				var x = (window.event) ? window.event.clientX : event.pageX;
				var y = (window.event) ? window.event.clientY : event.pageY;
			
				this.dialog.captionContainer.style.top = (this.dialog.captionContainer.offsetTop + y - this.dialog.oldY) + 'px';
				this.dialog.captionContainer.style.left = (this.dialog.captionContainer.offsetLeft + x - this.dialog.oldX) + 'px';
				
				this.dialog.oldX = x;
				this.dialog.oldY = y;
			}
		}

		this.window.fading = new fading(this.window);
		this.window.fading.value = 0;
	}

	extend(dialog, control);

	dialog.prototype.destroy = function()
	{
		this.window.dialog = undefined;
		this.element.parentNode.removeChild(this.element);
		dialog.parentClass.destroy.apply(this, arguments);
	}

	dialog.prototype.getType = function()
	{
		return 'dialog';
	}

	dialog.prototype.caption;
	dialog.prototype.closeButton;
	dialog.prototype.contentContainer;
	dialog.prototype.autoDestroy = false;

	// content - DOMFragment
	dialog.prototype.setContent = function(content) 
	{
		$(this.contentContainer).empty().append(content);
	}

	dialog.prototype.setCaption = function(caption)
	{
		this.caption = caption;
		$(this.captionContainer).empty().append(caption);
	}

	dialog.prototype.open = function(left, top)
	{
		document.eventer.forceEvent('onDialogOpen', {dialog: this})
	
		if(top == undefined) top = getScrollOffset().top;
		this.window.style.top = top + 'px';
		if(left != undefined) this.window.style.left = left + 'px';

		$(this.element).fadeIn('normal');
	}

	dialog.prototype.isOpen = function()
	{
		return !this.isHidden();
	}

	dialog.prototype.close = function()
	{
		document.eventer.forceEvent('onDialogClose', {dialog: this})
		
		var dialog = this;
		var autoDestroy = function() { if(dialog.autoDestroy) dialog.destroy(); }
		$(this.element).fadeOut('fast', autoDestroy);
	}
