var onImage = 0;
var maxImage = 0;
var onMotion = false;

$(document).ready(function() {
// Global
	$("#menuBar li").livequery(function() {
		$(this).hover(function() {
			$(this).children("div").fadeTo("fast", 1.00);
		},
		function() {
			if (!$(this).hasClass("active")) {
				$(this).children("div").fadeTo("fast", 0.45);
			}
		});
	});
	$("#philosophy li").livequery(function() {
		$(this).click(function() {
			if (onMotion==false) {
				onMotion = true;
				var toLoad = $(this).children("a").attr("href");
				$('#philosophy li').removeClass('activeSub');
				$(this).addClass('activeSub');
				$('#philosophy-Text p.activeSub').removeClass('activeSub').fadeOut('fast', function () {
					$(toLoad).fadeIn('fast', function () {
						$(toLoad).addClass('activeSub');
						onMotion = false;
					});
				});
			}
			return false;							   
		});
	});
	
	$("div#theShow img").fadeOut(0);
	$(window).ready(function() {

		var arr = $("div#theShow").children().size();
		var conWidth = $("div#theShow").width();
		var imgWidth = 0;
		for(i=0;i<(arr);i++) {
			imgWidth = $("div#theShow").children("img").eq(i).width();
			$("div#theShow").children("img").eq(i).css("left", Math.floor(conWidth / 2) - Math.floor(imgWidth / 2));
		}
		startSlideShow();
	});
});

function startSlideShow() {
	if ($("div#theShow").children().size()) {
		$("div#theShow").livequery(function() {
			maxImage = $("div#theShow").children().size();
			if (onImage == maxImage) {
				onImage = 0;	
			}
			if (onImage==0) {
				$(this).children("img").eq(maxImage - 1).fadeOut(1200).parent().children("img").eq(onImage).fadeIn(1200, function() {
					onImage = onImage + 1;
					setTimeout ( startSlideShow, 2000 );
				});
			}
			else {
				$(this).children("img").eq(onImage - 1).fadeOut(1200).parent().children("img").eq(onImage).fadeIn(1200, function() {
					onImage = onImage + 1;
					setTimeout ( startSlideShow, 2000 );
				});
			}
		});
	}
}