/*
 Contains javascript functions for displaying and hiding media details.
 Julien Roubieu - 26/05/06
*/

/*
    Opens or close div with id 'detailsX', where X is given mediaId
*/

var smooth_timer;

function switchDetails(mediaId)
{
    var details = $('details' + mediaId);
    if (details.style.display == 'none') {
        Element.show(details);
    }
    else {
        Element.hide(details);
    }
    return false;
}

function openDetails(id, current, target, step)
{
  diff = target - current;
  if (diff < step)  {
  	step = diff;
  	}
  if (diff > 0) {
  	newH = current + step;
    ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.height = newH + "px";
    if (smooth_timer) window.clearTimeout(smooth_timer);
    smooth_timer = window.setTimeout( "openDetails('" + id + "'," + newH + "," + target + "," + step + ")", 20 );
  }
}

function closeDetails(id, current, step)
{
  if (current.indexOf("px") != -1) current = current.substring(0, current.indexOf("px"));
  newH = (current < step) ? 0 : current - step;
  ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.height = newH + "px";
  if (newH != 0) {
     if (smooth_timer) window.clearTimeout(smooth_timer);
     smooth_timer = window.setTimeout( "closeDetails('" + id + "','" + newH + "'," + step + ")", 20 );
  }
  else {
    ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.display = "none";
  }
}
