/* --------------------------------------------------------------------
exesdotorg Network
-------------------------------------------------------------------- */




/* ----------------------------------------------------------------- */
var functionObject = new Object();
/* ----------------------------------------------------------------- */


/* --------------------------------------------------------------------
Function Set: Element Transition
  elementTransition(), elementTransitor(), elementOpacity()
-----------------------------------------------------------------------
Function: elementTransition(elementId,direction,step,interval)
  This function simply fades in a specified element.

Input Variables:
 *elementId  str  The ID of the element to transition.
 *direction  str  Direction; either 'in' or 'out'.
 *step       num  At each transitioning phase the image is either faded
                  in or out depending on what value you give for 
                  direction; this value determines how much the 
                  opacity of the element is changed.  The number must 
                  be a product of 100.
 *interval   num  Interval between transitions.
-------------------------------------------------------------------- */
functionObject.elementTransition = new Object();
functionObject.elementTransition.currentOpacity = null;
function elementTransition(elementId,direction,step,interval) {
	if (!document.getElementById(elementId)) { showError("overwrite","The element ID '"+elementId+"' does not exist."); return false; }
	if (!inArray(direction,["in","out"])) { showError("overwrite","The direction is not valid; must be either 'in' or 'out'."); return false; }
	if ((step < 0) || (step > 100)) { showError("overwrite","The step must be between 0 and 100."); return false; }
	if (/\./.test((100/step))) { showError("overwrite","The step is invalid; 100/step can not be a float."); return false; }

	elementOpacity(elementId,((direction == "in") ? 0:100));
	functionObject.elementTransition.currentOpacity = ((direction == "in") ? 0:100);
	elementTransitor(elementId,direction,step,interval);
}
/* --------------------------------------------------------------------
Function: elementTransitor(elementId,direction,step,interval)
  Helper function for elementTransition; does the transitioning.
-------------------------------------------------------------------- */
function elementTransitor(elementId,direction,step,interval) {
	var currentOpacity = functionObject.elementTransition.currentOpacity;
	var newOpacity = ((direction == "in") ? currentOpacity+step:currentOpacity-step);
	if (newOpacity > 100) { newOpacity = 100; }
	if (newOpacity < 0) { newOpacity = 0; }
	elementOpacity(elementId,newOpacity);
	if ((newOpacity == 0) || (newOpacity == 100)) { return; }
	setTimeout("elementTransitor('"+elementId+"','"+direction+"',"+step+","+interval+");",interval);
}
/* --------------------------------------------------------------------
Function: elementOpacity(elementId,opacity)
  Helper function for elementTransitor; does the opacity change.
-------------------------------------------------------------------- */
function elementOpacity(elementId,opacity) {
	document.getElementById(elementId).style.filter = "alpha(opacity="+opacity+");";
	document.getElementById(elementId).style.opacity = (opacity/100);
	functionObject.elementTransition.currentOpacity = opacity;
}
/* ----------------------------------------------------------------- */


/* ---------------------------------------------------------------------
Function: inArray(value,array)
  Returns true if the specified value is in the specified array.

Input Variables:
 *needle    str  Value to find in the haystack.
 *haystack  ary  The array of values.
--------------------------------------------------------------------- */
function inArray(needle,haystack) {
	if ((typeof(needle) == "undefined") || (needle == null) || (needle.length < 1)) { return false; }
	if ((typeof(haystack) == "undefined") || (haystack == null) || (haystack.length < 1)) { return false; }
	else if (haystack.constructor != Array) { return false; }

	for (var loop1 = 0; loop1 < haystack.length; loop1++) { if (haystack[loop1] == needle) { return true; } }
	return false;
}
/* ------------------------------------------------------------------ */


/* ---------------------------------------------------------------------
Function: showError(method,error)
  Adds a message to the error box on the main page.

Input Variables:
 *method  str  "append" or "overwrite"
 *error   str  Message to append.
--------------------------------------------------------------------- */
var showErrorTimeout = null;
function showError(method,error) {
	if (!inArray(method,["append","overwrite"])) { return false; }
	if ((typeof(error) == "undefined") || (error == null) || (error.length < 1)) { return false; }

	elementTransition('errorContainer','in',10,50);
	if (showErrorTimeout != null) { clearTimeout(showErrorTimeout); }
	document.getElementById("errorContainer").style.display = "";
	if (method == "append") { document.getElementById("error").innerHTML = document.getElementById("error").innerHTML+"<br>"+error; }
	else if (method == "overwrite") { document.getElementById("error").innerHTML = error; }
	showErrorTimeout = setTimeout('elementTransition(\'errorContainer\',\'out\',5,50);',5000);
}
/* ------------------------------------------------------------------ */

