
/*JQUERY SLIDESHOW**********************************************************
  BY MARCOFOLIO.NET********************************************************/
  
  
// Speed of the automatic slideshow
var slideshowSpeed = 10000;

// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [ {
		"image" : "/images/jqslideshow/play.jpg",
		"text" : "<div class='box-1'><h1>E<sup>2</sup> is a place to <strong>play!</strong></h1><p><strong>Climb</strong> our tree, try the trucks,<br>	jump, <strong>jump</strong>, jump!<br> <strong>Cook</strong> in the kitchen, pedal a car,<br> sail our <strong>ship</strong>!<br> daily <strong>art activities</strong><br> plus <strong>much, much more!</strong></p></div>",
		"position" : "10%"
	}, {
		"image" : "/images/jqslideshow/toys.jpg",
		"text" : "<div class='box-2'><h1>E<sup>2</sup> is a place to<br> <strong>Discover new toys!</strong></h1><p>eco-friendly, lead-free<br> &amp; <strong>Powered by</strong><br> creativity, curiosity,<br> &amp; imagination!</p></div>",
		"position" : "50%"
	}, {
		"image" : "/images/jqslideshow/testdrives.jpg",
		"text" : "<div class='box-1'><h1>Toy <strong>Test-Drives!</strong></h1><p><strong>Try our toys</strong> in our playground!<br>Fully visible, age appropriate <strong>play areas</strong><br> allow siblings to each play<br>in <strong>their own way</strong>.<br>Want to <strong>try something new?</strong><br>If you don&#8217;t see it - ask!</p></div>",
		"position" : "10%"
	}, {
		"image" : "/images/jqslideshow/celebrate.jpg",
		"text" : "<div class='box-2'><h1>E<sup>2</sup> is a place to <strong>Celebrate!</strong></h1><p>We offer <strong>private<br><a href='birthdayparties.php'>Birthday Parties &amp; Fund Raisers!</a></strong><br><br><strong>Relax!</strong><br>	We do the work,<br>	you have the <strong>fun!</strong></p></div>",
		"position" : "50%"
	}
];



$(document).ready(function() {
		textTimer = true;
	// Backwards navigation
	$("#back").click(function() {
		stopAnimation();
		navigate("back");
	});
	
	// Forward navigation
	$("#next").click(function() {
		stopAnimation();
		navigate("next");
	});
	$("#goto1").click(function() {
		stopAnimation();
		navigate(1);
	});
	$("#goto2").click(function() {
		stopAnimation();
		navigate(2);
	});
	$("#goto3").click(function() {
		stopAnimation();
		navigate(3);
	});
	$("#goto4").click(function() {
		stopAnimation();
		navigate(4);
	});
	$("#goto5").click(function() {
		stopAnimation();
		navigate(5);
	});
	
	var interval;
	$("#playpause").toggle(function(){
		stopAnimation();
	}, function() {
		// Change the background image to "pause"
		$(this).css({ "background-image" : "url(/images/pausebutton.jpg)" });
		
		// Show the next image
		navigate("next");
		
		// Start playing the animation
		interval = setInterval(function() {
			navigate("next");
		}, slideshowSpeed);
		textTimer = true;
	});
	
	
	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	var navigate = function(direction) {
		// Check if no animation is running. If it is, prevent the action
		if(animating) {
			return;
		}
		
		// Check which current image we need to show
		if(direction == "next") {
			currentImg++;
			if(currentImg == photos.length + 1) {
				currentImg = 1;
			}
		} else if (direction == "back") {
			currentImg--;
			if(currentImg == 0) {
				currentImg = photos.length;
			}
		} else {
			currentImg = direction;
		}
		
		// Check which container we need to use
		var currentContainer = activeContainer;
		if(activeContainer == 1) {
			activeContainer = 2;
		} else {
			activeContainer = 1;
		}
		
		showImage(photos[currentImg - 1], currentContainer, activeContainer);
		for (i=1; i<=photos.length; i++){
			$("#goto" + i).css("background", "rgb(40, 206, 255)").css("color", "black");
		}
		$("#goto" + currentImg).css("background", "rgb(6, 172, 221)").css("color", "white");
	};
	
	var currentZindex = 1000;
	var showImage = function(photoObject, currentContainer, activeContainer) {
		animating = true;
		
		// Make sure the new container is always on the background
		currentZindex--;
		
		// Set the background image of the new active container
		$("#headerimg" + activeContainer).css({
			"background-image" : "url(" + photoObject.image + ")",
			"display" : "block",
			"z-index" : currentZindex
		});
		
		// Hide the header text
		$("#headertxt").css({"display" : "none"});
		
		// Set the new header text
		$("#headertxt").html(photoObject.text);		
		$("#headertxt").css("left", photoObject.position);
		
		// Fade out the current container
		// and display the header text when animation is complete
		$("#headerimg" + currentContainer).fadeOut(function() {
			setTimeout(function() {
				$("#headertxt").fadeIn(500)
				setTimeout(function() {
					if (textTimer) {
					$("#headertxt").fadeOut(500);
					}
				}, slideshowSpeed-1800);
				animating = false;
			}, 500);
		});
	};
	
	var stopAnimation = function() {
		// Change the background image to "play"
		$("#playpause").css({ "background-image" : "url(/images/playbutton.jpg)" });
		textTimer = false;
		// Clear the interval
		clearInterval(interval);
	};
	
	// We should statically set the first image
	navigate("next");
	
	// Start playing the animation
	interval = setInterval(function() {
		navigate("next");
	}, slideshowSpeed);
	
});
