function setup_jQuery(activeSection) {
    $("#title H1").addClass('ui-widget-header');
    $("#accordion").accordion({collapsible: true});
    if (activeSection > 0) {
      if ($("#accordion").accordion('option', 'active') != activeSection) {
        $("#accordion").accordion('activate', activeSection);
      }
    } else if (activeSection < 0) {
      $("#accordion").accordion('activate', false);
    }
    $("#home_div").addClass('ui-accordion');
    $("#home_div").addClass('ui-widget');
    $("#home_div").addClass('ui-helper-reset');
    $("#home_link").addClass('ui-accordion-header');
    $("#home_link").addClass('ui-helper-reset');
    //hover states on the static widgets
    $("#home_link").hover(
      function() {
        $(this).addClass('ui-state-hover');
      },
      function() {
        $(this).removeClass('ui-state-hover');
      }
    );
    $("#bookmark A").addClass('ui-state-default');
    $("#bookmark A").addClass(' ui-corner-all');
    //hover states on the static widgets
    $("#bookmark A").hover(
      function() {
        $(this).addClass('ui-state-hover');
      },
      function() {
        $(this).removeClass('ui-state-hover');
      }
    );
    $("H3").addClass('ui-widget-header');
    $("#menubar").css("visibility", "visible");
}

function CreateBookmarkLink(title,url) {
  if (window.sidebar) { // firefox
     window.sidebar.addPanel(title, url, "");
  } else if (document.all) { // IE
     window.external.AddFavorite(url, title);
  } else if (window.opera && window.print) { // opera
     var elem = document.createElement('a');
     elem.setAttribute('href',url);
     elem.setAttribute('title',title);
     elem.setAttribute('rel','sidebar');
     elem.click();
  }
}

function showPopMenu(section) {
  var divMenu = document.getElementById('menu_' + section);
  var divPos = findPos(divMenu);
  var leftPos = divPos[0];
  var topPos = divPos[1];
  var divPopmenu = document.getElementById('popmenu_' + section);
  divPopmenu.style.display = 'block';
  divPopmenu.style.left = leftPos + 'px';
  divPopmenu.style.top = topPos + 'px';
}

function hidePopMenu(evt, section) {
  if (!evt) var evt = window.event;
  var tg = (window.event) ? evt.srcElement : evt.target;
  var divPopmenu = document.getElementById('popmenu_' + section);
  // if mouse does not come from the popmenu DIV, check if it is from one of its descendents
  if (tg != divPopmenu) {
    while (tg != divPopmenu && tg.nodeName != 'BODY') {
      tg = tg.parentNode;
    }
  }
  // Event not related to popmenu so return
  if (tg != divPopmenu) return;
  // Check if moved to descendant within the popmenu
  var reltg = (evt.relatedTarget) ? evt.relatedTarget : evt.toElement;
  if (reltg == null) return;
  while (reltg != tg && reltg.nodeName != 'BODY') {
    reltg = reltg.parentNode;
    if (reltg == null) {
      divPopmenu.style.display = 'none';
      return;
    }
  }
  // Mouse moved within popmenu so return
  if (reltg == tg) return;
  // Mouse left popmenu so hide it
  divPopmenu.style.display = 'none';
}

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
  }
  return [curleft,curtop];
}


function show_hide_dialog(id, heading) {
  var dialog = document.getElementById(id);
  var overlay = document.getElementById('overlay');
  var container = document.getElementById('container');
  if (dialog.style.display == "none") {
    //var overlayHeight = document.body.offsetHeight;
    var overlayHeight = container.offsetHeight;
    var overlayWidth = container.offsetWidth;
    overlay.style.height = overlayHeight + "px";
    overlay.style.width = overlayWidth + "px";
    overlay.style.display = "block";
    dialog.style.display = "block";
    var windowWidth = 0, windowHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
      //Non-IE
      windowWidth = window.innerWidth;
      windowHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      windowWidth = document.documentElement.clientWidth;
      windowHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      windowWidth = document.body.clientWidth;
      windowHeight = document.body.clientHeight;
    }
    var backgroundHeight = (windowHeight > overlayHeight) ? overlayHeight : windowHeight;
    var backgroundWidth = (windowHeight > overlayHeight) ? overlayHeight : windowHeight;
    var topDialog = (backgroundWidth  / 2) - (dialog.offsetHeight / 2);
    var leftDialog = (windowWidth / 2) - (dialog.offsetWidth / 2);
    dialog.style.top = topDialog + "px";
    dialog.style.left = leftDialog + "px";
    headings = dialog.getElementsByTagName('H3');
    headings[0].innerHTML = heading;
  } else { // shown already so hide
    overlay.style.display = "none";
    dialog.style.display = "none";
  }
}
