// **********************************************************************************
// NAME:        Interface Effect Routines
// DESCRIPTION: Library of user interface AJAX JavaScript routines
// CREATED:     12/1/2006 © Copyright One Bad Ant 
// Copyright © One Bad Ant - all rights reserved
// **********************************************************************************

// **********************************************************************************
// NAME:        oba_toggleDisplay
// DESCRIPTION: Routine to toggle the display (show or hide) of an interface element
// INPUT:       (1) The id of the element
// **********************************************************************************
function oba_toggleDisplay(div_id) 
{
	thiselement = document.getElementById(div_id).style;
	
	if (thiselement.display == "block")
       {thiselement.display = "none";}
	else
       {thiselement.display = "block";}
}

// ***********************************************************************************
// NAME:        oba_setDivDisplay
// DESCRIPTION: Routine to set the display of an interface element
// INPUT:       (1) The id of the element
//              (2) The state to which to set the element's display ("none," "block")
// ***********************************************************************************
function oba_setDivDisplay(div_id,div_state) 
{
	thiselement = document.getElementById(div_id).style;
	thiselement.display = div_state;
}

// ***********************************************************************************
// NAME:        oba_setDivVisibility
// DESCRIPTION: Routine to set the visibility of an interface element
// INPUT:       (1) The id of the element
//              (2) The state to which to set the element's display ("visible," "hidden")
// ***********************************************************************************
function oba_setDivVisibility(div_id,div_state) 
{
	thiselement = document.getElementById(div_id).style;
	thiselement.visibility = div_state;
}

// ***********************************************************************************
// NAME:        oba_changeDivClass
// DESCRIPTION: Routine to change the class of an interface element
// INPUT:       (1) The id of the element
//              (2) The CSS class to apply to the element
//              (3) The name of the 'skip' class.  This is useful if an item in a list
//                  has been choosen and highlighted and you want to skip the rollover
//                  effect for this one item.
// ***********************************************************************************
function oba_changeDivClass(div_id,div_class,skip_class) 
{
	if (document.getElementById(div_id).className != skip_class)
	   {
	   thiselement = document.getElementById(div_id);
       thiselement.setAttribute("class",div_class);
       thiselement.setAttribute("className",div_class); // IE workaround
	   }
}

// ***********************************************************************************
// NAME:        oba_toggleDisplay_byarrow
// DESCRIPTION: Routine to toggle the display (show or hide) of an interface element
//              and the "open" or "close" state of an expansion arrow icon
//              (note: an arrow is not required - can be any image whose state changes.
// INPUT:       (1) The id of the element to toggle (show or hide)
//              (2) The id of the graphic element to toggle (on or off state)
//              (3) The path and name of the graphic to change minus the "_on.gif"
//              or "_off.gif" suffix. The two graphics (one for each state) must be
//              named the same except for these suffixes.
// ***********************************************************************************
function oba_toggleDisplay_byarrow(div_id,graphic_id,graphic_name)
{
   	thisDIVelement = document.getElementById(div_id).style;
	
	if (thisDIVelement.display == "block")
	   // if the div is open, then close the div and turn the graphic to its "off" state
       {
	   thisDIVelement.display = "none";
	   document.getElementById(graphic_id).src = graphic_name + "_off.gif";  
	   }
	else
	   // else open the div and turn the graphic to its "on" state
       {
	   thisDIVelement.display = "block";
	   document.getElementById(graphic_id).src = graphic_name + "_on.gif";  
	   }
}

// ***********************************************************************************
// NAME:        oba_setImageSource
// DESCRIPTION: Routine to set the source of an image
// INPUT:       (1) The id of the image
//              (2) The source of the image file (path and file name)
// ***********************************************************************************
function oba_setImageSource(image_id,image_source) 
{
	thisimage = document.getElementById(image_id);
	thisimage.src = image_source;
}

// ***********************************************************************************
// NAME:        oba_wipe_div
// DESCRIPTION: Effect to expand the dimensions of a div using a 'wipe' effect
//              While the wipe direction can be controlled, the assumption is a fixed
//              top left div corner
// INPUT:       (1) The id of the div to wipe
//              (2) The starting (minimum) dimension of the div (ie. 0 or 1)
//              (3) The ending (maximum) dimension of the div
//              (4) The speed of the wipe in milliseconds
//              (5) The direction of the wipe (up, down, left, right)
// ***********************************************************************************
function oba_wipe_div(div_id,start_dim,end_dim,speed,direction) 
{
   thisDIVelement = document.getElementById(div_id).style;

   // Increment the dimension
   if (direction == "down" || direction == "right")
      {start_dim++;}
   if (direction == "up" || direction == "left")
      {start_dim--;}

   // Set the new dimension
   if (direction == "down" || direction == "up")
      {thisDIVelement.height=start_dim;}
   if (direction == "right" || direction == "left")
      {thisDIVelement.width=start_dim;}

   // Speed (recall)
   if ((start_dim <= end_dim) && (direction == "down" || direction == "right"))
      {setTimeout("oba_wipe_div('" + div_id + "'," + start_dim + "," + end_dim + "," + speed + ",'" + direction + "')",speed);}
   if ((start_dim > end_dim) && (direction == "up" || direction == "left"))
      {setTimeout("oba_wipe_div('" + div_id + "'," + start_dim + "," + end_dim + "," + speed + ",'" + direction + "')",speed);}
}
