/* Illegal copying of this code prohibited by real patsan's law! */

function twihoo() {
 this.globalTop = 0;
 this.wait = 0;
 this.pause = 0;
 this.speed = 3000;
 this.win = 0;
 this.lastid = 0;
 this.saytmt, this.movetmt;
 this.onlynew = 0;
 this.project = 2;
 this.order = 0;

 this.say = function(){
  if ($("li").length < 40) {
   t.wait = 1;
     
   $.getJSON('http://twihoo.com/list?p='+ t.project 
     + '&' + Math.random() 
     + ( t.order ? '&order=ask' : '&order=desc' )
     + ( t.onlynew ? ('&since=' + t.lastid ) : '' ) 
     + ( t.win ? ('&enc=win') : '' ) 
     + '&callback=?',
    function(data,textStatus){
     $.each(data, function(i,item){
      if (window.location.href.indexOf('roem')!=-1) {
       $("<li style='margin:0px 0px 20px 0px;' class='headline'>").html('<table><tr><td width="60"><a href="http://twitter.com/'+ item[1] +'" target="_blank"><img src="'+ item[3] +'" border="0" width="48" height="48"></a></td><td align="left" style="font-size:120%">'+ item[4].replace(/<strong>/g,'<strong class="s">') +'</td></tr></table>').appendTo("#scrollup");
      } else {
       $("<li style='margin:0px 0px 20px 0px;' class='headline'>").html('<table><tr><td><a href="http://twitter.com/'+ item[1] +'" target="_blank"><img src="'+ item[3] +'" border="0" width="48" height="48"></a></td><td>'+ item[4].replace(/<strong>/g,'<strong class="s">') +'</td></tr></table>').appendTo("#scrollup");
      }
      t.lastid = item[0];
     });
     data = null;
     t.wait = 0;
   });
  }
  t.saytmt = setTimeout('t.say()',10000);
 };

 this.getTop = function() {
  t.globalTop = $("#monitor").height();
  $.each($("li.screen"), function(i,item) {
   t.globalTop-=$(item).height()+20;
  });
  return t.globalTop;
 }
  
 this.move = function() {
  clearTimeout(t.movetmt);
  tTop = 0;
  if ($("li.headline").length && t.pause==0) {
   tTop = t.getTop();
   $("li.headline:first").attr("class","screen");
   $("#scrollup").animate( { top: tTop }, { queue: false, duration: ((tTop>10) ? 10 : 700), complete:function(){ 
    if (t.globalTop < -100) {
     t.globalTop+=($("li.screen:first").height()+20); 
     $("li.screen:first").remove();
     $("#scrollup").css('top',t.globalTop+'px');
    };
   }});
  }
  t.movetmt = setTimeout('t.move()',(tTop>0) ? 10 : t.speed);
 };

 this.sized = function() { 
  $("#monitor").height($("#monitor").height()); 
 }

 this.paused = function() {
  if (t.pause==0) {
   $('li#sactive').attr("id","");
   $('li.s0').attr("id","sactive");
   t.pause=1;
  } else {
   $('li.s0').attr("id","");
   $('li.'+((t.speed==6000) ? 's1' : ( (t.speed==3000) ? 's2' : 's3' ))).attr("id","sactive");
   t.pause=0;
  }
  return false;
 }

 $('#monitor').html('<ul id="scrollup" style="margin:0px;padding:0px;list-style:none;position:relative"></ul>');
 $('#monitor').css('overflow','hidden');
 $('#monitor').css('position','relative');
 if($.browser.msie) {
//  document.getElementById('monitor').style.height = "200px";
 }
 $("#scrollup").css('top',$("#monitor").height()+'px');
};

$(document).ready(function(){
 t=new twihoo();
 if (window.location.href.indexOf('forest')!=-1) {
  t.order = 1;
  t.onlynew = 1;
  t.project = 7;
 }
 if (window.location.href.indexOf('ok2009')!=-1) {
  t.win = 1;
  t.project = 2;
  $('#menu ul').css('z-index','10');
 }
 if (window.location.href.indexOf('remix')!=-1) {
  t.win = 0;
  t.project = 6;
 }
 if (window.location.href.indexOf('narod')!=-1) {
  t.win = 0;
  t.onlynew = 1;
  t.project = 23;
 }
 if (window.location.href.indexOf('fire')!=-1) {
  t.win = 0;
  t.onlynew = 1;
  t.project = 25;
 }
 if (window.location.href.indexOf('radio')!=-1) {
  t.win = 0;
  t.project = 16;
 }
 if (window.location.href.indexOf('roem')!=-1) {
  t.win = 1;
 }
 t.sized();
 t.say();
 t.move();
});

$(window).keypress(function (e) {if (e.which==32) {return t.paused()}});
