<?xml version="1.0" encoding="UTF-8" ?>
 <Module>
  <ModulePrefs
   title="scifAI" title_url="http://scifai.com/"
   description="The latest SciFaiku (science fiction haiku) posted at scifai.com"
   author="Alex Ibrado"
   author_email="gadget@scifai.com"
   author_affiliation="ibrado.org"
   author_location="Mandaluyong, PH"
   height="100"
   width="270"
   thumbnail="http://stargate.scifai.com/scifai-logo-new.png"
   screenshot="http://stargate.scifai.com/igoogle-snap-new.png">
    <Require feature="setprefs" />
  </ModulePrefs>

  <UserPref
    name="lastseen"
    default_value="0"
    datatype="hidden"/>

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

<style type="text/css">
  #scifai-wrap {
    background: #003456 url('http://stargate.scifai.com/fbbg.png');
    height: 100px;
    display: block;
  }
  .scifai-loader {
    text-align: center;
    position: relative;
    top: 29px;
    display: block;
  }
  .scifai-content {
    color: #ff9900;
    text-align: left;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 18px;
    padding-left: 5px;
    padding-top: 5px;
  }
  .scifai-tanka {
    color: #ff9900;
    text-align: left;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 13px;
    padding-left: 5px;
    padding-top: 10px;
    line-height: 13px;
  }
  .scifai-content-narrow {
    color: #ff9900;
    text-align: left;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    padding-left: 5px;
    padding-top: 20px;
  }
  .scifai-tanka-narrow {
    color: #ff9900;
    text-align: left;
    font-family:  Arial, Helvetica, sans-serif;
    font-size: 11px;
    padding-left: 5px;
    padding-top: 10px;
  }
  .scifai-links {
    border-width: 0px;
    font-size: 11px;
    position: absolute;
    top: 82px;
    right: 7px;
    color: #808080;
    height: 12px;
    text-align: right;
    list-style-type: none;
    margin: 0pt;
    padding: 0pt;
  }
  .scifai-links a {
    color: #fff;
    font-size: 11px;
    border-bottom: 1px dotted #fff;
    text-decoration: none;
  }
  .scifai-links a:hover {
    color: #ff9900;
    font-size: 11px;
    border-bottom: 1px solid #ff9900;
    text-decoration: none;
  }
  .scifai-disqus {
     position: absolute;
     top: 82px;
     left: 7px;
     float: left;
     display: block;
     color: #808080;
     height: 15px;
   }
  .scifai-disqus a {
    color: #fff;
    font-size: 11px;
    border-bottom: 1px dotted #fff;
    text-decoration: none;
  }
  .scifai-disqus a:hover {
    color: #ff9900;
    font-size: 11px;
    border-bottom: 1px solid #ff9900;
    text-decoration: none;
  }
  .scifai-more {
    position: absolute;
    top: 0px;
    right: 0px;
    float: right;
    display: block;
    color: #808080;
    padding: 3px;
    font-size: 9px;
  }
  .scifai-more a {
    color: #808080;
    font-size: 9px;
    text-decoration: none;
  }
  .scifai-more a:hover {
    color: #ff9900;
    font-size: 9px;
    border-bottom: 1px solid #ff9900;
    text-decoration: none;
  }
</style>

<div id="scifai-more-wrap"></div>
<div id="scifai-wrap">
  <div class="scifai-loader"><img alt="*" src="http://stargate.scifai.com/fbloader-new.gif" height="32" width="32" /></div>
