// JavaScript Document

function rotateImagesTopLeft() {
	var currentPhoto = $("#topLeft div.current");
	var nextPhoto = currentPhoto.next();
	if (nextPhoto.length == 0) {
		nextPhoto = $("#topLeft div:first")
	}
	
	currentPhoto.removeClass("current").addClass("previous");
	nextPhoto.css({ opacity: 0.0 }).addClass("current").animate({ opacity: 1.0 }, 1000,
		function() {
			currentPhoto.removeClass("previous");
		});
}

function rotateImagesTopRight() {
	var currentPhoto = $("#topRight div.current");
	var nextPhoto = currentPhoto.next();
	if (nextPhoto.length == 0) {
		nextPhoto = $("#topRight div:first")
	}
	
	currentPhoto.removeClass("current").addClass("previous");
	nextPhoto.css({ opacity: 0.0 }).addClass("current").animate({ opacity: 1.0 }, 1000,
		function() {
			currentPhoto.removeClass("previous");
		});
}

function rotateImagesBottomLeft() {
	var currentPhoto = $("#bottomLeft div.current");
	var nextPhoto = currentPhoto.next();
	if (nextPhoto.length == 0) {
		nextPhoto = $("#bottomLeft div:first")
	}
	
	currentPhoto.removeClass("current").addClass("previous");
	nextPhoto.css({ opacity: 0.0 }).addClass("current").animate({ opacity: 1.0 }, 1000,
		function() {
			currentPhoto.removeClass("previous");
		});
}

function rotateImagesBottomRight() {
	var currentPhoto = $("#bottomRight div.current");
	var nextPhoto = currentPhoto.next();
	if (nextPhoto.length == 0) {
		nextPhoto = $("#bottomRight div:first")
	}
	
	currentPhoto.removeClass("current").addClass("previous");
	nextPhoto.css({ opacity: 0.0 }).addClass("current").animate({ opacity: 1.0 }, 1000,
		function() {
			currentPhoto.removeClass("previous");
		});
}

$(function() {
	var topLeft = setInterval("rotateImagesTopLeft()", 4000);
	$("#topLeft").hover(function() {
			clearInterval(topLeft);
			}, function() {
			topLeft = setInterval("rotateImagesTopLeft()", 4000);
	});

	var topRight = setInterval("rotateImagesTopRight()", 7000);
		$("#topRight").hover(function() {
			clearInterval(topRight);
			}, function() {
			topRight = setInterval("rotateImagesTopRight()", 7000);
		});
	
	var bottomLeft = setInterval("rotateImagesBottomLeft()", 6000);
		$("#bottomLeft").hover(function() {
			clearInterval(bottomLeft);
			}, function() {
			bottomLeft = setInterval("rotateImagesBottomLeft()", 6000);
		});
	
	var bottomRight = setInterval("rotateImagesBottomRight()", 5000);
		$("#bottomRight").hover(function() {
			clearInterval(bottomRight);
			}, function() {
			bottomRight = setInterval("rotateImagesBottomRight()", 5000);
		});
	
	
});

