var contentStatus = ".generalStats";
$(document).ready(function(){
	// add illustration div hooks
	$(".stops h2").after("<div class='illustration'></div>");

	// setup day counter thermometer
	var today = new Date();
	var arriveDate = new Date("09/02/2011");
	var departDate = new Date("09/24/2011");
	var daysUntilLeave = Math.round((arriveDate - today) / 86400000);
	var daysUntilDepart = Math.round((departDate - today) / 86400000);

	// Stats - Days Spent
	var daysSpent = (21 - daysUntilDepart);
	if(daysSpent < 0) {
		daysSpent = 0;
	} else if(daysSpent > 21) {
		daysSpent = 21;
	}
	$(".stats .days p").html(daysSpent + " <span>of</span> 21");
	$(".stats .days .chart").css("width", 210 * (daysSpent / 21));

	// Stats - KMs Travelled
	var travelledSoFarArray = [0, 13211, 13211, 13211, 13211, 13211, 13924, 13924, 13924, 15124, 15124, 15124, 15124, 17244, 17244, 17244, 18633, 18633, 18633, 18633, 19361, 32572]; // 1276 sf + 11935 syd + 713 melb + 1200 ade + 2120 cairns + 1389 bri + 728 syd + 11935 sf + 1276 van
	$(".stats .kms p").html(travelledSoFarArray[daysSpent] + " <span>of</span> 32572");
	$(".stats .kms .chart").css("width", 210 * (travelledSoFarArray[daysSpent] / 32572));

	// setup day main text counter
	if(daysUntilLeave > 1) {
		$(".aboutTheTrip .dayCount").html(daysUntilLeave + " days");
	} else if(daysUntilLeave == 1) {
		$(".aboutTheTrip .dayCount").html(" tomorrow");
	} else if(daysUntilLeave == 0) {
		$(".aboutTheTrip .dayCount").html("hours");
	} else if(daysUntilLeave < 0 && daysUntilDepart > 0) {
		$(".aboutTheTrip .countdown").html("We're in Australia! <span class='dayCount'>Back soon</span>.");
	} else {
		$(".aboutTheTrip .countdown").html("We're back home, what a great trip.");
	}


	// figure out
	$("nav .route").click(function(e){
		$.scrollTo(0, 500);
		e.preventDefault();
	});
	$("nav .updates").click(function(e){
		$.scrollTo("#blog", 500);
		e.preventDefault();
	});
	$(".stops a").hover(
	  function () {
		$(this).parent().parent().find(".illustration").stop().animate({opacity:1}, 200);
	  },
	  function () {
	    $(this).parent().parent().find(".illustration").stop().animate({opacity:0}, 500);
	  }
	);
	$(".stops a").click(function(e){
		$(contentStatus).hide();
		contentStatus = ".explanation." + $(this).parent().parent().attr("class");
		$(contentStatus).show();
		$.scrollTo(200, 500);
		e.preventDefault();
	});

	// twitter
	$(".twitterupdates").html($("#twitter_update_list li span").html());
});

