// HELPER FUNCTIONS
// IE 5+, Netscape 4+ (PC & MAC)

	function getObj(n, d) { //v4.0
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=getObj(n,d.layers[i].document);
		if(!x && document.getElementById) x=document.getElementById(n); return x;
	}



// GLOBAL DECLARATIONS
	var DLwaitVar = new Array(100);
	var DLisSliding;
	var DLcycler = 0;
	function DLslidingIndicator() {
		isSliding = false;
	}



// DHTML FUNCTIONS -----------------------------------------------------------------------
	/*
		All functions by Adam J. Moore (adam@adamjmoore.com)
		
		IE 5+, Netscape 4+ (PC & MAC)
			DLslideDivBy
			DLslideDivByTo
			setDLwaitVarAfterSequence
			setDLwaitVarAfterSequenceDelay
			swapImage
			showDiv
			hideDiv
			showDivDelay
			hideDivDelay			
			callFunction
		
		IE 5+, Netscape 6+ (PC & MAC)
			morphTextColor
			morphTextColorRev
			isDivVisible
			displayDivOn
			displayDivOff					
	*/


function DLslideDivTo(divId, xDest, yDest, speed, smoothness, serialize, DLwaitVarIndex, DLsetVarIndex, boolSlideIndicator) { 
	//Determine the xAmt & yAmt >> Call DLslideDivBy
	xAmt = xDest - DLgetObjScreenLeft(divId);
	yAmt = yDest - DLgetObjScreenTop(divId);
	DLslideDivBy(divId, xAmt, yAmt, speed, smoothness, serialize, DLwaitVarIndex, DLsetVarIndex, boolSlideIndicator);
}	

function DLslideDivBy(divId, xAmt, yAmt, speed, smoothness, serialize, DLwaitVarIndex, DLsetVarIndex, boolSlideIndicator) { 

	if ((serialize && DLwaitVar[DLwaitVarIndex] == 'done') || !serialize) {		
	
		//Get the current coordinates of the Div (relative)
		if (document.layers) {
			xCur = getObj(divId).left;
			yCur = getObj(divId).top;			
		} else {
			if (getObj(divId).style.position=='relative') {
				xCur = getObj(divId).style.left;
				yCur = getObj(divId).style.top;							
				if (xCur.indexOf('px') > 0) xCur = xCur.replace('px', '');
				if (yCur.indexOf('px') > 0) yCur = yCur.replace('px', '');
				if (xCur.indexOf('pt') > 0) xCur = xCur.replace('pt', '');
				if (yCur.indexOf('pt') > 0) yCur = yCur.replace('pt', '');
				xCur = parseInt(xCur);
				yCur = parseInt(yCur);
			} else {				
				xCur = getObj(divId).offsetLeft;
				yCur = getObj(divId).offsetTop;
			}					
		}		
		
		//For a linear path, calculate the proper xdelta & ydelta
		if (yAmt == 0) {
			xdelta = 1;
		} else {
			xdelta = Math.abs(xAmt / yAmt);	
		}
		if (xAmt == 0) {
			ydelta = 1;
		} else {
			ydelta = Math.abs(yAmt / xAmt);	
		}
		
		//Translate Smoothness to create a perfect linear movement
		useSmoothness = 103-smoothness;		
		if (Math.abs(xAmt) < Math.abs(yAmt)) {
			useSmoothnessX = Math.round(useSmoothness * xdelta);
		} else {
			useSmoothnessX = useSmoothness;
		}
		if (Math.abs(yAmt) < Math.abs(xAmt)) {
			useSmoothnessY = Math.round(useSmoothness * ydelta);
		} else {
			useSmoothnessY = useSmoothness;
		}
		
		
		//Advance the Cycler
		DLcycler++;
		if (DLcycler == 10000000) DLcycler=1;
		
		//Alternate zero condition to fixup rounding loss on high definition / extremely non-equilateral slides	
		if (useSmoothnessX == 0) {		
			if (DLcycler % 2==1) {
				useSmoothnessX = 0;
			} else {
				useSmoothnessX = 1;
			}
		}
		if (useSmoothnessY == 0) {
			if (DLcycler % 2==1) {
				useSmoothnessY = 0;
			} else {
				useSmoothnessY = 1;
			}
		}
		
				
		//Calculate the horizontal component	
		//Check for overshoot
		xNext = xCur;
		if (xAmt != 0) {
		if (xAmt < 0) {
			//Direction is -
			xFinal = xCur + xAmt;
			xNext = xCur - useSmoothnessX;
			if (xNext < xFinal) { 
				xNext = xFinal;
				xAmt = 0;
			} else {
				xAmt = xAmt + useSmoothnessX;
			}
			
		} else {
			//Direction is +
			xFinal = xCur + xAmt;		
			xNext = xCur + useSmoothnessX;
			if (xNext > xFinal) { 
				xNext = xFinal;
				xAmt = 0;
			} else {
				xAmt = xAmt - useSmoothnessX;
			}
		}
		}
	
		//Calculate the vertical component	
		//Check for overshoot
		yNext = yCur;
		if (yAmt != 0) {
		if (yAmt < 0) {
			//Direction is -
			yFinal = yCur + yAmt;
			yNext = yCur - useSmoothnessY;
			if (yNext < yFinal) { 
				yNext = yFinal;
				yAmt = 0;
			} else {
				yAmt = yAmt + useSmoothnessY;
			}
			
		} else {
			//Direction is +
			yFinal = yCur + yAmt;		
			yNext = yCur + useSmoothnessY;
			if (yNext > yFinal) { 
				yNext = yFinal;
				yAmt = 0;
			} else {
				yAmt = yAmt - useSmoothnessY;
			}
		}
		}
		
	
		//Set horizontal & vertical components	
		if (document.layers) {
			getObj(divId).left = xNext;
			getObj(divId).top = yNext;
		} else {
			getObj(divId).style.left = xNext;
			getObj(divId).style.top = yNext;
		}

	}
	
	//Recursive call	
	if (xAmt!=0 || yAmt!=0)	{
		DLisSliding = true;	
		if (typeof boolSlideIndicator != 'string') boolSlideIndicator = '';
		if (boolSlideIndicator != '') { eval(boolSlideIndicator).isSliding = true; }
		setTimeout('DLslideDivBy(\'' + divId + '\',' + xAmt + ',' + yAmt + ',' + speed + ',' + smoothness + ',' + serialize + ',' + DLwaitVarIndex + ',' + DLsetVarIndex + ',\'' + boolSlideIndicator + '\')', 101-speed+20);		
		
	} else {
		DLisSliding = false;
		if (typeof boolSlideIndicator != 'string') boolSlideIndicator = '';
		if (boolSlideIndicator != '') { eval(boolSlideIndicator).isSliding = false; }
		if (serialize) DLwaitVar[DLsetVarIndex] = 'done';
	}

}


