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

<ModulePrefs 
title="Yahoo! Photo Pulse"
directory_title="Yahoo! Photo Pulse"
description="View Yahoo! News Most Emailed Photos on iGoogle.  Choose from 19 Yahoo! photo streams.  Updates in real time and is configurable via gadget settings (how many photos to display at once, text size, update frequency and photo source)."
title_url="http://www.gingagadgets.com/hub.php?caller=yahoomep"
screenshot="http://hosting.gmodules.com/ig/gadgets/file/109859150862124727573/screenshot_yahoomep.png"
thumbnail="http://hosting.gmodules.com/ig/gadgets/file/109859150862124727573/thumbnail_yahoomep.png"
scrolling="false" singleton="false" author="Ginga"
author_email="ginga.gadgets@gmail.com" author_location="USA"
author_photo="http://ginga.gadgets.googlepages.com/authorphoto.png"
author_aboutme="Restless"
author_link="http://gingagadgets.com"
author_affiliation="ginga gadgets" category="funandgames" category2="lifestyle">
 
<Require feature="dynamic-height"/>
<Require feature="minimessage"/>
<Require feature="analytics" /> 

</ModulePrefs>

  <UserPref 
   name="fontSize" 
   display_name="Font size"
   default_value="x-small"
   datatype="enum">

    <EnumValue value="x-small" display_value="Extra small" /> 
    <EnumValue value="small" display_value="Small" /> 
    <EnumValue value="medium" display_value="Medium" /> 
    <EnumValue value="large" display_value="Large" /> 
   </UserPref>


  <UserPref 
    name="myRows" 
    display_name="Number of rows"
    default_value="2"/>

  <UserPref 
    name="myCols" 
    display_name="Number of columns" 
    default_value="2"/>

  <UserPref 
    name="myFreq" 
    display_name="Update Frequency (mins)" 
    default_value="10"/>

  <UserPref 
    name="photoStream" 
    display_name="Photo Stream" 
    datatype="enum"
    default_value="http://rss.news.yahoo.com/imgrss/1756">

    <EnumValue value="http://rss.news.yahoo.com/imgrss/1756" display_value="Most Emailed" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/1778" display_value="Most Viewed" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/1750" display_value="Most Recommended" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/705" display_value="Top Stories" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/708" display_value="World Photos" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/2767" display_value="U.S. News" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/1479" display_value="Iraq" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/707" display_value="Entertainment" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/706" display_value="Sports" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/1617" display_value="Politics" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/833" display_value="Business" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/1216" display_value="Technology" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/832" display_value="Science" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/1599" display_value="Health" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/1007" display_value="Lifestyle" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/1600" display_value="Odd News" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/2760" display_value="Travel" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/1890" display_value="Fashion" /> 
    <EnumValue value="http://rss.news.yahoo.com/imgrss/1573" display_value="AFP Top Photos" /> 

    </UserPref>

  <Content type="html">
