// javascript can go here

$(document).ready(function() {
  // DOM (document object model) is done loading!
  populateTwitter();
  if ( !$.browser.msie ) {
    $('#header').css('opacity', '0.0');
    
    $('#page').css('opacity', '0.0');
    $('#ads').css('opacity', '0.0');
    $('#footer').css('opacity', '0.0');
    animatePage();
  }
  else {
    $('#header').css('opacity', '1.0');
    
    $('#page').css('opacity', '1.0');
    $('#ads').css('opacity', '0.0');
    $('#footer').css('opacity', '1.0');  
  }
});

function populateTwitter() {
  $.jTwitter('digitaldokuro', 1, function(data) {
    $('#josh_tweet').empty();
        $.each(data, function(i, post) {
          post = post.text;
          startPosition = post.indexOf('http://');
       		if ( post.indexOf(')', startPosition+1) != -1) {
       		  endPosition = post.indexOf(')', startPosition+1);
       		}
       		else if ( post.indexOf(' ', startPosition+1) != -1) {
       		  endPosition = post.indexOf(' ', startPosition+1);
       		}
       		else if ( post.indexOf('!', startPosition+1) != -1) {
       		  endPosition = post.indexOf('!', startPosition+1);
       		}
       		else if ( post.indexOf('?', startPosition+1) != -1) {
       		  endPosition = post.indexOf('?', startPosition+1);
       		}
       		else {
       		  endPosition = post.length;
       		}
          postTextUrl = post.slice(startPosition, endPosition);
          newString = '<a href=\"'+postTextUrl+'\">'+postTextUrl+'</a>';
          post = post.replace(postTextUrl, newString);
          $('#josh_tweet').append(post);
        });
  });
   $.jTwitter('8bitginger', 1, function(data) {
    $('#kim_tweet').empty();
        $.each(data, function(i, post) {
          post = post.text;
          startPosition = post.indexOf('http://');
       		if ( post.indexOf(')', startPosition+1) != -1) {
       		  endPosition = post.indexOf(')', startPosition+1);
       		}
       		else if ( post.indexOf(' ', startPosition+1) != -1) {
       		  endPosition = post.indexOf(' ', startPosition+1);
       		}
       		else if ( post.indexOf('!', startPosition+1) != -1) {
       		  endPosition = post.indexOf('!', startPosition+1);
       		}
       		else if ( post.indexOf('?', startPosition+1) != -1) {
       		  endPosition = post.indexOf('?', startPosition+1);
       		}
       		else {
       		  endPosition = post.length;
       		}
          postTextUrl = post.slice(startPosition, endPosition);
          newString = '<a href=\"'+postTextUrl+'\">'+postTextUrl+'</a>';
          post = post.replace(postTextUrl, newString);
          $('#kim_tweet').append(post);
        });
  });  
}

function animatePage() {
 $('#header').animate({
      opacity:1.0
  },500, function() {
    $('#page').animate( {
        opacity:1.0
    },500, function() {
      $('#ads').animate( {
          opacity:1.0
      },500, function() {
        $('#footer').animate( {
          opacity:1.0
        })
      });
    });
  }); 
}