function DLwaitVarInit(start, end) {
	DLwaitVar[start] = 'done';
	for(i=start+1; i<=end; i++) DLwaitVar[i] = '';
}


function setDLwaitVarAfterSequence(DLsetVarIndex, DLwaitVarIndexa, DLwaitVarIndexb) {
	var allDone = true;
	for(i=DLwaitVarIndexa; i<=DLwaitVarIndexb; i++) {
		if (DLwaitVar[i] != 'done') {
			allDone=false;
			break;
		}
	}
	
	if (allDone) {
		DLwaitVar[DLsetVarIndex] = 'done';
	} else {
		setTimeout('setDLwaitVarAfterSequence(' + DLsetVarIndex + ',' + DLwaitVarIndexa + ',' + DLwaitVarIndexb + ')', 50);
	}
}

function setDLwaitVarAfterSequenceDelay(DLsetVarIndex, DLwaitVarIndexa, DLwaitVarIndexb, delay) {
	var allDone = true;
	for(i=DLwaitVarIndexa; i<=DLwaitVarIndexb; i++) {
		if (DLwaitVar[i] != 'done') {
			allDone=false;
			break;
		}
	}
	
	if (allDone) {
		setTimeout('DLwaitVar[' + DLsetVarIndex + '] = \'done\'', delay);
	} else {
		setTimeout('setDLwaitVarAfterSequenceDelay(' + DLsetVarIndex + ',' + DLwaitVarIndexa + ',' + DLwaitVarIndexb + ',' + delay + ')', 50);
	}
}

function swapImage(imgId, uncachedImageFile) {
	getObj(imgId).src = uncachedImageFile;
} 

function displayDivOn(divId, outterDivStr) {
	if (document.layers) {
		if (!outterDivStr) { 
			eval('document.'+divId).display='block';		
		 } else {
		 	eval(outterDivStr + '.' +divId).display='block';		
		}
	 } else {
	 	getObj(divId).style.display = 'block';
	}
}

function displayDivOff(divId, outterDivStr) {
	if (document.layers) {
		if (!outterDivStr) { 
			eval('document.'+divId).display='none';		
		 } else {
		 	eval(outterDivStr + '.' +divId).display='none';		
		}
	 } else {
	 	getObj(divId).style.display = 'none';
	}
}

function isDivDisplayed(divId, outterDivStr) {
	if (document.layers) {
		if (!outterDivStr) { 
			if (eval('document.'+divId).display=='none') { return false; } else { return true; }
		 } else {
		 	if (eval(outterDivStr + '.' +divId).display=='none') { return false; } else { return true; }	
		}
	 } else {
	 	if (getObj(divId).style.display=='none') { return false; } else { return true; }
	}
}

