var sourcingTime = 2000;

$(document).ready(function($) {
	initRollovers();
	initTriggers();
	initSourcingPot();
});

function initRollovers() {
	$(".rollover").hover(
		function() {
			this.src = this.src.replace("_off","_on");
		},
		function() {
			this.src = this.src.replace("_on","_off");
		}
	);
}
function initTriggers() {
	$("[target]").hover(
		function() {
			target = $(this).attr("target");
			$(target).show();
		},
		function() {
			target = $(this).attr("target");
			$(target).hide();
		}
	);
}
function initPressRollover() {
	$(".thumbnailBox").hover(
		function() {
			$(".titleBox", this).fadeIn();
		},
		function() {
			$(".titleBox", this).fadeOut();
		}
	);
}
function initToasting() {
	$(".toasterBody").click(
		function() {
			target = $(this).parents(".toaster");
			checkToasters(target);
		}
	);
}
function initSourcingPot() {
	$("#rightColumn").hover(
		function() {
			offSRC = $("#rightColumn #sourcingPot").attr("src");
			offSRC = offSRC.replace("_off","_on");
			$("#rightColumn #sourcingPot").attr("src", offSRC);
			rootSourcing();
		},
		function() {
			onSRC = $("#rightColumn #sourcingPot").attr("src");
			onSRC = onSRC.replace("_on","_off");
			$("#rightColumn #sourcingPot").attr("src", onSRC);
			plantSourcing()
		}
	);
}
function checkToasters(target) {
	readyToaster = $("[position=up]").attr('position', 'up');
	target = $(target);
	toastReady(target);
	if(!(readyToaster === target)) {
		startToasting(readyToaster);
		readyToaster.removeAttr('position');
	}
}
function showFremont() {
	toastReady($("#capHill"));
	$("#capHillAddressTarget").show();
}
function startToasting(targetToaster) {
	$(".toast", targetToaster).animate({
		bottom: '21px'
	}, 150);
	$(".levers", targetToaster).animate({
		bottom: '15px'
	}, 100);
}
function toastReady(targetToaster) {
	$(".toast", targetToaster).animate({
		bottom: '86px'
	}, 150);
	$(".levers", targetToaster).animate({
		bottom: '45px'
	}, 100);
	$(targetToaster).attr('position', 'up');
}
function rootSourcing() {
	$("#rightColumn #gMaskTop img").animate({
		top: '21px'
	}, sourcingTime);
	$("#rightColumn #gMaskBottom img").animate({
		top: '-225px'
	}, sourcingTime);
}
function plantSourcing() {
	$("#rightColumn #gMaskTop img").animate({
		top: '88px'
	}, sourcingTime);
	$("#rightColumn #gMaskBottom img").animate({
		top: '-176px'
	}, sourcingTime);
}
