<?xml version="1.0" encoding="UTF-8"?>
<Module>
	<ModulePrefs 
		title="Faves.com Bookmarks" 
		directory_title="Faves Bookmarks" 
		category="tools"
		height="300" width="320" scrolling="true" 
		description="Displays bookmarks from your friends or favorite topics from Faves.com" 
		screenshot="http://home.comcast.net/~roberthd/css-dock-menu/screenshot.png" thumbnail="http://home.comcast.net/~roberthd/css-dock-menu/thumbnail.png" 
		title_url="http://faves.com" 
		author="Rob Dickerson" author_email="rob@faves.com" author_link="http://faves.com/users/roberthd/tags" author_affiliation="Faves.com">
		<Require feature="analytics"/>
		<Require feature="settitle" />
	</ModulePrefs>
	<UserPref name="userName" display_name="User Name:" default_value="roberthd" datatype="string"/>
	<UserPref name="topic" display_name="Topic:" default_value="" datatype="string"/>
	<UserPref name="fromPeople" display_name="Show Faves from:" default_value="my friends" datatype="enum">
		<EnumValue value="me"/>
		<EnumValue value="my friends"/>
		<EnumValue value="everyone"/>
	</UserPref>
	<UserPref name="theme" display_name="Display Theme:" default_value="Minima" datatype="enum">
		<EnumValue value="Default"/>
		<EnumValue value="Minima"/>
		<EnumValue value="Denim"/>
		<EnumValue value="WP"/>
		<EnumValue value="WPSecret"/>
		<EnumValue value="WPHeaven"/>
		<EnumValue value="WPBeta"/>
		<EnumValue value="Grey"/>
	</UserPref>
	<UserPref name="showNotes" display_name="Show notes?" default_value="true" datatype="bool"/>
	<UserPref name="showPeople" display_name="Show people?" default_value="true" datatype="bool"/>
	<UserPref name="showThumbs" display_name="Show thumbnail images?" default_value="true" datatype="bool"/>
  <Content type="html">
    <![CDATA[
	  <link href="http://faves.com/css/ScriptWidget.css" rel="stylesheet" type="text/css" />

      <script type="text/javascript">

        var prefs = new _IG_Prefs(__MODULE_ID__);
		document.write ('<div id="message" class="favesWidget favesTheme faves' + prefs.getString ('theme') + '"></div>');
		var titleString = prefs.getString("topic")
				? prefs.getString("topic").substring(0,1).toUpperCase() + prefs.getString("topic").substring(1,prefs.getString("topic").length)
				: 'Faves';
		titleString += ' from ' + prefs.getString("fromPeople");
		_IG_SetTitle(titleString);
        callFaves();
		// Check for new Faves every two minutes
		var refreshRate = 240;
        setInterval(callFaves, refreshRate*1000);
		_IG_Analytics("UA-584316-1", "/googlegadget/" + prefs.getString ("userName"));

		/*
		** callFaves - builds the JSON URL then processes the resulting data 
		*/
        function callFaves() {
		  if (prefs.getString("fromPeople") == "everyone") {
			url = "http://faves.com/json/buzz/" + prefs.getString("topic");
			url += "?count=10";
		  }
		  else {
		  	url = "http://faves.com/users/" + prefs.getString ("userName");
			url += prefs.getString("fromPeople")== "me" ? "/json" : "/friends/json?count=10";
			if (prefs.getString("topic"))
				url += "&st=tag:" + prefs.getString("topic");
		  }
          _IG_FetchContent(url, showFaves, refreshRate);
        }

		/*
		** showFaves - builds the HTML in the same format as the Faves syndication widget.
		**
		** Input: json - the text returned by the JSON call.
		*/
		function showFaves(json) {
			eval("faves=" + json);
			var message = document.getElementById("message");
			h = '<ul>';
			for (var i in faves.faves)
				if (faves.faves[i].u) {
					h += '<li><h3><a target="_top" href="' + faves.faves[i].u + '">';
					if (prefs.getBool ("showThumbs")) {
						h += '<span';
						if (faves.faves[i].tIU)
							h += ' style="background-image: url(\'' + faves.faves[i].tIU + '\') !important;"';
						h += '></span>';
					}
					h += faves.faves[i].s + '</a>';
					if (prefs.getBool ("showPeople")) {
						h += '<div>';
						if (faves.faves[i].uIU)
							h += '<img src="' + faves.faves[i].uIU + '" />';
						h += faves.faves[i].uN + '</div>';
					}
					if (prefs.getBool ("showNotes"))
						h += '<p>' + faves.faves[i].n + '</p>';
					h += '</li>';
				}
			h += "</ul>";
			message.innerHTML = h;
		}

      </script>
    ]]>
  </Content>
</Module>