</div>
<div id="scifai-disqus-wrap"></div>
<script type="text/javascript" src="http://stargate.scifai.com/jsr_class.js"></script>
<script type="text/javascript">
  var prefs = new _IG_Prefs(__MODULE_ID__);
  var json_request;
  var post_count = 0;

  var winW = 270;
  var winH = 100;

  if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    winW = window.innerWidth-16;
    winH = window.innerHeight-16;
   }
   if (navigator.appName.indexOf("Microsoft")!=-1) {
    winW = document.body.offsetWidth-20;
    winH = document.body.offsetHeight-20;
   }
  }

  var is_narrow = (winW < 250);
  var ref = document.referrer;
  var is_fb = ref.match(/opensocket\.info/);
  var is_fb_canvas = ref.match(/fb_sig_in_iframe/);
  var post_url = '#';

  function swagURLs(content) {
    content = content.replace(/^\s+/g, '').replace(/\s+$/g, '');
    content = content.replace(/<br\/?>\\s*$/gi, '');

    var re = new RegExp("([^<]+)\\s+<br/?>([^<]+)\\s+<br/?>([^<]+)\\s+<br/?>([^<]+)\\s+<br/?>([^<]+)", "i");
    var m = re.exec(content);
    var urls = new Array('#', '#');
    var pref = 'http://www.zazzle.com/api/create?at=238030773790926334&ax=Linkover&fwd=ProductPage';

    if(m != null) {
      var line1 = encodeURI(m[1]);
      var line2 = encodeURI(m[2]);
      var line3 = encodeURI(m[3]);
      var line4 = encodeURI(m[4]);
      var line5 = encodeURI(m[5]);
      urls[0] = pref + '&pd=235811679170238687'
          + '&line1='+line1
          + '&line2='+line2
          + '&line3='+line3
          + '&line4='+line4
          + '&line5='+line5;

      urls[1] = pref + '&pd=168818891060041226'
          + '&line1='+line1
          + '&line2='+line2
          + '&line3='+line3
          + '&line4='+line4
          + '&line5='+line5;

      urls[2] = '1';

    } else {
      re = new RegExp("([^<]+)\\s+<br/?>([^<]+)\\s+<br/?>([^<]+)", "i");
      m = re.exec(content);

      if(m != null) {
        var line1 = encodeURI(m[1]);
        var line2 = encodeURI(m[2]);
        var line3 = encodeURI(m[3]);
        urls[0] = pref + '&pd=235492492309225217'
            + '&line1='+line1
            + '&line2='+line2
            + '&line3='+line3;
        urls[1] = pref + '&pd=168256815828863591'
            + '&line1='+line1
            + '&line2='+line2
            + '&line3='+line3;
        urls[2] = '0';
      }
    }
    return urls;
  }

  function getPost(type) {
    var url = 'http://scifai.com/api/read/json?type=regular&callback=scifaiCBtumblr&num=1';
    switch(type) {
      case -1:
        // previous;
        break;
      case 1:
        // next
        break;
      case 9:
        document.getElementById('scifai-wrap').innerHTML = '<div class="scifai-loader"><img alt="*" src="http://stargate.scifai.com/fbloader-new.gif" height="32" width="32" /></div>';
        var r = 1+Math.floor(Math.random()*post_count);
        url += '&start='+r;
        break;
    // default is current
    }

    json_request = new JSONscriptRequest(url);
    json_request.buildScriptTag();
    json_request.addScriptTag();
  }

  function scifaiCBtumblr(obj) {
    json_request.removeScriptTag();
    var post_body = obj['posts'][0]['regular-body'];
    var post_id = obj['posts'][0]['id'];
    post_url = obj['posts'][0]['url'];
    var post_turl = encodeURI(post_url);
    post_count = obj['posts-total'];
    var post_date = new Date(obj['posts'][0]['date']);
    var post_m = post_date.getMonth() + 1;
    var post_d = post_date.getDate();
    var post_y = parseInt(post_date.getYear() % 100);
    if (post_d < 10) post_d = '0' + post_d;
    if (post_y < 10) post_y = '0' + post_y;

    var swag = swagURLs(post_body);
    var text_class = 'scifai-'
      + (((typeof(swag[2]) != 'undefined') && (swag[2] == '1')) ? 'tanka' : 'content')
      + (is_narrow ? '-narrow' : '');
    var newhtml = '<div class="' + text_class +  '">'
      + post_body + '</div><div class="scifai-links">';

    var showswag = (!is_fb) || is_fb_canvas;

    var targ = ' target="_blank"';
    if (showswag && (swag[0] != '#')) {
      var swag_prompt = 'get a ';
      var swag_tee = 'tee';
      var swag_mug = 'mug';

      if(is_narrow) {
        swag_prompt = '';
        swag_tee = 'T';
        swag_mug = 'M';
      } else if(winW > 335) {
        swag_prompt = 'get this on a ';
      }
      newhtml += swag_prompt + '<a href="' + swag[0] + '"' + targ + '>' + swag_tee + '</a> | <a href="'
        + swag[1] + '"' + targ + '>' + swag_mug +'</a>&nbsp;&nbsp';
    }
    newhtml += '<a href="' + post_url + '" target="_blank">' + post_id + '</a>&nbsp;'
      + post_m + '.' + post_d + '.' + post_y + '</div>';

    document.getElementById('scifai-wrap').innerHTML = newhtml;
    var last_seen = prefs.getInt("lastseen");

    var mhtml = '<div class="scifai-more">';
    var delta = post_count - last_seen - 1;
    mhtml += '<a href="http://scifai.com/" target="_blank">' + (delta > 0 ? delta + ' ' : '')
      + 'more</a>';

    // mhtml += ' | ' + '<a href="javascript:getPost(9)">'+(is_narrow ? '?' : 'random')+'</a>';
    mhtml += ' | ' + '<a href="javascript:getPost(9)">random</a>';

    if(is_fb && !is_fb_canvas) {
      mhtml += ' | <a href="http://apps.facebook.com/scifaiku/" target="_blank">app' + (is_narrow ? '' : ' home')
        + '</a>';
    }

    mhtml += '</div>';
    document.getElementById('scifai-more-wrap').innerHTML = mhtml;

    prefs.set("lastseen", post_count);
    json_request = new JSONscriptRequest('http://disqus.com/api/v1/get_num_posts?forum_url=scifai&amp;thread_url='
      + post_turl + '&amp;response_type=json&amp;callback=scifaiCBdisqus');
    json_request.buildScriptTag();
    json_request.addScriptTag();
  }

  function scifaiCBdisqus(obj) {
    json_request.removeScriptTag();
    var post_nc = obj['num_posts'];
    var capt = (is_narrow ? '' : 'author\'s ') + "notes";
    if(post_nc > 1) {
      var s = ((post_nc-1) == 1) ? '' : 's';
      capt += ' + ' + (post_nc-1) + (is_narrow ? '' : ' comment'+s);
    }
    document.getElementById('scifai-disqus-wrap').innerHTML =
      '<div class="scifai-disqus"><a href="' + post_url + '#disqus_thread" target="_blank">' + capt + '</a></div>';
  }

</script>
<script type="text/javascript">
<!--
  getPost(0);
// -->
</script>
<!-- Start of StatCounter Code -->
<script type="text/javascript">
sc_project=3551173;
sc_invisible=1;
sc_partition=39;
sc_security="dee4faaa";
</script>

<script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div class="statcounter"><a href="http://www.statcounter.com/free_web_stats.html" target="_blank"><img class="statcounter" src="http://c40.statcounter.com/3551173/0/dee4faaa/1/" alt="web statistics" ></a></div></noscript>
<!-- End of StatCounter Code -->
  ]]>
  </Content>
  </Module>