/**
	Kailash Nadh,	http://kailashnadh.name
	August 2009
	Smooth popup dialog for jQuery

	License:	GNU Public License: http://www.fsf.org/copyleft/gpl.html
	
	v1.2	September 2 2009
**/

var jqDialog = new function() {

	//________
	this.closeTimer = null;
	this.width = 0; this.height = 0;
	
	this.divBoxName =	'jqDialog_box';	this.divBox = null;
	this.divContentName =	'jqDialog_content';	this.divContent = null;
	this.divOptionsName = 'jqDialog_options'; this.divOptions = null;



	
	//________create a dialog with custom content
	this.content = function(content, close_seconds) {
		this.createDialog(content);
		this.divOptions.hide();
	};

	//________create an auto-hiding notification
	this.notify = function(content, close_seconds) {
		this.content(content);
		if(close_seconds)
			this.closeTimer = setTimeout(function() { jqDialog.close(); }, close_seconds*1000 );
	};

	//________dialog control
	this.createDialog = function(content) {
		clearTimeout(this.closeTimer);
		this.divOptions.show();
		this.divContent.html(content);
		this.divBox.fadeIn('fast');
//		this.maintainPosition();
	};
	
	this.close = function() {
		this.divBox.fadeOut('fast');
	};

	//________position control

	this.makeCenter = function() {
		$(jqDialog.divBox).css (
			{
				top: ( (($(window).height() / 2) - ( ($(jqDialog.divBox).height()) / 2 ) )) + ($(document).scrollTop()) + 'px',
				left: ( (($(window).width() / 2) - ( ($(jqDialog.divBox).width()) / 2 ) )) + ($(document).scrollLeft()) + 'px',
			}
		);
	};
	this.maintainPosition = function() {
		$(window).scroll( function() {
			jqDialog.makeCenter();
		} );
		
	}

	//________
	this.init = function() {
		this.divBox = $("<div>").attr({ id: this.divBoxName });
		this.divContent = $("<div>").attr({ id: this.divContentName });
		this.divOptions = $("<div>").attr({ id: this.divOptionsName });
		this.divBox.append( this.btClose ).append( this.divContent ).append(
			this.divOptions.append(this.btYes).append(this.btNo).append(this.btOk).append(this.btCancel)
		);
		
		this.divBox.hide();
		$('body').append( this.divBox );
		this.makeCenter();
	};
	
};

$(window).load(function () {
	jqDialog.init();
});