
//Name:    suBridgeKit.js
//Author:  Anders Frostad
//Created: 06.25.2007
//Changed: 07.03.2007

/*
TABLE OF CONTENTS
- Class #1:    Ajax(requestURL)
- Function #1: loadFlash(file, width, height, bgcolor, flashvars)
- Function #2: doNothing()
- Function #3: toggleVisibility(id, toggle, tween)
- Function #4: changeHeight(id, newHeight, evalWhenDone)
*/

//***********************************************
//*************** Class #2: Ajax ****************
//***********************************************

function Ajax(requestURL)
{
  this.handleResponse = function()
  {
    if ( me._http.readyState == 4)
    {
      var rawdata = me._http.responseText.split('|');
      for( var i = 0; i < rawdata.length; i++ )
      {
        var item = (rawdata[i]).split('=>');
        if( item[0].substring(7, 26) == '<b>Parse error</b>:' )
          reportBug(BUGCRITICAL, item[0]);
        else if( item[0] != '' )
        {
          if( item[0] == "javascript" )
            eval(item[1]);
          else
            document.getElementById(item[0]).innerHTML = item[1];
        }
      }
    }
  }
  
  var me = this;
  
  if( ! ( typeof requestURL == "undefined" ) )
    this.request(requestURL);
}

try
{
  Ajax.prototype._http = new XMLHttpRequest();
}
catch(e)
{
  Ajax.prototype._http = new ActiveXObject("Microsoft.XMLHTTP");
}

Ajax.prototype.request = function(requestURL)
{
    this._busy = true;
    this._http.open('GET', requestURL, true);
    this._http.onreadystatechange = this.handleResponse;
    this._http.send(null);
}

//***********************************************
//*********** Function #1: loadFlash ************
//***********************************************

loadFlash = function(file, width, height, bgcolor, flashvars)
{
  if( bgcolor == '#ff00ff' )
    windowmode = 'transparent';
  else
    windowmode = 'window';

  document.write( '' +
  '<object classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '">' +
  '  <param name = "movie" value="' + file + '" />' +
  '  <param name="quality" value="high" />' +
  '  <param name="bgcolor" value="' + bgcolor + '" />' +
  '  <param name="wmode" value="' + windowmode + '" />' +
  '  <param name="FlashVars" value="' + flashvars + '">' +
  '  <embed src="' + file + '" FlashVars="' + flashvars + '" quality="high" bgcolor="' + bgcolor + '" width="' + width + '" height="' + height + '" wmode="' + windowmode + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
  '</object>');
}

//***********************************************
//*********** Function #2: doNothing ************
//***********************************************

doNothing = function()
{
}

//***********************************************
//******** Function #3: toggleVisibility ********
//***********************************************
var TOGGLE_AUTO = 0;
var TOGGLE_ON   = 1;
var TOGGLE_OFF  = 2;
toggleVisibility = function(id, toggle, tween)
{
  element = document.getElementById(id);
  
  if( ! element.tweening )
  {
    if( ( element.style.visibility == 'hidden' || toggle == TOGGLE_ON ) && toggle != TOGGLE_OFF )
    {
      element.style.display = 'block';
      element.style.visibility = 'visible';
      if( tween == true )
        changeHeight(id, element.originalHeight, '');
    }
    else
    {
      if( tween == true )
      {
        element.originalHeight = element.offsetHeight;
        changeHeight(id, 0, 'toggleVisibility("' + id + '", TOGGLE_OFF, false);');
      }
      else
      {
        element.style.display = 'none';
        element.style.visibility = 'hidden';
      }
    }
  }
}

//***********************************************
//********** Function #4: changeHeight **********
//***********************************************

changeHeight = function(id, newHeight, evalWhenDone)
{
  targetObject = document.getElementById(id);
  targetObject.tweening = true;
  
  if( ! ( targetObject.offsetHeight == newHeight ) )
    setTimeout("changeHeight('" + id + "'," + newHeight + ", '" + evalWhenDone + "')", 50);
  else
  {
    targetObject.tweening = false;
    eval(evalWhenDone);
  }
  
  if( targetObject.offsetHeight < newHeight )
  {
    var suggestChange = (newHeight - targetObject.offsetHeight) / 5;
    if( suggestChange < 1 )
      targetObject.style.height = newHeight + "px";
    else
      targetObject.style.height = targetObject.offsetHeight + Math.ceil(suggestChange) + "px";
  }

  if( targetObject.offsetHeight > newHeight )
  {
    var suggestChange = (targetObject.offsetHeight - newHeight) / 5;
    if( suggestChange < 1 )
      targetObject.style.height = newHeight + "px";
    else
      targetObject.style.height = targetObject.offsetHeight - Math.floor(suggestChange) + "px";
  }
}