<![CDATA[ 

<!-- Anchor everything -->
<div id="content_div" style="font-size:x-small"></div>
<div id="msg_div"></div>

<style type="text/css">
<!--
span.actionlink {
  color:#039;
  text-decoration:underline;
  cursor:pointer;
}
// and for browsers that support hover, the following:
span.actionlink:hover {
  text-decoration:none;
}
-->
</style>

<script type="text/javascript">

_IG_Analytics("UA-2621463-1", "/yahoomep");

// GLOBAL VARS
var myCapsules = new Array();
var myPos = 0;
var prefs = new _IG_Prefs();
var numRows = prefs.getString("myRows");
var numCols = prefs.getString("myCols");
var fontSize = prefs.getString("fontSize");
var updateFreq = prefs.getString("myFreq");
var photoStream = prefs.getString("photoStream");

// little helper func
function displayImage(imgNum) {
  // handle optional arg
  if (typeof imgNum == "undefined") {
    // do nothing we're fine
  } else {
    myPos = imgNum;
  }

  // calc home number
  var homeNum = myPos - (myPos % (numRows*numCols));

  // Create HTML Block
  var html = "<table style=\"font-size:" + fontSize + "\">";
  html += "<tr><td colspan=2 valign=top>";
  html += "<span class=\"actionlink\" onclick=\"displayPrev()\">&lt;&lt; prev</span> ";
  html += "<span class=\"actionlink\" onclick=\"displayHome(";
  html += homeNum + ")\">home</span> ";
  html += "<span class=\"actionlink\" onclick=\"displayNext()\">next &gt;&gt;</span>";
  html += "</td></tr><tr><td valign=top>";
  html += "<a target=\"_blank\" href=\"" + myCapsules[myPos].link + "\">";
  html += "<img border=0 width=\"" + myCapsules[myPos].width;
  html += "\" height=\"" + myCapsules[myPos].height;
  html += "\" src=\"" + myCapsules[myPos].imgUrl + "\"></a>";
  html += "</td>";
  html += "<td valign=top>" + myCapsules[myPos].caption + "</td>";
  html += "</tr></table>";

  // Write out to div
  _gel('content_div').innerHTML = html; 
  // Tells gadget to resize itself
  _IG_AdjustIFrameHeight();
}

// Create new object - capsule
function capsule(title,link,imgUrl,height,width,caption)
{
  this.title=title;
  this.link=link;
  this.imgUrl = imgUrl;
  this.height=height;
  this.width=width;
  this.caption=caption;
} 

// Called on startup !
function cacheFeed(disp_p) { 
  // XML feed
  var url = photoStream; 

   _IG_FetchXmlContent(url, function (response) {
    if (response == null || typeof(response) != "object" || 
	response.firstChild == null) {
      _gel("content_div").innerHTML = "<i>Invalid data.</i>";
      return;
    }

    // pull all item nodes
    var myItems = response.getElementsByTagName("item");

    // Loop through all <item> nodes
    for (var i = 0; i < myItems.length ; i++) { 
	  
      // going to go through all children of this item
      var nodeList = myItems.item(i).childNodes;  
      for (var j = 0; j < nodeList.length ; j++) {
	var node = nodeList.item(j);  
	       
	if (node.nodeName == "title") {
	  var title = node.firstChild.nodeValue; 
	}
	if (node.nodeName == "link") {
	  var link = node.firstChild.nodeValue;
	}
	if (node.nodeName == "media:content") {
	  var imgURL = node.getAttribute("url");
	  var imgHeight = node.getAttribute("height");
	  var imgWidth = node.getAttribute("width");
	}
	if (node.nodeName == "media:full_image_caption") {
	  var caption = node.firstChild.nodeValue;
	}
      }
      
      // Build out array of capsules:
      myCapsules[i] = new capsule(title,link,imgURL,imgHeight,imgWidth,caption);

    }
    
    if (typeof disp_p == "undefined" || disp_p == 1) {
      displayHome();
    }

  }, { refreshInterval: (60 * updateFreq) }); // end of fetch content call and it's inline response function 
}

// Run above function onload
_IG_RegisterOnloadHandler(cacheFeed);

// schedule continuous updating
setInterval ( "cacheFeed(0)", 1000 * 60 * updateFreq  );

// Functions for EVENTS
// on NEXT
function displayNext() {
  // advance counter
  myPos += 1;
  if (myPos == myCapsules.length) {
    myPos = 0;
  }
  
  displayImage();
}

// on PREV
function displayPrev() {
  // advance counter
  myPos -= 1;
  if (myPos == -1) {
    myPos = myCapsules.length -1;
  }

  displayImage();
}

// on HOME
function displayHome(startPos) {
  var count = 0;
  if (typeof startPos == "undefined") {
    // do nothing
  } else {
    count = startPos;
  }

  var numPhotos = numRows * numCols;

  // Navigation Bar
  var html = "<table width=100% style=\"font-size:" + fontSize + "\">";
  html += "<tr>";
  html += "<td align=left>";
  if ( count - numPhotos >= 0 ) {
    html += "<span class=\"actionlink\" onclick=\"displayHome(";
    html += (count-numPhotos) + ")\">&lt;&lt;</span>";
  }
  html += "</td>";
  html += "<td align=right>";
  if (count+numPhotos < myCapsules.length) {
    html += "<span class=\"actionlink\" onclick=\"displayHome(";
    html += (count+numPhotos) + ")\">&gt;&gt;</span>";
  }
  html += "</td>";
  html += "</tr>";
  html += "</table>";
  
  
  //CREATE TABLE
  html += "<table width=100% border=0 style=\"font-size:x-small\">";
  for ( i = 0; i < numRows; i++) {
    // going through each row
    html += "<tr>";
    for (j = 0; j < numCols; j++) {
      // go through the columns
      html += "<td valign=center align=center>";
      if (count >= myCapsules.length) {
	html += "&nbsp;";
      } else {
	html += "<span class=\"actionlink\" onclick=\"displayImage(";
	html += count + ")\">";
	html += "<img width=\"" + myCapsules[count].width;
	html += "\" height=\"" + myCapsules[count].height;
	html += "\" src=\"" + myCapsules[count++].imgUrl + "\">";
	html += "</span";
      }      
      html += "</td>";
    }
    html += "</tr>";
  }
  html += "</table>";

  // Display HTML string in <div>
  _gel('content_div').innerHTML = html; 
  
  // Tells gadget to resize itself
  _IG_AdjustIFrameHeight();
}

// Don't forget promotion :)
var msg = new _IG_MiniMessage(__MODULE_ID__,_gel("msg_div"));

_IG_FetchContent('http://www.gingagadgets.com/lib/message_center.php?caller=yahoomep', function (responseText) {
  statusMsg = msg.createDismissibleMessage(responseText,resize);
  statusMsg.style.backgroundColor = "white";
  _IG_AdjustIFrameHeight();
});



function resize() {
  _IG_AdjustIFrameHeight();
}
</script>

   ]]> 
</Content>
</Module>


