//-- Created by Matias Santini (C) 2003 //
//-- Animation Script Starts Here //
//-- This section declares the arrays that will hold and pre-load the images //
var mostAnim = new Array();
var AnimA = new Array();
var AnimB = new Array();
var AnimC = new Array();
var AnimD = new Array();
var AnimE = new Array();
var AnimF = new Array();
//-- These Variable are place markers to tell the script where in the animation //
//-- Sequence we currently are //
var heldplaceA = 1;
var heldplaceB = 1;
var heldplaceC = 1;
var heldplaceD = 1;
var heldplaceE = 1;
var heldplaceF = 1;
//-- This initializes the interval variables, these are a script thing that controls the speed
//-- of the animation among other things //
var intervalIDA = 0;
var intervalIDB = 0;
var intervalIDC = 0;
var intervalIDD = 0;
var intervalIDE = 0;
var intervalIDF = 0;

//-- This section pre-loads the gifs into the arrays we prepared earlier. //
//-- First, the common frames are loaded //
for (var i = 1; i<7; i++){
mostAnim[i] = new Image(120, 120);
mostAnim[i].src = "images/buttons/BookShared" + i + ".gif";
}

//-- now the button-specific frames are loaded. //
for (var j = 7; j < 17; j++) {
AnimA[j] = new Image(120, 120);
AnimB[j] = new Image(120, 120);
AnimC[j] = new Image(120, 120);
AnimD[j] = new Image(120, 120);
AnimE[j] = new Image(120, 120);
AnimF[j] = new Image(120, 120);
AnimA[j].src = "images/buttons/BookHome" + j + ".gif"
AnimB[j].src = "images/buttons/BookNewR" + j + ".gif"
AnimC[j].src = "images/buttons/BookReviews" + j + ".gif"
AnimD[j].src = "images/buttons/BookEvents" + j + ".gif"
AnimE[j].src = "images/buttons/BookOrder" + j + ".gif"
AnimF[j].src = "images/buttons/BookContact" + j + ".gif"
}

//-- this is the function that deals with animating the buttons forward (or opening) //
function animateForward(Iam) {
//-- since later on we subtract from our placeholder, it is possible for it to get bellow //
//-- an acceptable value, so we guard for that here. //
if (heldplaceA < 1) heldplaceA = 1;
if (heldplaceB < 1) heldplaceB = 1;
if (heldplaceC < 1) heldplaceC = 1;
if (heldplaceD < 1) heldplaceD = 1;
if (heldplaceE < 1) heldplaceE = 1;
if (heldplaceF < 1) heldplaceF = 1;

//-- The following Ifs first check if its their button being dealt with and then //
//-- Check to see where the placeholder is, it then accordingly references the //
//-- Correct file in the correct array and replaces the image on the page with it. //
//-- It then advances the placeholder //

if (Iam == 'A') {

	if (heldplaceA < 7) {
		document.images.bookanimA.src = mostAnim[heldplaceA].src;
		heldplaceA++;
	}
	
	if (heldplaceA > 6) {
		if (heldplaceA < 16) {
			document.images.bookanimA.src = AnimA[heldplaceA].src;
			heldplaceA++;
		}
	}
}

if (Iam == 'B') {

	if (heldplaceB < 7) {
		document.images.bookanimB.src = mostAnim[heldplaceB].src;
		heldplaceB++;
	}
	
	if (heldplaceB > 6) {
		if (heldplaceB < 16) {
			document.images.bookanimB.src = AnimB[heldplaceB].src;
			heldplaceB++;
		}
	}
}

if (Iam == 'C') {

	if (heldplaceC < 7) {
		document.images.bookanimC.src = mostAnim[heldplaceC].src;
		heldplaceC++;
	}
	
	if (heldplaceC > 6) {
		if (heldplaceC < 16) {
			document.images.bookanimC.src = AnimC[heldplaceC].src;
			heldplaceC++;
		}
	}
}

if (Iam == 'D') {

	if (heldplaceD < 7) {
		document.images.bookanimD.src = mostAnim[heldplaceD].src;
		heldplaceD++;
	}
	
	if (heldplaceD > 6) {
		if (heldplaceD < 16) {
			document.images.bookanimD.src = AnimD[heldplaceD].src;
			heldplaceD++;
		}
	}
}

if (Iam == 'E') {

	if (heldplaceE < 7) {
		document.images.bookanimE.src = mostAnim[heldplaceE].src;
		heldplaceE++;
	}
	
	if (heldplaceE > 6) {
		if (heldplaceE < 16) {
			document.images.bookanimE.src = AnimE[heldplaceE].src;
			heldplaceE++;
		}
	}
}
if (Iam == 'F') {

	if (heldplaceF < 7) {
		document.images.bookanimF.src = mostAnim[heldplaceF].src;
		heldplaceF++;
	}
	
	if (heldplaceF > 6) {
		if (heldplaceF < 16) {
			document.images.bookanimF.src = AnimF[heldplaceF].src;
			heldplaceF++;
		}
	}
}

}

