/*
 Animated slideshow for twitter
*/
var twitterShow = {

  reference:null,
  count:null,
  slide:null,
  current: 1, // the current slide selected
  offset: 209, // the length of each slide (assuming that they are equal)
  
  init:function(){
    
    if(document.getElementById('twitter_update_list')){
    
      twitterShow.reference = document.getElementById('twitter_update_list');
      twitterShow.count = document.getElementById('twitter_count');
      
      twitterShow.count.style.display = 'block';
     
      var links = twitterShow.count.getElementsByTagName('A');
    
      for(var x=0; x<links.length; x++){
      
        links[x].onclick = function(){ // switch slide
        
          this.parentNode.className += ' selected';
        
          var next = parseInt(this.innerHTML);
          var timer = 0;
          
          if(next != twitterShow.current){
          
            var curr = twitterShow.offset * (twitterShow.current-1);
            var to = twitterShow.offset * (next-1);
            
            while(curr != to){
              setTimeout('twitterShow.set(' + curr + ')' , (timer * 1));
              timer++;
              
              if(curr > to){
                var diff = curr-to;
                if(diff>(twitterShow.offset*3))curr-=5; // adjust the curr
                else if(diff>(twitterShow.offset*2))curr-=4; // adjust the curr
                else if(diff>twitterShow.offset)curr-=3; // adjust the curr
                  else curr--;  
              }
              else if(curr < to){
                var diff = to-curr;
                if(diff>(twitterShow.offset*3))curr+=5; // adjust the curr
                else if(diff>(twitterShow.offset*2))curr+=4; // adjust the curr
                else if(diff>twitterShow.offset)curr+=3; // adjust the curr
                  else curr++;
              }
            }
          
          }
          
          twitterShow.current = next;
          
          var other = twitterShow.count.getElementsByTagName('A');
    
          for(var y=0; y<other.length; y++){
            other[y].parentNode.className = other[y].parentNode.className.replace('selected', '');
          }
          
          this.parentNode.className = 'selected';
          
          this.blur();
          
          return false;
        }
      
      }
    
    }
  
  },
  
  /*
    sets the position of the slider
  */
  set:function(left){
    twitterShow.reference.style.marginLeft = '-' + left + 'px';
  }

}

window.onload = twitterShow.init;