var showing = 1;
var oldid = 1;
var animating = 0;
var last_hover = 0;

$(document).ready(function(){

	preload([
		'images/sidekick-header.png',
		'images/sword-header.png',
		'images/sush-header.png',
	]);

	function check_hover(idName) {
		trueID = 0;
		if (idName == "slide-1") { trueID = 1; }
		else if (idName == "slide-2") { trueID = 2; }
		else if (idName == "slide-3") { trueID = 3; }
		else { return false; }

		if(showing == trueID) {
			return false;
		}

		last_hover = trueID;
		if(animating > 2) {
			return false;
		}

		oldid = showing;
		showing = trueID;

		animating++;

		$("#slide-"+oldid).removeClass("highlight");


		// For sliding them in and out simultaneously

		$("#p"+oldid).hide(400);
		$("#p"+trueID).show(400, function() {
			animating--;
			if(animating < 1) animating = 0;
			if(showing != last_hover) {
				//alert("showing = " + showing + ", last_hover = " + last_hover);
				//setTimeout("check_hover(last_hover)", 100);
			}
		});

		// For fading them out and back in
		/*
		$("#p"+oldid).fadeOut(200, function() {
			$("#p"+trueID).fadeIn(800, function() {
				animating = 0;
			});
		});
		*/

		$("#slide-"+trueID).addClass("highlight");
	}

	// Set up the slider functionality
	$(".third").hover(function(event){
		idName = this.id;
		//last_hover = this.id;
		//last_hover = last_hover.replace("slide-", "");
		check_hover(idName);
	}, function(event) {});

});

function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
        // Alternatively you could use:
        // (new Image()).src = this;
    });
}

