// JavaScript Document
// Written by John Keese, http://www.johnkeese.com
// Feel free to use it, but drop me a line and let me know... it makes me feel good

var datastream = {};
var temp = {};
var addstuff = "";
var randomNum = 0;
var someTimer;
var delay = 10000; //10 second delay between entries
var feedString = "";
//$.getJSON("http://pipes.yahoo.com/neopsalms/feedone?_render=json&_callback=?",

function firsttime() {
	addstuff = ""; //reset entry
	$.getJSON(feedString,
	function(data){
		randomNum = Math.floor(Math.random() * data.count); //get a random number -> count
		temp = data.value.items[randomNum]; //assign item[x] to temp
		
		addstuff = "<div id=\"entry\"><p>" + temp.description + " <a href=\"" + temp["y:id"].value + "\" target=\"_blank\">more</a></p></div><div id=\"author\"><h1><a href=\"" + temp["y:id"].value + "\" target=\"_blank\">" + temp["y:title"] + "</a></h1><h3>" + temp["dc:creator"].content + "</h3></div>"; //create entry
		var letsBegin = setTimeout("stuff()", 7000);//7 second delay the beginning
	});
}
function randomFeed() {// this way there's not one huge feed - at least in my thinking
	randomNum = Math.floor(Math.random() * 4); // number = number of feeds
	switch(randomNum) {
		case 0: feedString = "http://pipes.yahoo.com/neopsalms/feedone?_render=json&_callback=?"; break;
		case 1: feedString = "http://pipes.yahoo.com/neopsalms/feedtwo?_render=json&_callback=?"; break;
		case 2: feedString = "http://pipes.yahoo.com/neopsalms/feedthree?_render=json&_callback=?"; break;
		case 3: feedString = "http://pipes.yahoo.com/neopsalms/feedfour?_render=json&_callback=?"; break;
		default: alert("Something broke. My bad. Please shoot me an email and let me know what's up. Thanks!"); break;
	}
}	
function stuff() {
	$("#stuff").html(addstuff);
	$("#stuff").show("slide", {direction: "left"}, 1000); //slide in
	
	addstuff = ""; //reset entry
	$.getJSON(feedString,
	function(data){
		randomNum = Math.floor(Math.random() * data.count); //get a random number -> count
		temp = data.value.items[randomNum]; //assign item[x] to temp
		
		addstuff = "<div id=\"entry\"><p>" + temp.description + " <a href=\"" + temp["y:id"].value + "\" target=\"_blank\">more</a></p></div><div id=\"author\"><h1><a href=\"" + temp["y:id"].value + "\" target=\"_blank\">" + temp["y:title"] + "</a></h1><h3>" + temp["dc:creator"].content + "</h3></div>"; //create entry
	});
	someTimer = setTimeout("goaway()", delay);
}
function goaway() {
	$("#stuff").hide("slide", {direction: "right"}, 1000, stuff); //slide out
}
$(document).ready(function(){
	animatedcollapse.addDiv('alt1','group=all,hide=1');
	animatedcollapse.addDiv('alt2','group=all,hide=1');
	animatedcollapse.addDiv('alt3','group=all,hide=1');
	animatedcollapse.addDiv('alt4','group=all,hide=1');
	animatedcollapse.addDiv('alt5','group=all,hide=1');
	animatedcollapse.init();
	
	$('a.about').click(function(){
		animatedcollapse.toggle('alt1');
		$.scrollTo('#here',1000);
		return false;
	});
	$('a.process').click(function(){
		animatedcollapse.toggle('alt2');
		$.scrollTo('#here',1000);
		return false;
	});
	$('a.contact').click(function(){
		animatedcollapse.toggle('alt3');
		$.scrollTo('#here',1000);
		return false;
	});
	$('a.and').click(function(){
		animatedcollapse.toggle('alt4');
		$.scrollTo('#here',1000);
		return false;
	});
	$('a.sixteen14').click(function(){
		animatedcollapse.toggle('alt5');
		$.scrollTo('#here',1000);
		return false;
	});
	$('a.increaseDelay').click(function(){
		delay -= 1000;
		$.jGrowl("Delay is now " + (delay/1000) + " seconds.");
		return false;
	});
	$('a.decreaseDelay').click(function(){
		delay += 1000;
		$.jGrowl("Delay is now " + (delay/1000) + " seconds.");
		return false;
	});
	$('a.pausePlay').toggle(
		function() {
			$(this).text("Play");
			clearTimeout(someTimer);
		},
		function() {
			$(this).text("Pause");
			goaway();
		}
	);
	randomFeed();
	firsttime();
});
