$(document).ready(function(){
	
	// Don't Open Dialog till Time
	$('#dialog').dialog({ 
		autoOpen: false,
		dialogClass: 'dialog',
		height: 330,
		width: 550,
		hide: 'fadeOut',
		show: 'fadeIn',
		position: 'center',
		resizable: false,
		zIndex: 3999,
		close: function(event, ui) { setCookie('dialogClosed', 'true', 1); }
		});
	
	// Initialize the Dialog Timer
	initializeTimer();
});

var TIMEPERIOD = 5000;

/*
 * Initialize Timer
 */
function initializeTimer()
{
	window.setTimeout('openDialog()', TIMEPERIOD);
}

/*
 * Open the Dialog Box after so many seconds
 */
function openDialog()
{
	var dialogClosed = getCookie('dialogClosed');
	
	// Only Open the Dialog if it has not already been shown
	if(dialogClosed == null || dialogClosed == "")
	{
		$('#dialog').dialog('open');
	}
}

/*
 * Set a Cookie
 */
function setCookie(c_name, value, expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name+ "=" + escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

/*
 * Get a Cookie
 */
function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			
			if (c_end==-1) c_end=document.cookie.length;
			
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	
	return "";
}


