( 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 {
         init : function() {
            $.f.houseKeep();
            $.f.buildStructure();
            $.f.buildBehavior();
         },
         buildBehavior : function() {
            $.f.ping();
            setInterval($.f.animate, 100);
            setInterval($.f.ping, 60000);
         }, 
         animate : function() {
            var n = $.v.d.length;
            for (var i = 0; i < n; i++) {
               var d = $.v.d[i];
               if (d.className == 'tweet') {
                  d.x = d.x + d.dx;
                  if (d.x < 0) { d.x = 0; d.dx = 0 - d.dx; d.style.zIndex++;}
                  if (d.x > (document.body.offsetWidth - d.offsetWidth)) { d.x = (document.body.offsetWidth - d.offsetWidth); d.dx = 0 - d.dx; d.style.zIndex++;}
               } 
               if (d.className == 'flick') {
                  d.y = d.y + d.dy;
                  if (d.y < 0) { d.y = 0; d.dy = 0 - d.dy; d.style.zIndex++;}
                  if (d.y > (document.body.offsetHeight - d.offsetHeight)) { d.y = (document.body.offsetHeight - d.offsetHeight); d.dy = 0 - d.dy; d.style.zIndex++;}
               }
               d.style.top = d.y;
               d.style.left = d.x;
            }
         },
         buildStructure : function() {
            $.s = document.getElementsByTagName('BODY')[0].appendChild(document.createElement('DIV'));
            $.s.className = 'radar';
         },
         ping : function() {
            if (!$.f.pong) { $.f.pong = []; }
            var n = $.f.pong.length;
            var id = trueName + '.f.pong%5B' + n + '%5D';
            $.f.pong[n] = function(r) {
               delete($.f.pong[n]);
               $.f.removeScript(id);
               $.f.doStuffWith(r);
            }
            var url = 'http://pipes.yahoo.com/pipes/pipe.run?_id=48008a3405a20dbbd847cf0916cc961e';
            url += '&t=' + $.a.t + '&f=' + $.a.f;
            url += '&_render=json&_callback=' + id;
            $.f.runScript(url, id);
         },
         doStuffWith : function(z) {
            $.v.d = [];
            $.v.maxZ = 8675309;
            $.s.innerHTML = '<p class="info">twitter + flickr</br>' + $.a.t + ' on <a href="http://search.twitter.com/search?q=' + $.a.t + '" target="_vu">twitter</a> + ' + $.a.f + ' on <a href="http://flickr.com/search/?q=' + $.a.f + '&s=rec" target="_vu">flickr</a><br />questions? comments? ping <a href="http://twitter.com/kentbrew" target="_vu">@kentbrew</a></p>';
            var r = z.value.items;
            $.a.dupe = [];

            for (var i = 0; i < r.length; i++) {
               if (!r[i].k && $.a.dupe.length < 10 ) {
                  doy = 0;
                  for (var j = 0; j < $.a.dupe.length; j++) {
                     if (r[i].a === $.a.dupe[j]) {
                         doy = 1;                        
                     }
                  }
                  if (!doy) {
                     $.a.dupe[$.a.dupe.length] = r[i].a;
                     $.f.tweet(r[i]);
                  }               
               }
               if (r[i].k == 'flickr') {
                  $.f.flick(r[i]);
               }            
            }
         },
         tweet : function(t) {
            var d = document.createElement('DIV')
            d.className = 'tweet';
            var img = document.createElement('IMG');
            img.height = '48';
            img.width = '48'
            img.src = t.n;
            d.appendChild(img);
            var c = document.createElement('CITE');
            var a = document.createElement('A');
            a.innerHTML = t.a;
            a.href = 'http://twitter.com/' + t.a;
            a.target = '_vu';
            c.appendChild(a);
            c.appendChild(document.createTextNode(': '));
            d.appendChild(c);
            var s = document.createElement('SPAN');
            s.innerHTML = t.t;
            d.appendChild(s);
            $.s.appendChild(d);
            $.f.addAnimate(d);
            return true;
         },
         flick : function(t) {
            var d = document.createElement('DIV')
            d.className = 'flick';
            var img = document.createElement('DIV');
            img.className = 'img';
            img.style.background = 'transparent url(' + t.n + ') 50% 50% no-repeat';
            d.appendChild(img);
            var p = document.createElement('P');
            var c = document.createElement('CITE');
            var a = document.createElement('A');
            a.innerHTML = t.a;
            a.target = '_vu';
            a.href = t.u;
            c.appendChild(a);
            c.appendChild(document.createTextNode(': '));
            p.appendChild(c);
            var s = document.createElement('SPAN');
            s.innerHTML = t.t;
            p.appendChild(s);
            d.appendChild(p);
            $.s.appendChild(d);
            $.f.addAnimate(d);
         },
         addAnimate : function(d) {
            var n = $.v.d.length;
            $.v.d[n] = d;
            $.v.d[n].style.position = 'absolute';
            $.v.d[n].x = (Math.floor(Math.random() * (document.body.offsetWidth - d.offsetWidth)));
            $.v.d[n].dx = (Math.floor(Math.random() * 12) - 6);
            $.v.d[n].y = (Math.floor(Math.random() * (document.body.offsetHeight - d.offsetHeight)));
            $.v.d[n].dy = (Math.floor(Math.random() * 12) - 6);
            if (!$.v.d[n].dx) { $.v.d[n].dx = 1; }
            if (!$.v.d[n].dy) { $.v.d[n].dy = -1; }
            $.v.d[n].style.top = '100px';
            $.v.d[n].style.left = '100px';
            $.v.d[n].onmouseover = function() {
               this.style.zIndex = $.v.maxZ + 1;
               $.v.maxZ++;
            }
         },
         runScript : function(url, id) {
            var s = document.createElement('script');
            s.id = id;
            s.type ='text/javascript';
            s.charset = 'utf-8';
            s.src = url;
            document.getElementsByTagName('body')[0].appendChild(s);
         },
         removeScript : function(id) {
            var s = document.getElementById(id);
            if (s !== 'undefined') { s.parentNode.removeChild(s); }
         },
         houseKeep : function() {
            // thank you: Keith Brewster
            $.a = {};
            var p = location.search.replace(/\?/, '').split('&');
            for (var i = 0; i < p.length; i++) {
               var q = p[i].split('=');
               if (q[0] && q[1]) {
                  $.a[q[0]] = q[1];
               }
            }
            if (!$.a.t) {
               $.a.t = 'hackday';
            }
            
            if (!$.a.f) {
               $.a.f = 'openhack08';
            }
            
            if (!$.a.b) {
               $.a.b = 'hi217,Blondie_Emily,hi215,goobama11,thomaaaas';
            }
                      
            $.a.block = [];
            
            var bbbb = $.a.b.split(',');
            for (var i =0; i < bbbb.length; i++) {
               $.a.block[i] = bbbb[i];
            }

            $.v = {};
            $.v.d = [];
            $.v.q = {};
         }
      };
   }();
   $.f.init();
})();