var hover = 0;
var currentNode = 1;
var nodeCount = 0;
var t;
$(document).ready(function() {
	//ghetto redirect event binding
	$("#logo").click(function() {
		window.location = "http://www.epicfit.com/index.html";
	});
	$("#n_tr").click(function() {
		window.location = "http://www.epicfit.com/pages/treadmills.html";
	});
	$("#n_el").click(function() {
		window.location = "http://www.epicfit.com/pages/ellipticals.html";
	});
	$("#n_bk").click(function() {
		window.location = "http://www.epicfit.com/pages/bikes.html";
	});
	$("#n_str").click(function() {
		window.location = "http://www.epicfit.com/pages/strength.html";
	});
	$("#n_ac").click(function() {
		window.location = "http://www.epicfit.com/pages/accessories.html";
	});
	
	// init animation should only use the slideRight and slideUp animations.
	$("li.active div.lorbitOverlay").fadeIn(function(){
		$("li.active p.lorbitCopy").slideDown(function(){
			$("li.active p.lorbitTitle").fadeIn();
		});
	});

	nodeCount = $("#lorbit").children("li").length;
	$("#nodeTotal").text(nodeCount);
	$("#currentNode").text(currentNode);
	$("#switch").show();
	
	setTimeout('hoverCheck()', 3000);
	$("#lorbit").parent().hover(function(){hover = 1;},function(){hover = 0;});
});

function lorbit() {
	current = $("li.active");
	if ($("li.active").next().length == 0) {
		next = $("#lorbit li:first-child");
		currentNode = 1;
	} else {
		next = $("li.active").next();
		currentNode += 1;
	}
	clearLorbit(current,next);
}

function clearLorbit(current,next) {
	current.fadeOut(function(){
		$("li.active div.lorbitOverlay").hide();
		$("li.active p.lorbitCopy").hide();
		$("li.active p.lorbitTitle").hide();
		loadLorbit(current, next);
	});
}
	
function loadLorbit(current,next) {
	current.removeClass("active");
	$("#currentNode").text(currentNode);
	next.addClass("active").fadeIn(function(){
		$("li.active div.lorbitOverlay").fadeIn(function() {
			$("li.active p.lorbitCopy").slideDown(function(){
				$("li.active p.lorbitTitle").fadeIn();
			});
		});
	});
	clearTimeout(t);
	t = setTimeout('hoverCheck()', 5000);
}

function hoverCheck() {
	if(hover == 1) {
		t = setTimeout('hoverCheck()', 2000);
	} else {
		lorbit();
	}
}

function lorbitPrev() {
	current = $("li.active");
	if ($("li.active").prev().length == 0) {
		next = $("#lorbit li:last-child");
		currentNode = nodeCount;
	} else {
		next = $("li.active").prev();
		currentNode -= 1;
	}
	// remove preset timeout
	clearLorbit(current,next);
}
