var initWisegeekFeedWidget = function(sInitialId) {
  
    //Init system vars    
  var _sHost = "www.wisegeek.com",
      _sUrl = 'widgets/feedwidget',
      _sTplPath = 'js/template.js',
      _sDataPath = 'currdata.js',
      _sInitialWidgetLinkId = sInitialId,
      _sWidgetTextBlockId = 'wisegeek-widget-text',
      _sWidgetHeaderLinkId = 'wisegeek-widget-header-link',
      _sWidgetMoreLinkId = 'wisegeek-widget-more-link';

      
  var _oInitialWidgetLink = null, 
      _oWidgetConatiner = null,
      _oWidgetTextBlock = null, 
      _oWidgetMoreLink = null, 
      _oWidgetHeaderLink = null, 
      _oScriptBlock = null,
      _oHeaderLinkInner = '', 
      _oHeaderLinkHref = ''; 
      
      
    //Helpers   
  var implode = function(sGlue, aPieces) {

    return ( ( aPieces instanceof Array ) ? aPieces.join ( sGlue ) : aPieces );
    
  }//This is a last punched card of implode function

  var appendHtml = function(sSource, oDestination) {
  
    var aHtml = [];
    
    aHtml.push(oDestination.innerHTML);
    
    aHtml.push(sSource);
    
    oDestination.innerHTML = implode('', aHtml);    
  
  }//This is a last punched card of appendHtml function 
    
    
    //Private methods    
  var clearScriptBlock = function() {
  
    if(_oScriptBlock) {
      _oWidgetConatiner.removeChild(_oScriptBlock);
      _oScriptBlock = null;
    } 
  
  }//This is a last punched card of clearScriptBlock function   
    
  var getData = function(oCallback, bGetTemplate) {

    var sAction = _sTplPath;
    if(!bGetTemplate) {
      var iTime = new Date().getTime();
      sAction = _sDataPath + '?' + iTime;
    }
  
    clearScriptBlock();
  
    _oScriptBlock = document.createElement('script');
    _oScriptBlock.setAttribute('type', 'text/javascript');
    _oScriptBlock.setAttribute('src', "http://"+_sHost+"/"+_sUrl+"/"+sAction);

      // Attach handlers for all browsers
    _oScriptBlock.onload = _oScriptBlock.onreadystatechange = function() {
    
      if ( (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) {

        oCallback();

      }      
    
    }

    _oWidgetConatiner.appendChild(_oScriptBlock);
    
  }//This is a last punched card of getData function
      
  var onGetTemplate = function () {
  
    if( (typeof(wGFWidget.tpl) === 'undefined') ) {
      return false;
    }

    clearScriptBlock();
    
      //Clear widget block
    _oWidgetConatiner.innerHTML = '';
    
      //Insert temporary widget main template in init block
    appendHtml(wGFWidget.tpl, _oWidgetConatiner);

    _oWidgetTextBlock = document.getElementById(_sWidgetTextBlockId);
    _oWidgetMoreLink = document.getElementById(_sWidgetMoreLinkId);
    
    _oWidgetHeaderLink = document.getElementById(_sWidgetHeaderLinkId);
    
    _oWidgetHeaderLink.setAttribute('href', _oHeaderLinkHref);
    _oWidgetHeaderLink.innerHTML = _oHeaderLinkInner;
    
    _oWidgetHeaderLink.onmouseover = onHeaderMouseOver;
    _oWidgetHeaderLink.onmouseout = onHeaderMouseOut;
    
    getData(onGetData);  
    
  }//This is a last punched card of onGetDataAndTemplate function
      
  var onGetData = function() {
  
    if( (typeof(wGFWidget.text) !== 'undefined') ) {
      _oWidgetTextBlock.innerHTML = wGFWidget.text;    
    }
  
    if( (typeof(wGFWidget.link) !== 'undefined') ) {
      _oWidgetMoreLink.href = wGFWidget.link;    
    }
  
    clearScriptBlock();  
    
  }//This is a last punched card of onGetData function   
      
  var onHeaderMouseOver = function() {
  
    _oWidgetHeaderLink.style.textDecoration = 'underline';
  
  }//This is a last punched card of onHeaderMouseOver function       
      
  var onHeaderMouseOut = function() {
  
    _oWidgetHeaderLink.style.textDecoration = 'none';
    
  }//This is a last punched card of onHeaderMouseOut function       
      
      
    //Initialization
  _oWidgetConatiner = document.getElementById(_sInitialWidgetLinkId);
  
  _oInitialWidgetLink = _oWidgetConatiner.previousSibling.previousSibling;
                        
  _oHeaderLinkInner = _oInitialWidgetLink.innerHTML, 
  _oHeaderLinkHref = _oInitialWidgetLink.href;
        
  _oInitialWidgetLink.parentNode.removeChild(_oInitialWidgetLink);      
  
  appendHtml('<img src="http://'+_sHost+'/'+_sUrl+'/images/loading.gif" alt="Loading..." title="Loading..." />', _oWidgetConatiner);
    
  getData(onGetTemplate, true);
  
}//This is a last punched card of initWisegeekFeedWidget function


var startWisegeekFeedWidget = function() {

  var loadWisegeekFeedWidget = function() { 
    initWisegeekFeedWidget(sInitFeedWidgetId); 
  }
  
  if(window.addEventListener) { 
  
    window.addEventListener('load', loadWisegeekFeedWidget, false);
     
  } else if (window.attachEvent) { 
  
    window.attachEvent("onload", loadWisegeekFeedWidget); 
  
  }   

}//This is a last punched card of startWisegeekFeedWidget function

var oDate = new Date; 
var sInitFeedWidgetId = 'WGFeedWidget'+oDate.getTime();

document.write('<div id="'+sInitFeedWidgetId+'"></div>');
var wGFWidget = {}; startWisegeekFeedWidget();