//-- This function animates the buttons backwards (Closing) //
function animateBackward(Iamtoo) {
//-- Similar to the other function, we check if the value has been incremented out of bounds //
if (heldplaceA > 15) heldplaceA = 15;
if (heldplaceB > 15) heldplaceB = 15;
if (heldplaceC > 15) heldplaceC = 15;
if (heldplaceD > 15) heldplaceD = 15;
if (heldplaceE > 15) heldplaceE = 15;
if (heldplaceF > 15) heldplaceF = 15;

//--Now we check which button has the floor and we do basically the same thing as the forward function but in reverse //
if (Iamtoo == 'A') {
	if (heldplaceA > 0) {
		if (heldplaceA < 7) {
		document.images.bookanimA.src = mostAnim[heldplaceA].src;
		heldplaceA--;
		}
		if (heldplaceA > 6) {
		document.images.bookanimA.src = AnimA[heldplaceA].src;
		heldplaceA--;
		}
	}
}
if (Iamtoo == 'B') {
	if (heldplaceB > 0) {
		if (heldplaceB < 7) {
		document.images.bookanimB.src = mostAnim[heldplaceB].src;
		heldplaceB--;
		}
		if (heldplaceB > 6) {
		document.images.bookanimB.src = AnimB[heldplaceB].src;
		heldplaceB--;
		}
	}
}

if (Iamtoo == 'C') {
	if (heldplaceC > 0) {
		if (heldplaceC < 7) {
		document.images.bookanimC.src = mostAnim[heldplaceC].src;
		heldplaceC--;
		}
		if (heldplaceC > 6) {
		document.images.bookanimC.src = AnimC[heldplaceC].src;
		heldplaceC--;
		}
	}
}

if (Iamtoo == 'D') {
	if (heldplaceD > 0) {
		if (heldplaceD < 7) {
		document.images.bookanimD.src = mostAnim[heldplaceD].src;
		heldplaceD--;
		}
		if (heldplaceD > 6) {
		document.images.bookanimD.src = AnimD[heldplaceD].src;
		heldplaceD--;
		}
	}
}

if (Iamtoo == 'E') {
	if (heldplaceE > 0) {
		if (heldplaceE < 7) {
		document.images.bookanimE.src = mostAnim[heldplaceE].src;
		heldplaceE--;
		}
		if (heldplaceE > 6) {
		document.images.bookanimE.src = AnimE[heldplaceE].src;
		heldplaceE--;
		}
	}
}

if (Iamtoo == 'F') {
	if (heldplaceF > 0) {
		if (heldplaceF < 7) {
		document.images.bookanimF.src = mostAnim[heldplaceF].src;
		heldplaceF--;
		}
		if (heldplaceF > 6) {
		document.images.bookanimF.src = AnimF[heldplaceF].src;
		heldplaceF--;
		}
	}
}
}

//-- This function is crucial as a gateway function. it fields the mouseover and passes that value to the image //
//-- Replacing function, it also does this with a delay so that the animation progresses at humanly viible speeds //
//-- it also clears the interval variable (what controlls the delay) so if someone mouses out and then back over //
//-- you don't get the opening and closing functions fighting each other //
function bookanimplayforward(whoryou) {

if (whoryou == 'A') { 
	if (intervalIDA) clearInterval(intervalIDA);
	intervalIDA = setInterval("animateForward('A')", 66);
	}
if (whoryou == 'B') {
	if (intervalIDB) clearInterval(intervalIDB);
	intervalIDB = setInterval("animateForward('B')", 66);
	}
if (whoryou == 'C') {
	if (intervalIDC) clearInterval(intervalIDC);
	intervalIDC = setInterval("animateForward('C')", 66);
	}
if (whoryou == 'D') {
	if (intervalIDD) clearInterval(intervalIDD);
	intervalIDD = setInterval("animateForward('D')", 66);
	}
if (whoryou == 'E') {
	if (intervalIDE) clearInterval(intervalIDE);
	intervalIDE = setInterval("animateForward('E')", 66);
   }
   if (whoryou == 'F') {
	if (intervalIDF) clearInterval(intervalIDF);
	intervalIDF = setInterval("animateForward('F')", 66);
   }
}
function bookanimplaybackward(whoryout) {
if (whoryout == 'A') { 
	clearInterval(intervalIDA);
	intervalIDA = setInterval("animateBackward('A')", 33);
	}
if (whoryout == 'B') {
	clearInterval(intervalIDB);
	intervalIDB = setInterval("animateBackward('B')", 33);
	}
if (whoryout == 'C') {
	clearInterval(intervalIDC);
	intervalIDC = setInterval("animateBackward('C')", 33);
	}
if (whoryout == 'D') {
	clearInterval(intervalIDD);
	intervalIDD = setInterval("animateBackward('D')", 33);
	}
if (whoryout == 'E') {
	clearInterval(intervalIDE);
	intervalIDE = setInterval("animateBackward('E')", 33);
	}
if (whoryout == 'F') {
	clearInterval(intervalIDF);
	intervalIDF = setInterval("animateBackward('F')", 33);
	}
}

//-- That about covers it. If i can figure out how to get javascript to increment alphabetically i could reduce the size //
//-- of this thing by like 30% //