<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="RedOrbit Images" 
description="Displays the latest RedOrbit images-of-the-day from a selected category"
author="RedOrbit.com"
author_email="feedback+nospamhereandeverywhere@redorbit.com"
screenshot="http://master.redorbit.com/modules/news/googlehome/redorbit_iod.jpg"
render_inline="optional" 
scrolling="true" />
<UserPref name="earth" display_name="Earth" default_value="true" datatype="bool" />
<UserPref name="mars" display_name="Mars" default_value="true" datatype="bool" />
<UserPref name="universe" display_name="Universe" default_value="true" datatype="bool" />
<Content type="html"><![CDATA[

<div id="content_earth__MODULE_ID__"></div>
<div id="content_mars__MODULE_ID__"></div>
<div id="content_universe__MODULE_ID__"></div>
<style>
.romc { font-size:82%; font-family:arial,sans-serif; }
.romc { width:100%; padding-top:4px; padding-bottom:4px; }
.romc img, .romc font img { float: left; margin: 0px 8px 8px 0px; }
</style>
<script>
	function extract_tag_content( txt, tag_name )
	{
		var open_tag = "<" + tag_name + ">";
		var close_tag = "</" + tag_name + ">";
		var p1 = txt.indexOf( open_tag );
		
		var result = null;
		
		if( p1 != -1 )
		{
			var txtcut = txt.substring( p1 + open_tag.length );
			var p2 = txtcut.indexOf( close_tag );
					
			if( p2 != -1 )
			{
				result = txtcut.substring( 0, p2 );
			}
		}
		return result;
	}
			
	function remove_1st_tag( txt, tag_name )
	{
		var open_tag = "<" + tag_name + ">";
		var close_tag = "</" + tag_name + ">";
		var p1 = txt.indexOf( open_tag );
				
		var result = txt;
				
		if( p1 != -1 )
		{
			var txtcut = txt.substring( p1 + open_tag.length );
			var p2 = txtcut.indexOf( close_tag );
			
			if( p2 != -1 )
			{
				result = txtcut.substring( p2 + close_tag.length );
			}
		}
		return result;
	}
			
  function fetcher( response_text, category_name )
  {
    var prefs = new _IG_Prefs( __MODULE_ID__ )
	
	var output_ct = _gel( "content_" + category_name + __MODULE_ID__ );
	var output = "";
	
	var tag_content = extract_tag_content( response_text, "item" );
		
	if( tag_content != "" )
	{
		var title = extract_tag_content( tag_content, "title" );
		var url = extract_tag_content( tag_content, "link" ); 
		var description = extract_tag_content( tag_content, "description" );
		description = description.replace( /&amp;/g, "&" );
		description = description.replace( /&lt;/g, "<" );
		description = description.replace( /&gt;/g, ">" );
		//alert( description );
		
		output += "<div class='romc'><b>"+category_name.toUpperCase()+"</b>&nbsp;|&nbsp;";
		output += "<a href='" + url + "' target='_parent'>" + title + "</a>";
		output += "&nbsp;<a href='"+url+"' target='_new'><img src='http://master.redorbit.com/modules/news/googlehome/new_window.gif' border='0' align='center' style='float:none;' alt='Open link in new window'></a></div>";
		output += "<div class='romc'><font size='-1'>" + description + "</font></div>";
		output += "<div style='clear:both;margin:0px;padding:0px;height:0px;'></div>";
	}

	output_ct.innerHTML = output;
  }
  
  function fetcher_earth( response_text )
  {
    fetcher( response_text, "earth" );
  }

  function fetcher_mars( response_text )
  {
    fetcher( response_text, "mars" );
  }

  function fetcher_universe( response_text )
  {
    fetcher( response_text, "universe" );
  }

  function displayFeed() 
  {
    prefs = new _IG_Prefs( __MODULE_ID__ );

	bEarth = prefs.getBool( "earth" );
	bMars = prefs.getBool( "mars" );
	bUniverse = prefs.getBool( "universe" );
	
	if( bEarth )
	{
	    //feed_url = "http://master.redorbit.com/feeds/earth_iod.xml";
		feed_url = "http://master.redorbit.com/modules/imagegallery/tools.php?tool=rss_iod&category_id=1";	
		_IG_FetchContent( feed_url, fetcher_earth );
	}
	if( bMars )
	{
	    //feed_url = "http://master.redorbit.com/feeds/mars_iod.xml";	
		feed_url = "http://master.redorbit.com/modules/imagegallery/tools.php?tool=rss_iod&category_id=2";	
		_IG_FetchContent( feed_url, fetcher_mars );
	}
	if( bUniverse )
	{
	    //feed_url = "http://master.redorbit.com/feeds/universe_iod.xml";	
		feed_url = "http://master.redorbit.com/modules/imagegallery/tools.php?tool=rss_iod&category_id=3";	
		_IG_FetchContent( feed_url, fetcher_universe );
	}
   }
      
   displayFeed(); 
</script> 
]]>
</Content>
</Module>