// JavaScript Document
function TopZ(topNode, z)
{
	nodeCurrentZ = topNode.style.zIndex;
	dojo.query(".bigbox").forEach(function (node, i){
		if (node.style.zIndex > nodeCurrentZ && node.style.zIndex <= z) {
			if (node.style.zIndex == 7) {
				MouseOverEvent[node.id] = dojo.connect(node, "mouseover", function() { MoveToTop(node); });
				dojo.attr(node, "onTop", false);
			}
			node.style.zIndex = node.style.zIndex - 1;
		}
	});
	topNode.style.zIndex = z;
}
function MoveToTop(node) 
{
	
	if (dojo.attr(node, "onTop") == false) {
		dojo.attr(node, "onTop", true);
		dojo.disconnect(MouseOverEvent[node.id]);
		// 
		function SingleSlideUp(node, topStart, leftStart, topOut, leftOut, toZ, bounceIt)
		{
			var slideOut = dojo.fx.slideTo({
				node:node,
				duration:100,
				left:leftOut,
				top:topOut});
			dojo.connect(slideOut, "onEnd", function() {TopZ(node, toZ); });
			var bounceIn = dojo.fx.slideTo({
				node:node,
				duration:600,
				easing: bounceIt,
				left: leftStart,
				top: topStart});
			dojo.fx.chain([
				slideOut,
				bounceIn
			]).play();
		}
		function DoubleSlideUp(node, topStart, leftStart, topMiddle, leftMiddle, topOut, leftOut, toZ, bounceIt)
		{
			var slideOut = dojo.fx.slideTo({
				node:node,
				duration:100,
				left:leftMiddle,
				top:topMiddle});
			dojo.connect(slideOut, "onEnd", function() {TopZ(node, toZ); });
			var slideAcross = dojo.fx.slideTo({
				node:node,
				duration:100,
				left:leftOut,
				top:topOut});
			dojo.connect(slideAcross, "onEnd", function() {TopZ(node, 7); });
			var bounceIn = dojo.fx.slideTo({
				node:node,
				duration:600,
				easing: dojo.fx.easing.bounceOut,
				left: leftStart,
				top: topStart});
			dojo.fx.chain([
				slideOut,
				slideAcross,
				bounceIn
			]).play();
		}
		switch (node.id) {
			case "banner":
				leftNodeZ = dojo.byId("groundhogcentral").style.zIndex;
				rightNodeZ = dojo.byId("birthdayclub").style.zIndex;
				currentNodeZ = node.style.zIndex;
				if (currentNodeZ < leftNodeZ && currentNodeZ < rightNodeZ) {
					if (leftNodeZ > rightNodeZ) {
						DoubleSlideUp(node, 8, 140, 4, 115, 4, 160, rightNodeZ, dojo.fx.easing.bounceOut);
					} else {
						DoubleSlideUp(node, 8, 140, 4, 160, 4, 115, leftNodeZ, dojo.fx.easing.bounceOut);
					}
				} else if (currentNodeZ > leftNodeZ && currentNodeZ < rightNodeZ) {
					SingleSlideUp(node, 8, 140, 4, 115, 7, dojo.fx.easing.bounceOut);
				} else if (currentNodeZ > rightNodeZ && currentNodeZ < leftNodeZ) {
					SingleSlideUp(node, 8, 140, 4, 160, 7, dojo.fx.easing.bounceOut);
				}
				break;
			case "links":
				leftNodeZ = dojo.byId("mall").style.zIndex;
				rightNodeZ = dojo.byId("campwoodchuck").style.zIndex;
				currentNodeZ = node.style.zIndex;
				if (currentNodeZ < leftNodeZ && currentNodeZ < rightNodeZ) {
					if (leftNodeZ > rightNodeZ) {
						DoubleSlideUp(node, 450, 140, 460, 90, 460, 184, rightNodeZ, dojo.fx.easing.bounceOut);
					} else {
						DoubleSlideUp(node, 450, 140, 460, 184, 460, 90, leftNodeZ, dojo.fx.easing.bounceOut);
					}
				} else if (currentNodeZ > leftNodeZ && currentNodeZ < rightNodeZ) {
					SingleSlideUp(node, 450, 140, 460, 90, 7, dojo.fx.easing.bounceOut);
				} else if (currentNodeZ > rightNodeZ && currentNodeZ < leftNodeZ) {
					SingleSlideUp(node, 450, 140, 460, 184, 7, dojo.fx.easing.bounceOut);
				}
				break;
			case "groundhogcentral":
				// do the shimmy for Groundhog Central Big Box
				SingleSlideUp(node, 144, -164, 120, -184, 7, dojo.fx.easing.bounceOut);
				break;
			case "birthdayclub":
				SingleSlideUp(node, 126, 440, 100, 460, 7, dojo.fx.easing.bounceOut);
				break;
			case "mall":
				SingleSlideUp(node, 320, -140, 340, -185, 7, dojo.fx.easing.bounceOut);
				break;
			case "campwoodchuck":
				SingleSlideUp(node, 302, 416, 322, 466, 7, dojo.fx.easing.bounceOut);
				break;
			

		}
		// restore the mouseover event to the old top node.
	}
}
