
// requires x-library.js

//----------------------

// basic properties
var expandFrames = 10,		// #frames to open/close
	timerMS = 30,
	curP = 0,				// currently open popup (or 0 for none)
	switchingTo = 0,
	gBUSY = false;
var popups = new Array(8),	// info about each popup (see constructor below)
	imgNms = new Array(8),
	iObj = new Array(8);

// from robert penner's actionscript code
function easeOutCubic(t, b, c, d) {	return c*((t=t/d-1)*t*t + 1) + b; }

function expand( popupIndex, obj, curFrame, startPos, travelDistance, steps)
{
	// set the new height using the easing equation above
	xHeight( obj, easeOutCubic( curFrame, startPos, travelDistance, steps));
	if ( ++curFrame < steps) {
		// renew the timer
		var fnc = 'expand(' + popupIndex + ',\'' + obj + '\',' + curFrame + ',' + startPos + ',' + travelDistance + ',' + steps + ');';
		popups[popupIndex].activeTimer = setTimeout(fnc,timerMS);
		if ( curFrame == 3) showOverImg(popupIndex);	// some folks need a quick refresh
	}
	else {
		// cancel the timer; we're done
		var slid = popups[popupIndex];
		slid.activeTimer = "none";
		gBUSY = false;
		switchingTo = 0;
		curP = popupIndex;
	}
}
function contract( popupIndex, obj, curFrame, startPos, travelDistance, steps)
{
	xHeight( obj, easeOutCubic( curFrame, startPos, travelDistance, steps));
	if ( ++curFrame < steps) {
		var fnc = 'contract(' + popupIndex + ',\'' + obj + '\',' + curFrame + ',' + startPos + ',' + travelDistance + ',' + steps + ');';
		popups[popupIndex].activeTimer = setTimeout(fnc,timerMS);
		if ( curFrame == 3) showNormalImg(popupIndex);	// some folks need a quick refresh
	}
	else {
		var pop = popups[popupIndex];
		pop.activeTimer = "none";
		gBUSY = false;
		xHide( obj);
		
		// open another one
		if ( pop.daisyChain > 0) {
			var pNum = pop.daisyChain;
			pop.daisyChain = 0;
			popups[pNum].OpenNow( pNum, 'p'+pNum, popups[pNum].ht);
		}
	}
}

// class constructor
function Popup(ht) { this.activeTimer = "none"; this.ht = ht; this.daisyChain = 0; }
Popup.prototype.okToMove = function()
{
	if ( gBUSY) return false;
	gBUSY = true;
	
	// first stop any current motion
	if ( this.activeTimer != "none") {
		clearTimeout( this.activeTimer);
		this.activeTimer = "none";
	}
	return true;
}

Popup.prototype.OpenNow = function( arrayIndex, layerName, newHt )
{
	if ( this.okToMove()) {
		xShow(layerName);
		xHeight(layerName,1);
		expand( arrayIndex, layerName, 0, 1, newHt-1, expandFrames);
	}
}
Popup.prototype.CloseNow = function( arrayIndex, layerName, newHt )
{
	if ( this.okToMove()) {
		var openHt = popups[arrayIndex].ht;
		contract( arrayIndex, layerName, 0, openHt, -(openHt-newHt), expandFrames);
	}
}

// create the popups
popups[1] = new Popup(209);
popups[2] = new Popup(253);
popups[3] = new Popup(254);
popups[4] = new Popup(284);
popups[5] = new Popup(325);
popups[6] = new Popup(368);

function initImages(nm1,nm2,nm3,nm4,nm5,nm6)
{
	// cache the image references
	iObj[1] = document.i1;
	iObj[2] = document.i2;
	iObj[3] = document.i3;
	iObj[4] = document.i4;
	iObj[5] = document.i5;
	iObj[6] = document.i6;
	imgNms[1] = 'images/names/'+nm1;
	imgNms[2] = 'images/names/'+nm2;
	imgNms[3] = 'images/names/'+nm3;
	imgNms[4] = 'images/names/'+nm4;
	imgNms[5] = 'images/names/'+nm5;
	imgNms[6] = 'images/names/'+nm6;
}
function dbg(x) { /* document.getElementById('voiTitle').innerHTML=x; */ }
function showOverImg(pNum) { iObj[pNum].src = imgNms[pNum]+'-on.gif'; /* dbg(pNum+' -- '+imgNms[pNum]+'-on'); */ }
function showNormalImg(pNum) { iObj[pNum].src = imgNms[pNum]+'.gif';  /* dbg(pNum+' -- '+imgNms[pNum]+'-off'); */} 

// user wants a popup opened
function openPopup(pNum)
{
	var newPos, i;

	// user clicked on the open popup...just close it up
	if ( curP == pNum) {
		closePopup();
	}
	else {
		showOverImg(pNum);
		switchingTo = pNum;
		if ( curP != 0) {
			popups[curP].daisyChain = pNum;
			showNormalImg(curP);
			popups[curP].CloseNow( curP, 'p'+curP, 0);
		}
		else
			popups[pNum].OpenNow( pNum, 'p'+pNum, popups[pNum].ht);
	}
}
function closePopup() {
	if ( curP != 0) {
		showNormalImg(curP);
		popups[curP].CloseNow( curP, 'p'+curP, 0);
		curP = 0;
	}
}

// mouse ops
function mOver(pNum) {
	if ( curP != pNum)
		showOverImg(pNum);
}
function mOut(pNum) {
	if ( curP != pNum && pNum != switchingTo)
		showNormalImg(pNum);
}
