$(document).ready(function(){

	var initialDelay = 3200;
	var allCourses = getAllCourseNames("#gp-writer");
	$("#random-banner").hide();
	
	$("#overlay-nine").hide().fadeIn(5000);$("#gp-title").hide();
	$("#gp-title").fadeIn(2000);$("#gp-desc").hide().fadeIn(6000).typewriter();$("#gp-writer > p").hide();
	animationLoop(3200);
	window.setInterval(animationLoop(initialDelay), 5000);
		
	function animationLoop(currentTimeline) {
		fadeAnimation(currentTimeline, 1.0);
		fadeAnimation(currentTimeline * 1.5, 0.3);
		initialDelay += 3000;
	} 
	
	function fadeAnimation(initialDelay, fadeValue) {
		var delay = initialDelay;
		$("#gp-writer > p").each(function(){
			$(this).delay(delay).fadeTo("slow", fadeValue);
			delay += 200;
		});
	}
	
	function appearRandomCourse() {
		appearCourse(allCourses[randomInRange(0, allCourses.length - 1)]);
	}
	
	/*
	("#gp-writer > p:first-child").css({position:"relative",left:"-400px"});
	$("#gp-writer > p:first-child").delay(3200).animate({left:"0px",opacity:"toggle"},2000);
	$("#gp-writer > p:nth-child(2)").css({position:"relative",left:"200px"});
	$("#gp-writer > p:nth-child(2)").delay(3600).animate({left:"0px",opacity:"toggle"},2000);
	$("#gp-writer > p:nth-child(3)").css({position:"relative",left:"20px"});
	$("#gp-writer > p:nth-child(3)").delay(4000).animate({left:"0px",opacity:"toggle"},2000);
	$("#gp-writer > p:nth-child(4)").css({position:"relative",top:"20px"});
	$("#gp-writer > p:nth-child(4)").delay(4400).animate({top:"0px",opacity:"toggle"},2000);
	$("#gp-writer > p:nth-child(5)").css({position:"relative",top:"80px"});
	$("#gp-writer > p:nth-child(5)").delay(4800).animate({top:"0px",opacity:"toggle"},2000);
	$("#gp-writer > p:nth-child(6)").css({position:"relative",top:"10px"});
	$("#gp-writer > p:nth-child(6)").delay(5200).animate({top:"0px",opacity:"toggle"},2000);
	$("#gp-writer > p:nth-child(7)").css({position:"relative",top:"10px",right:"10px"});
	$("#gp-writer > p:nth-child(7)").delay(5600).animate({top:"0px",right:"0px",opacity:"toggle"},2000);
	$("#gp-writer > p:nth-child(8)").css({position:"relative",top:"10px",left:"50px"});
	$("#gp-writer > p:nth-child(8)").delay(6000).animate({top:"0px",left:"0px",opacity:"toggle"},2000);
	$("#gp-writer > p:nth-child(9)").css({position:"relative",bottom:"10px",left:"50px"});
	$("#gp-writer > p:nth-child(9)").delay(6400).animate({bottom:"0px",left:"0px",opacity:"toggle"},2000);	
	*/


});

function randomInRange(start,end){
   return Math.floor(Math.random() * (end - start + 1) + start);
}

function getAllCourseNames(rootEle) {
	var result = [];
	$(rootEle).children().each(function(){
		result.push($(this).html());
	});
	return result;
}
