define([
	"dojo/_base/declare"
], function(declare) {
	return declare("chy.widget.Fortune",null, {
		//properties
		openOnClick : false,
		
		//constructor
		constructor: function(args){
			this.inherited(arguments);
			require(["dijit/Dialog", "dojo/request/xhr", "dojo/cookie", "dojo/date", "dojo/domReady!"], function(Dialog, xhr, cookie, date){
				var cookiedate = cookie("fortunedate");
				var today = new Date()
				var datestring = '' + today.getFullYear() + (today.getMonth()+1) + today.getDate();
				if(cookiedate != datestring){
					cookie("fortunedate", datestring, {expires: 1});
					xhr("jsp/fortune.jsp", {
						handleAs: "text"
					  }).then(function(data){
						var myDialog = new Dialog({
							title: "Fortune",
							content: '<br/><img height="50px" src="images/fortune.png" /><br/><br/>"'+data,
							style: "width: 500px; height: 250px; background-color: white; border: 1px black solid; text-align: center;",
							class: "nihilo"
						});
						myDialog.show();
					  });
				}
			});					
		}
	});
});	
