var storyList = new Array;
var tweetList = new Array;

getStories = function() {
	jQuery.getJSON("/skybox/stories.json",
        function(data){
          for(x in data) {
          	story = data[x];
			story.headline = unescape(story.headline);
			story.link = unescape(story.link);
			story.section = unescape(story.section);
			formatStory(story);
          }
         getTweets();
    });
}

formatStory = function(item)
{
    var html = '';
    html += '<div class="item">';
    html += '<span class="section">' + item.section + ' | </span>';
    html += '<a href="' + item.link + '">' + item.headline + '<\/a><\/div>';
    storyList.push(html);
};


getTweets = function () {
	$.getJSON("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=vassarvsa&trim_user=true&count=" + (storyList.length + 1) + "&callback=?",
        function(data){
          $.each(data, function(i,item){
            formatTweet(item.id, item.text);
          });
        printSkybox();
        });
};

formatTweet = function(id, text) {
	if (text.length > 115) {
		text = text.slice(0,114);
		text += '...';
	}
	var html = ''
	html += '<div class="item"><span class="section tweet">';
	html += '<a href="http://twitter.com/vassarvsa">vassarvsa</a> | </span>';
	html += '<a href="http://twitter.com/vassarvsa/status/' + id + '">';
	html += text + '<\/a><\/div>';
	tweetList.push(html);
};


printSkybox = function() {
	var html = '';
	
	for(x in storyList) {
		html += storyList[x];
		html += tweetList[x];
	}
		
	$('#skybox').html(html);
	
	$('#skybox').cycle({ 
		fx:      'fade', 
		sync: 0,
		speed: 750,
		timeout: 5250
	});
}
