// Tip of the Day (infinite slider)
// Author: Ryan Tovar
// Created: 2011.09.22
// Requires jQuery; built and tested using version 1.6.4

var tipArray = [];
var currentTipIndex = 0;
var secondsBetweenSlides = 10; // how many seconds between slide transitions
var secondsForTransition = 1.5 // how many seconds the transition/animation itself takes
var containerWidth = 359; // how wide is each slide
var xmlFilePath = "xml/tod.xml"; // where does the XML file that contains the tips reside

function parseTips(xml)	{
	$(xml).find("tip").each(function() {
		var tipText = $(this).text();
		tipArray.push(tipText);
	});
}

function advanceReel()	{
	var $firstTip = $("#TipReel td:nth-child(1)");
	var $secondTip = $("#TipReel td:nth-child(2)");
	$firstTip.animate({"left":"-=" + containerWidth + "px"},(secondsForTransition*1000),function() {
		$firstTip.css("left",containerWidth + "px").html(tipArray[currentTipIndex]);
		currentTipIndex++;
		if (currentTipIndex >= tipArray.length) {
			currentTipIndex = 0;
		}
	});
	$secondTip.animate({"left":"-=" + containerWidth + "px"},(secondsForTransition*1000));
	$firstTip.insertAfter($secondTip);
}

$(document).ready(function()	{
	$.ajax({
		type: "GET",
		url: xmlFilePath,
		dataType: "xml",
		async: false,
		success: parseTips
	});
	$("#TipReel td:nth-child(1)").html(tipArray[currentTipIndex]);
	currentTipIndex++;
	$("#TipReel td:nth-child(2)").html(tipArray[currentTipIndex]);
	currentTipIndex++;
	window.setInterval(advanceReel,(secondsBetweenSlides*1000));
});
