<?xml version="1.0" encoding="UTF-8" ?>
<Module>
	<ModulePrefs 
		title="Quotes of the Day" 
		directory_title="4 New Quotes of the Day Every Day"
		description="Displays 4 new quotes of the day every day with the quotes and authors easily visible. Once you've read them, you can clear it so they are hidden until new ones are available!" 
		author="Matt Kruse" 
		author_email="gadget@mattkruse.com" 
		screenshot="http://www.javascripttoolbox.com/gadget/qotd/qotd.png" 
		thumbnail="http://www.javascripttoolbox.com/gadget/qotd/qotd_thumb.png"
		author_affiliation="Matt Kruse" 
		author_location="IL, USA" 
		author_link="http://www.JavascriptToolbox.com/" 
		> 
		<Require feature="setprefs"/>
		<Require feature="dynamic-height"/>
		<Require feature="analytics"/>
	</ModulePrefs>
		<UserPref name="fontsize" display_name="Font Size: " default_value="80%" />
		<UserPref name="format" display_name="Format: " default_value="&lt;div class=mc&gt;%SUMMARY%&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-- &lt;b&gt;&lt;a href=&quot;%LINK%&quot; target=&quot;_blank&quot;&gt;%TITLE%&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;" />
		<UserPref name="lastseen" display_name="Last Seen Quote (do not change manually)" />
		<UserPref name="today" datatype="hidden" default_value="" />
		<Content type="html"> 
		<![CDATA[ 
<script>
var p,prefs;
p = prefs= new _IG_Prefs();

// Analytics
var now = new Date();
var today = (now.getFullYear?now.getFullYear():now.getYear())+'-'+(now.getMonth()+1)+'-'+now.getDate();
var prefs_today = prefs.getString('today');
// Analytics - Record a new gadget add
if (prefs_today=='') {
	_IG_Analytics("UA-6382940-1", "/addgadget/qotd");
}
// Analytics - Record a unique hit for today
if (prefs_today!=today) {
	prefs.set('today',today);
	_IG_Analytics("UA-6382940-1", "/gadget/qotd");
}
function donate() { _IG_Analytics("UA-6382940-1", "/donate/qotd"); return true; }
function link(url) { _IG_Analytics("UA-6382940-1", "/link/"+url); return true; }

var url = "http://feeds.feedburner.com/quotationspage/qotd";
var lastseen = p.getString("lastseen");

var loaded=false;
var interval = null;
var firstlink = "";
var tpl = p.getString('format');

function load() {
	if (interval!=null) { clearInterval(interval); }
	interval = setInterval(load, (60000 * 60));
	_IG_FetchFeedAsJSON(url,render,4,true);
}
function render(obj) {
	var content = "";
	if (!obj || (obj.ErrorMsg && obj.ErrorMsg!="") || (!obj.Entry || obj.Entry.length==0)) {
		content = "Information is temporarily unavailable";
	}
	else if (obj.Entry) {
		var hide = false;
		firstlink = obj.Entry[0].Link;
		for (var i = 0; i < obj.Entry.length; i++) {
			var item = obj.Entry[i];
			if (!hide && item.Link==lastseen) {
				hide = true;
			}
			if (!hide) {
				var summary = item.Summary.replace(/\<[^\>]*\>/gi,""); // Get rid of feed ads
				var link = "http://www.quotationspage.com/quotes/"+item.Title.replace(/\s/g,"_");
				content += tpl.replace(/\%LINK\%/g,link).replace(/\%TITLE\%/g, _hesc(item.Title)).replace(/\%SUMMARY\%/g, _hesc(summary));
			}
		}
	}
	if (content!="") {
//		content += '<center><div class="clear" onclick="clearAll()">Clear</div><div class="donate"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=1929562" onclick="return donate()" target="_blank">Click here to donate $2</a> to support <a href="http://mattkruse.com/" onclick="return link(this.href)" target="_blank">me</a> and my <a href="http://www.google.com/ig/directory?type=authors&url=gadget%40mattkruse.com" onclick="return link(this.href)" target="_blank">free gadget development</a>! Merry Christmas!</div></center>';
		content += '<center><div class="clear" onclick="clearAll()">Clear</div></center>';
	}
	else {
		content = '<center>No new quotes (<a href="#" style="text-decoration:underline;" onclick="showToday();return false;">re-show today\'s</a>)</center>';
	}
	_gel("content").innerHTML = content;
	_IG_AdjustIFrameHeight();
}
function clearAll() {
	p.set('lastseen',firstlink);
	lastseen = firstlink;
	_IG_Analytics("UA-6382940-1", "/gadgets/qotd/clear");
	load();
};
function showToday() {
	p.set('lastseen',"");
	lastseen = "";
	_IG_Analytics("UA-6382940-1", "/gadgets/qotd/showtoday");
	load();
}
_IG_RegisterOnloadHandler(load);

document.writeln("<style>body { font-size:"+p.getString('fontsize')+";}</style>");
</script>
<style>
a { 
	text-decoration:none;
	color:black;
}
a:visited {
	color:black;
}
body {
	background:white url(http://books.google.com/googlebooks/quote_l.gif) no-repeat left top;
	padding-left:20px;
}
#container {
	background:white url(http://books.google.com/googlebooks/quote_r.gif) no-repeat right bottom;
	padding-right:20px;
}
div.donate {
	font-size:10px;
	font-family:arial;
	border:1px solid #ccc;
	border-color:#01B403;
	background-color:#eee;
	cursor:hand;
	margin:5px;
	padding:2px;
}
div.donate a {
	text-decoration:underline;
}
div.clear {
	margin-right:10px;
	width:100px;
	border:1px solid #ccc;
	background-color:#eee;
	text-align:center;
	cursor:pointer;
}

</style>

<div id="container">
	<div id="content">
	Loading quotes of the day...
	</div>
</div>

     ]]> 
   </Content> 
</Module>