function isDivVisible(divId, outterDivStr) {
	if (document.layers) {
		if (!outterDivStr) { 
			if (eval('document.'+divId).visibility=='hidden') { return false; } else { return true; }
		 } else {
		 	if (eval(outterDivStr + '.' +divId).visibility=='hidden') { return false; } else { return true; }	
		}
	 } else {
	 	if (getObj(divId).style.visibility=='hidden') { return false; } else { return true; }
	}
}

function DLshowDiv (divId, serialize, DLwaitVarIndex, DLsetVarIndex, delay) {
	if (serialize && DLwaitVar[DLwaitVarIndex] != 'done') {
		setTimeout('DLshowDiv(\'' + divId + '\', true, ' + DLsetVarIndex + ',' + DLwaitVarIndex + ',' + delay + ')', 50);
	} else {
		getObj(divId).style.visibility = 'visible';
		if (serialize) setTimeout('DLwaitVar[' + DLsetVarIndex + '] = \'done\'', delay);
	}
}

function DLhideDiv (divId, serialize, DLwaitVarIndex, DLsetVarIndex, delay) {
	if (serialize && DLwaitVar[DLwaitVarIndex] != 'done') {
		setTimeout('DLhideDiv(\'' + divId + '\', true, ' + DLsetVarIndex + ',' + DLwaitVarIndex + ',' + delay + ')', 50);
	} else {
		getObj(divId).style.visibility = 'hidden';
		if (serialize) setTimeout('DLwaitVar[' + DLsetVarIndex + '] = \'done\'', delay);
	}
}

function changeIndex (divId, newIndex, serialize, DLsetVarIndex, DLwaitVarIndex) {
	if (serialize && DLwaitVar[DLwaitVarIndex] != 'done') {
		setTimeout('changeIndex(\'' + divId + '\',' + newIndex + ', true, ' + DLsetVarIndex + ',' + DLwaitVarIndex + ')', 50);
	} else {
		getObj(divId).style.zIndex = newIndex;
		if (serialize) DLwaitVar[DLsetVarIndex] = 'done';
	}
}

function morphTextColor (spanId, colorArray, speed, serialize, DLsetVarIndex, DLwaitVarIndex) {
	if (serialize && DLwaitVar[DLwaitVarIndex] != 'done') {
		setTimeout('morphTextColor(\'' + spanId + '\',' + colorArray.nameOf + ',' + speed + ', true, ' + DLsetVarIndex + ',' + DLwaitVarIndex + ')', 50);
	} else {
		for (mtcI=1; mtcI<=colorArray.length-1; mtcI++) {
			setTimeout('getObj(\'' + spanId + '\').style.color = \'' + colorArray[mtcI] + '\'', mtcI*(100-speed));	
		}
		if (serialize) DLwaitVar[DLsetVarIndex] = 'done';
	}
}

function morphTextColorRev (spanId, colorArray, speed, serialize, DLsetVarIndex, DLwaitVarIndex) {
	if (serialize && DLwaitVar[DLwaitVarIndex] != 'done') {
		setTimeout('morphTextColorRev(\'' + spanId + '\',' + colorArray.nameOf + ',' + speed + ', true, ' + DLsetVarIndex + ',' + DLwaitVarIndex + ')', 50);
	} else {
		for (mtcI=colorArray.length-1; mtcI>=1; mtcI--) {
			setTimeout('getObj(\'' + spanId + '\').style.color = \'' + colorArray[mtcI] + '\'', (colorArray.length-mtcI)*(100-speed));				
		}
		if (serialize) setDLwaitVarAfterSequenceDelay(DLsetVarIndex, DLwaitVarIndex, DLwaitVarIndex, (colorArray.length-1)*(100-speed))
	}
}

function callFunction (funcString, serialize, DLsetVarIndex, DLwaitVarIndex) {
	var regexp = /'/g; //Remove quotes from function call...
	if (serialize && DLwaitVar[DLwaitVarIndex] != 'done') {
		setTimeout('callFunction(\'' + funcString.replace(regexp, '\\\'') + '\', true, ' + DLsetVarIndex + ',' + DLwaitVarIndex + ')', 50);
	} else {
		eval(funcString);
		if (serialize) DLwaitVar[DLsetVarIndex] = 'done';
	}
}



function DLgetObjScreenLeft (objId) {
	leftCoord = getObj(objId).offsetLeft;
	parentObj = getObj(objId).offsetParent;
	while (parentObj) {		
		leftCoord = leftCoord + parentObj.offsetLeft;
		parentObj = parentObj.offsetParent;
	}
	return leftCoord;
}

function DLgetObjScreenTop (objId) {
	topCoord = getObj(objId).offsetTop;
	parentObj = getObj(objId).offsetParent;
	while (parentObj) {		
		topCoord = topCoord + parentObj.offsetTop;
		parentObj = parentObj.offsetParent;
	}
	return topCoord;
}
