<?xml version="1.0" encoding="UTF-8" ?>
<Module>
  <ModulePrefs 
    title="Bloomberg.com Headline News"   
    description="Keep up-to-date on breaking financial news through Bloomberg.com's headlines."
    author="Kitalya Deronar"
    author_email="kitalya+bloomberg@gmail.com"
    author_location="USA"
    screenshot="http://hosting.gmodules.com/ig/gadgets/file/101504252122922076987/Bloomberg_screenshot.png"  
    thumbnail="http://hosting.gmodules.com/ig/gadgets/file/101504252122922076987/Bloomberg_thumbnail.png"  
    scrolling="true">
    <Require feature="minimessage"/>
    <Require feature="analytics"/>  
    </ModulePrefs>

  <Content type="html">

  <![CDATA[  
  <div id="content_div" style="font-size:12px; background-image: url('http://hosting.gmodules.com/ig/gadgets/file/101504252122922076987/gradient.png'); background-repeat: repeat-y;"></div>
  <div id="loading">Loading headlines...</div>

  <script>    
  _IG_Analytics("UA-2891302-1", "/Bloomberg.xml");  
    
  var msg = new _IG_MiniMessage(__MODULE_ID__);
  var loadMessage = msg.createStaticMessage(_gel("loading"));

  var gotHeadlines = false;

function run()
{
  gotHeadlines = false;

  getHeadlines();
}

  function getHeadlines()
  {
    if (!gotHeadlines)
    {
      _IG_FetchContent("http://www.bloomberg.com/", parsePage);
      setTimeout("getHeadlines()", 15*1000);
    }
  }


  function parsePage(response)
  {
    if (response == null)
    {
      _gel("loading").innerHTML = "Error loading headlines, trying again...";
      return;
    }
    else
    {
      gotHeadlines = true;
      msg.dismissMessage(loadMessage);
    }

    html = "";

    response = response.substr(response.indexOf("breakingnews"));
    response = response.substr(0, response.indexOf("mostread"));

    var start = response.indexOf("<a href=\"/apps/news");
    while (start != -1)
    {
      response = response.substr(start);
      var length = response.indexOf("</a>");

      var newsAnchor = response.substr(0, length+4);
      newsAnchor = "&#187;&nbsp;" +
        newsAnchor.substr(0, 3) +
        "target='_blank' " +
        newsAnchor.substr(3, 6) + 
        "http://www.bloomberg.com" + 
        newsAnchor.substr(9) +
        "<br><br>";
      html += newsAnchor;
      
      response = response.substr(length);
    
      var start = response.indexOf("<a href=\"/apps/news");
    }

    html += "<div style='font-style:italic; text-align: center;'>This gadget is in no way endorsed by <a href='http://www.bloomberg.com'>Bloomberg.com</a></div>"
    
     _gel("content_div").innerHTML = html;
  }

run();
setInterval("run()", 60*60*1000);

  </script>
]]>
</Content>
</Module>










