$(window).load(function () {
	$(window).blur(function () {
		jQuery.fx.off = true;
	});

	$(window).focus(function () {
		jQuery.fx.off = false;
	});
	
	
	$("#ov0").delay(4500).fadeOut(500).parent().parent().children("#overlay").children("#ov1").delay(5000).fadeIn(500).delay(1).animate({
		opacity: 0.9,
		top: '-=20'
	}, 1500).fadeOut(500);

	
	//This keeps track of the slideshow's current location
	var current_panel = 1;
	//Controlling the duration of animation by variable will simplify changes
	var animation_duration = 750;

	$.timer(7500, function (timer) {
		//Determine the current location, and transition to next panel
		switch (current_panel) {
		case 1:	
			//Family	
			$("#ov6").css('left', '0px').css('top', '0px');


			$("#slideshow").stop().fadeIn(1).animate({
				left: "-450px",
				top: "0px"
			}, {
				duration: animation_duration
			});
			$('#overlay').find('#ov2').delay(250).fadeIn(1000).delay(250).animate({
				opacity: 0.9,
				left: '+=38'
			}, 4000).fadeOut(500);
			current_panel = 2;

			break;

		case 2:
			//House
			$("#ov2").css('left', '0px').css('top', '0px');

			$("#slideshow").stop().fadeIn(1).animate({
				left: "0px",
				top: "-400px"
			}, {
				duration: animation_duration
			});
			$('#overlay').find('#ov3').delay(250).fadeIn(1000).delay(250).animate({
				opacity: 0.9,
				left: '-=38'
			}, 4000).fadeOut(500);

			current_panel = 3;

			break;

		case 3:
			//Auto
			$("#ov3").css('left', '0px').css('top', '0px');

			$("#slideshow").stop().fadeIn(1).animate({
				left: "-450px",
				top: "-400px"
			}, {
				duration: animation_duration
			});
			$('#overlay').find('#ov4').delay(250).fadeIn(1000).delay(250).animate({
				opacity: 0.9,
				top: '+=20'
			}, 4000).fadeOut(500);

			current_panel = 4;

			break;

		case 4:
			//Farm
			$("#ov4").css('left', '0px').css('top', '0px');

			$("#slideshow").stop().fadeIn(1).animate({
				left: "0px",
				top: "-800px"
			}, {
				duration: animation_duration
			});
			$('#overlay').find('#ov5').delay(250).fadeIn(1000).delay(250).animate({
				opacity: 0.9,
				top: '+=20'
			}, 4000).fadeOut(500);

			current_panel = 5;

			break;

		case 5:
			//Farm (repeat)
			$("#ov1").css('left', '0px').css('top', '0px');

			$("#slideshow").stop().fadeIn(1).animate({
				left: "-450px",
				top: "-800px"
			}, {
				duration: animation_duration
			});
			$('#overlay').find('#ov6').delay(250).fadeIn(1000).delay(250).animate({
				opacity: 0.9,
				left: '+=20'
			}, 4000).fadeOut(500);

			current_panel = 6;

			break;

		case 6:
			//Commercial
			$("#ov5").css('left', '0px').css('top', '0px');

			$("#slideshow").stop().fadeIn(1).animate({
				left: "0px",
				top: "0px"
			}, {
				duration: animation_duration
			});
			$('#overlay').find('#ov1').delay(250).fadeIn(1000).delay(250).animate({
				opacity: 0.9,
				top: '-=20'
			}, 4000).fadeOut(500);

			current_panel = 1;

			break;

			timer.reset(15500);
		}
	});
});
