//======================================
// Program:       Event Page Expandables
// Date:          12.29.2010
// Last Modified: 12.29.2010
//======================================

function toggleEventPannelStatus(content)
{
  var expand = (content.style.display=="none");
  content.style.display = (expand ? "block" : "none");
  var expandImg = content.parentNode.firstChild.childNodes[1].childNodes[0];
  expandImg.src = expandImg.src.split(expand ? "event_expand.gif" : "event_collapse.gif").join(expand ? "event_collapse.gif" : "event_expand.gif");
}

// not animated collapse/expand
function toggleEventPanelStatusWithoutAnimation(content)
{
    var expand = (content.style.display=="none");
    content.style.display = (expand ? "block" : "none");
    toggleEventExpandableIcon(content);
}

// current animated collapsible panel content
var currentEventContent = null;

// animated collapse/expand
function toggleEventPanelAnimatedStatus(content, interval, step)
{
  // wait for another animated expand/collapse action to end
  if (currentEventContent==null)
  {
    currentEventContent = content;
    var expand = (content.style.display=="none");
    if (expand) content.style.display = "block";
    var max_height = content.offsetHeight;
    var step_height = step + (expand ? 0 : -max_height);
    toggleEventExpandableIcon(content);                
   // schedule first animated collapse/expand event
    content.style.height = Math.abs(step_height) + "px";
    setTimeout("toggleEventPanelAnimatingStatus(" + interval + "," + step + "," + max_height + "," + step_height + ")", interval);
  }
}

function toggleEventPanelAnimatingStatus(interval, step, max_height, step_height)
{
  var step_height_abs = Math.abs(step_height);
  // schedule next animated collapse/expand event
  if (step_height_abs>=step && step_height_abs<=(max_height-step))
  {
    step_height += step;
    currentEventContent.style.height = Math.abs(step_height) + "px";
    setTimeout("toggleEventPanelAnimatingStatus(" + interval + "," + step + "," + max_height + "," + step_height + ")", interval);
  }
  // animated expand/collapse done
  else
  {
    if (step_height_abs<step) currentEventContent.style.display = "none";
    currentEventContent.style.height = "";
    currentEventContent = null;
  }
}

function toggleEventExpandableIcon(content)
{
    var toggleImage = content.parentNode.firstChild.childNodes[1].childNodes[0];
    var expand = (toggleImage.src.indexOf("expand.gif")>0);
    toggleImage.src = toggleImage.src.split(expand ? "expand.gif" : "collapse.gif").join(expand ? "collapse.gif" : "expand.gif");
}
