Department.prototype._websites = null;

Department.prototype.GetName = function() {
  var websites = this.GetWebsites();

  if (websites.length > 0)
  {
    return ('<a href="' + websites[0].url + '"' + (websites[0].target != null ? (' target="' + websites[0].target + '"') : "") + '>' + this.name + '</a>');
  }
  else
  {
    return this.name;
  }
}

Department.prototype.GetWebsites = function() {
  if (this._websites == null)
  {
    this._websites = new Array();

    for (var i = 0; i < this.websites.length; i++)
    {
      var url = this.websites[i];
      var target = null;
      var index = url.indexOf(";");

      if (index != -1)
      {
        target = url.substring(index + 1);
        url = url.substring(0, index);
      }

      this._websites[i] = new Object();
      this._websites[i].url = url.indexOf("http://") != -1 ? url : (GetRootUrl() + url);
      this._websites[i].target = target;

      this._websites[i].GetLink = function() {
        return ('<a href="' + this.url + '"' + (this.target != null ? (' target="' + this.target + '"') : "") + '>' + this.url + '</a>');
      }
    }
  }

  return this._websites;
}

var _departmentsOut = null;

function InitDepartments()
{
  _departmentsOut = document.createElement("div");
  _departmentsOut.id = "depInfo";
  document.getElementsByTagName("body")[0].appendChild(_departmentsOut);
  ShowLinks();
}

function ShowLinks()
{
  var NUM_COLS = 3;
  var html = '<table width="95%" border="0" cellpadding="5" cellspacing="0">';

  for (var i = 0; i < _departments.length; i += NUM_COLS)
  {
    html += '<tr>';

    for (var j = 0; j < NUM_COLS; j++)
    {
      if (i + j < _departments.length)
      {
        html += '<td><a href="javascript:ShowDepartment(' + (i + j) + ')">' + _departments[i + j].name + '</a></td>';
      }
      else
      {
        html += '<td>&nbsp;</td>';
      }
    }

    html += '</tr>';
  }

  html += '</table>';
  document.getElementById("depList").innerHTML = html;
}

function ShowDepartment(index)
{
  var html = '<a href="javascript:HideDepartment()" onmouseover="document.getElementById(\'btnClose\').src = rootRelToPage + \'images/ms_btn_close_over.gif\'" onmouseout="document.getElementById(\'btnClose\').src = rootRelToPage + \'images/ms_btn_close_out.gif\'"><img src="' + rootRelToPage + 'images/ms_btn_close_out.gif" width="13" height="13" id="btnClose" align="right" border="0" alt="Close Contact Information" title="Close Contact Information"></a>'
           + '<b>' + _departments[index].GetName() + '</b>';

  var websites = _departments[index].GetWebsites();

  for (var i = 0; i < websites.length; i++)
  {
    html += '<br><span style="color:red">Website:</span> ' + websites[i].GetLink();
  }

  var offcBld = null;

  for (var i = 0; i < _offcBlds.length; i++)
  {
    if (_offcBlds[i].id == _departments[index].offcBldId)
    {
      offcBld = _offcBlds[i];
      break;
    }
  }

  html += '<p style="margin-left:16px; margin-right:10px; margin-bottom:3px">'
       +  (_departments[index].office ? (_departments[index].office + '<br>') : "")
       +  (offcBld != null && offcBld.address ? (offcBld.address + '<br>') : "")
       +  (_departments[index].location ? (_departments[index].location + (offcBld != null && offcBld.name ? (', ' + offcBld.name) : "") + '<br>') : "")
       +  (offcBld != null && offcBld.zip ? ('Hampton, VA ' + offcBld.zip + '<br>') : "");

  for (var i = 0; i < _departments[index].phones.length; i++)
  {
    html += '<br>Phone: ' + _departments[index].phones[i];
  }

  html += (_departments[index].fax ? ('<br>Fax: ' + _departments[index].fax) : "")
       +  (_departments[index].email ? ('<br>Email: <a href="mailto:' + _departments[index].email + '">' + _departments[index].email + '</a>') : "")
       +  (_departments[index].workhours ? ('<br><br>Hours: ' + _departments[index].workhours) : "") + '</p>';

  _departmentsOut.innerHTML = html;
  var clientWidth = document.all ? document.body.clientWidth : window.innerWidth;
  var clientHeight = document.all ? document.body.clientHeight : window.innerHeight;
  _departmentsOut.style.left = (_mouseX + _departmentsOut.offsetWidth) > clientWidth ? (_mouseX - _departmentsOut.offsetWidth) : _mouseX;
  _departmentsOut.style.top = ((_mouseY + _departmentsOut.offsetHeight) > (clientHeight - 32) ? (_mouseY - _departmentsOut.offsetHeight) : _mouseY) + (document.all ? document.body.scrollTop : 0);
  _departmentsOut.style.visibility = "visible";
}

function HideDepartment()
{
  _departmentsOut.style.visibility = "hidden";
}

