﻿var timeout;
var fadeDelay = 5000;
var fadeOutSpeed = 500;
var fadeInSpeed = 500;
var thisItem;
var nextItem;
var totalItems;

$(document).ready(function() {    
	totalItems = $(".APTHLMonitorSection td").length;
	$(".APTHLMonitorSection").show();
	startSlideShow();
});

function startSlideShow() {

	//establishes start positions
	//
	//much of this is superfluous for the first run, but is to fix problems when the
	//tab is switched back from the twitter tab
	
	thisItem = 0;
	nextItem = 1;
	$(".APTHLMonitorSection td").children().show();
	$(".APTHLMonitorSection tr").children().fadeTo(0, 1);
	$(".APTHLMonitorSection tr").children().hide();
	$(".APTHLMonitorSection tr").eq(thisItem).children().show();
	$(".HLLink1, .HLLink2, .HLLink3").removeClass("APTHLBlue");
	$(".HLLink1, .HLLink2, .HLLink3").eq(thisItem).addClass("APTHLBlue");
	SStimeout = setTimeout("cycleSlideShow()", fadeDelay);
}

function cycleSlideShow() {

	$(".HLLink1, .HLLink2, .HLLink3").eq(thisItem).removeClass("APTHLBlue");
	$(".APTHLMonitorSection tr").eq(thisItem).children().fadeOut(fadeOutSpeed, 
		function()
		{
			$(".APTHLMonitorSection tr").eq(nextItem).children().fadeIn(fadeInSpeed);
			$(".HLLink1, .HLLink2, .HLLink3").eq(nextItem).addClass("APTHLBlue");
			if(thisItem == totalItems - 1) thisItem = 0;
			else thisItem++;
			if(nextItem == totalItems - 1) nextItem = 0;
			else nextItem++;
			SStimeout = setTimeout("cycleSlideShow()", fadeDelay);
		}
	);
}
