/* --------------- STUDIO CONNECTIONS EXTERNAL JAVASCRIPT FILE -------------- */
/*                                                                            */
/*    Description: Menu system - permanent sub-menu version                   */
/*         Author: Colin Abrahams - colin@studioconnections.net.au            */
/*      Copyright: Colin Abrahams, Studio Connections                         */
/*       Location: Central Coast, NSW, Australia                              */
/*        Version: SC-5.8                                                     */
/*   Last Updated: 16-03-2011                                                 */


function BTOut(Button) {                           // called by onmouseout event
  if (Button && Button.className && Button.className == "Sel") {

    // Return button to normal
    Button.className = "";

    // Return submenus to normal
    BSSubTim = setTimeout("BSSub(top.BTCur)", 1000);
  }
}

function BTSel(Button) {                          // called by onmouseover event
  if (Button && !Button.className) {

    // Highlight button
    Button.className = "Sel";

    // Clear pending submenu close
    if (self.BSSubTim) {
      clearTimeout(BSSubTim);
    }

    // Find and open submenu for mouseover button
    BSSub(Button);
  }
}

function BTDep(Button) {                          // called by onmousedown event
  if (Button) {

    // Turn previous button off
    if (top.BTCur) {
      BTCur.className = "";
    }

    // Set current button
    BTCur = Button;

    // Depress current button
    Button.className = "Dep";
  }
}

function BTClick(Button) {                            // called by onclick event
  if (Button && top.Main) {

    // Turn button on
    Button.className = "Act";

    // Set page address
    BTPageAd = Button.href;       // This variable must survive outside function

    // Delay page loading to allow button to return to correct state
    setTimeout("top.Main.location = BTPageAd", 250);

    // Disable normal link operation
    return false;
  }
  else {
    return true;
  }
}

function BTSet() {                                // called by page onload event

  // Check all frames loaded
  if (!(top.FrCount && top.frames.length == FrCount)) {
    return;
  }
  for (var f = 0; f < top.frames.length; f++) {
    if (!top.frames[f].Loaded) {
      return;
    }
  }

  // Update current session start date, load final page and initialise JukeBox
  if (!top.BTInit) {
    top.VisitCurr ? CKSet("") : null;
    top.FinalPage ? setTimeout("top.Main.location = top.FinalPage", 250) : null;
    top.Upper && top.Upper.JukeInit ? top.Upper.JukeInit() : null;
    BTInit = true;
  }

  // Set buttons and submenus according to currently loaded page
  if (document.links) {
    BTCur = null;
    BSCur = null;
    BSTmp = null;
    BTPageAd = top.Main.location.href;
    for (var f = 0; f < top.frames.length; f++) {
      if (top.frames[f].name == "Main") {
        continue;
      }
      var BTList = top.frames[f].document.links;
      for (var i = 0; i < BTList.length; i++) {
        if (BTList[i].target == "Main") {
          if (escape(BTPageAd).indexOf(escape(BTList[i].href)) != -1) {
            BTList[i].className = "Act";
            BTCur = BTList[i];
            var SubMenu = BSFind(BTList[i]);
            if (SubMenu) {
              SubMenu.className = "SubMenu";
              BSCur = SubMenu;
              BSTmp = SubMenu;
            }
          }
          else {
            BTList[i].className = "";
            var SubMenu = BSFind(BTList[i]);
            if (SubMenu && !(top.BSCur && BSCur == SubMenu)) {
              SubMenu.className = "SubMenu SubCl";
            }
          }
        }
      }
    }
  }
}

function BSFind(Button) {
  if (Button && document.links && document.getElementById) {
    var Node = Button;
    while (Node != null && Node.nodeName != "BODY") {
      if (Node.className && Node.className.indexOf("SubMenu") != -1) {
        return Node;
      }
      Node = Node.parentNode;
    }
    for (var f = 0; f < top.frames.length; f++) {
      if (top.frames[f].name == "Main") {
        continue;
      }
      var BTList = top.frames[f].document.links;
      for (var i = 0; i < BTList.length - 1; i++) {
        if (BTList[i].target == "Main" &&
          escape(BTList[i].href).indexOf(escape(Button.href)) != -1) {
          Node = BTList[i + 1];
          while (Node != null && Node.nodeName != "BODY") {
            if (Node.className && Node.className.indexOf("SubMenu") != -1) {
              return Node;
            }
            Node = Node.parentNode;
          }
          return;
        }
      }
    }
  }
}

function BSSub(Button) {
  var SubMenu = BSFind(Button);

  // Close current submenu
  if (top.BSTmp && !(top.BSCur && top.BSCur == top.BSTmp) &&
    ( SubMenu && top.BSTmp != SubMenu || !SubMenu && top.BTCur == Button)) {
    BSTmp.className = "SubMenu SubCl";
    BSTmp = null;
  }

  // Open submenu for button object
  if (SubMenu) {
    SubMenu.className = "SubMenu";
    BSTmp = SubMenu;
  }
}

