<?xml version="1.0" encoding="UTF-8"?>

<!-- 
(C) Copyright 2005 Brad Anderson, Inc. All rights reserved.
-->


<channel>

  <initialize language="JavaScript">
  
	DataStore.Set("mainViewIdentifier", "Global");
	
	debug("----- Initializing the data store -----");
	
	
	/* Set the channel's minimum size */
 	DataStore.Set("Global.minViewSize", "{width=750; height=445}");
 	

	/* Update the data store representation of the search field as the
		user types into it. This way, if they click the search button
		before hitting return, the data store will reflect the latest
		changes made by the user.
	*/
	DataStore.Set("Global.searchText.updateValueOnTextChanged", true);
	
	DataStore.Set("Global.findButton.imageURL", "find.png");
	
	
	
 </initialize>

<triggers>

	<scripts>
		<script language="JavaScript">
			function URLencode(sStr) {
				return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
			}

			
		</script>
		<script language="XQuery">
			
		</script>
	</scripts>




<trigger path="Global.didInstall" language="JavaScript">

	DataStore.Set("Global.action.firstTime", 1);
</trigger> 


<trigger path="Global.action.firstTime" language="JavaScript">

	DataStore.Notify("Global.GetSettings");
	
	DataStore.Set("Global.stream.htmlData", "&lt;body leftmargin='0' rightmargin='0' marginwidth='0' marginheight='0' topmargin='0'>" + 
		'&lt;object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,65,0" width="450" height="400" id="gc" align="middle">\
&lt;param name="allowScriptAccess" value="sameDomain" />\
&lt;param name="movie" value="http://www.djbradanderson.com/global/gc.swf" />\
&lt;param name="quality" value="high" />\
&lt;param name="bgcolor" value="#000000" />\
&lt;embed src="http://www.djbradanderson.com/global/gc.swf" quality="high" bgcolor="#000000" width="450" height="400" name="gc" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
&lt;/object>'
		);
	//DataStore.Set("Global.stream.url", 
		//"http://www.djbradanderson.com/global/gc.swf");
	
	DataStore.Set("Global.stream.followLinksInView", "0");
	
</trigger>



<trigger language="XQuery" path="Global.GetSettings" async="true">
	{-- currently, do nothing with the data --}
	let $document :=	document("http://www.globalconscious.com/Globalhit.php")
	return null()
</trigger>






<trigger language="JavaScript" path="Global.gotoFirstRiver.action" async="true">

	System.OpenURL("sherlock://homepage.mac.com/javalizard/firstriver/firstriver.xml?new_window&action=add");

</trigger>


<trigger language="JavaScript" path="Global.gotoWebsite.action" async="true">

	System.OpenURL("http://www.djbradanderson.com/global/");

</trigger>









<trigger language="JavaScript" path="Global.findButton.action">
	
	
	keywords = DataStore.Get("Global.searchText.objectValue");
	
	if(DataStore.Get("Global.search") != keywords) {
		DataStore.Set("Global.busy.animating", true);
		DataStore.Set("Global.search", keywords);
		DataStore.Set("Global.messages.htmlData", null);
	}

</trigger>





<trigger language="XQuery" path="Global.search"
	inputs="keywords=Global.search"
	output="Global.processList" mutex="hitSiteSerial" task="true" async="true">
	
	let $url := concat("http://www.djbradanderson.com/global/blather.xml.php?words=", url-encode($keywords, "", ":/ &+=", "UTF-8"))
	
	let $document := document($url)
	
	
	let $numFound := count($document//messages/message)
{--	
	let $log := msg($url) --}
	let $log := msg("total: ", $numFound)   
	
	let $results := for $message in ($document//messages/message)
	 	return dictionary(
				 			("message",			$message/string())
			 			 )
		
	return dictionary(	
						("messages",		$results),
						("keywords",		$keywords),
						("total",		$numFound)
			)
</trigger>



<trigger language="JavaScript" path="Global.processList" task="true" async="true">
	
	page = DataStore.Get("Global.processList");
	
	if(page.messages != null && typeof page.messages[0] == 'undefined')
		page.messages = new Array(page.messages);
	
	if(page.total == 0) {
		html = "There were no messages found for: " + page.keywords;
	} else {
		html = "&lt;body leftmargin='0' rightmargin='0' marginwidth='0' marginheight='0' topmargin='0'>" + 
				"&lt;table cellspacing='0' cellpadding='3'>";
		for(i = 0; i &lt; page.messages.length; i++) {
			color = i%2 ? "#E7F0FD" : "";
			html += "&lt;tr>&lt;td bgcolor='" + color + "'>&lt;font type='Verdana,Helvetica,san-serif'>" + 
					page.messages[i].message + 
					"&lt;/font>&lt;/td>&lt;/tr>"
		}
		
		html += "&lt;/table>&lt;/body>"
	}
	
	DataStore.Set("Global.messages.htmlData", html);
	
	DataStore.Set("Global.busy.animating", false);

</trigger>





</triggers>

</channel>

