( function() {
   var trueName = '';
   for (var i = 0; i < 16; i++) {
      trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
   }
   window[trueName] = {};
   var $ = window[trueName];
   $.f = function() {
      return {
         runFunction : [],
         init : function(target) {
            var theScripts = document.getElementsByTagName('SCRIPT');
            for (var i = 0; i < theScripts.length; i++) {
               if (theScripts[i].src.match(target)) {
                  if (theScripts[i].innerHTML) {
                     if (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]+$/.test(theScripts[i].innerHTML.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''))) {
                        try {
                           $.a = eval( '(' + theScripts[i].innerHTML + ')' );
                        }
                        catch(err) { }
                     }
                  }
                  if (typeof $.a !== 'object') {
                     $.a = {};
                  }
                  $.f.buildStructure();
                  theScripts[i].parentNode.insertBefore($.w, theScripts[i]);
                  theScripts[i].parentNode.removeChild(theScripts[i]);
                  break;
               }
            }
         },
         buildStructure : function() {
            $.w = document.createElement('DIV');
	   $.d = {"background":"#E0E0E0", "border":"1px solid #000", "width":"400px"};
      for (var k in $.d) {
       if ($.a[k] === undefined) {
        $.a[k] = $.d[k];
       }
      }
      var ns = document.createElement('style');
      document.getElementsByTagName('head')[0].appendChild(ns);
      if (!window.createPopup) {
       ns.appendChild(document.createTextNode(''));
       ns.setAttribute("type", "text/css");
      }
      var s = document.styleSheets[document.styleSheets.length - 1];
      var rules = {
       "" : "{zoom:1;padding:5px;margin:5px;height:400px; overflow-x:hidden; overflow-y:auto;background:" + $.a.background + ";border:" + $.a.border + ";width:" + $.a.width + "}",
       "ul" : "{margin:0; padding:0;}",
       "ul li" : "{list-style:none;}"
      };
      var ieRules = " ";
      for (r in rules) {
       var selector = '.' + trueName + ' ' + r;
       if (!window.createPopup) {
        var theRule = document.createTextNode(selector + rules[r]);
        ns.appendChild(theRule);
       } else {
        ieRules += selector + rules[r];
       }
      }
      if (window.createPopup) {
       s.cssText = ieRules;
      }
      $.w.className = trueName;
            $.w.q = document.createElement('H3');
            $.w.q.innerHTML = 'Yesterday\'s Craigslist gigs'
	    $.w.appendChild($.w.q);
            $.w.r = document.createElement('UL');
	    
            $.w.appendChild($.w.r);
			$.f.runPipe();
         },
         runPipe : function() {
            $.w.r.innerHTML = '';
               var n = $.f.runFunction.length;
               var id = trueName + '.f.runFunction[' + n + ']';
               $.f.runFunction[n] = function(r) {
                  delete($.f.runFunction[n]);
                  $.f.removeScript(id);
                  $.f.renderResult(r);
               }
               var url = 'http://pipes.yahoo.com/pipes/pipe.run?';
               url += '_id=de2a43d0efcb49b7470bd92b807dc35e';
               url += '&_render=json';
               url += '&_callback=' + id;
               $.f.runScript(url, id);
         },
         renderResult: function(r) {
            for (var i = 0; i < r.count; i++) {
               var li = document.createElement('LI');
               var a = document.createElement('A');
               a.innerHTML = r.value.items[i].title;
               a.href = r.value.items[i].link;
               a.target = '_blank';
               li.appendChild(a);
               $.w.r.appendChild(li);
            }
         },
         runScript : function(url, id) {
            var s = document.createElement('script');
            s.id = id;
            s.type ='text/javascript';
            s.src = url;
            document.getElementsByTagName('body')[0].appendChild(s);
         },
         removeScript : function(id) {
            var s = '';
            if (s = document.getElementById(id)) {
               s.parentNode.removeChild(s);
            }
         }
      };
   }();
   var thisScript = /^http?:\/\/[^\/]*technopoetic.com\/published\/Widget3.js$/;
   if(typeof window.addEventListener !== 'undefined') {
      window.addEventListener('load', function() { $.f.init(thisScript); }, false);
   } else if(typeof window.attachEvent !== 'undefined') {
      window.attachEvent('onload', function() { $.f.init(thisScript); });
   }
} )();

