/* --------------- STUDIO CONNECTIONS EXTERNAL JAVASCRIPT FILE -------------- */
/*                                                                            */
/*    Description: Menu system - with pet extensions                          */
/*         Client: Cloud Studios - info@cloudstudios.com                      */
/*        Website: www.cloudstudios.com                                       */
/*         Author: Colin Abrahams - colin@studioconnections.net.au            */
/*      Copyright: 2008 Colin Abrahams, Studio Connections                    */
/*       Location: Wyong, NSW, Australia                                      */
/*        Version: SC-5.8                                                     */
/*   Last Updated: 2008-11-25                                                 */


function BTSel(Button) {                          // called by onmouseover event

  // Disturb the pet
  if (document.getElementById && top.Upper) {
    Pet = top.Upper.document.getElementById("Ninja");
    if (Pet) {
      Pet.className = "disturbed";
    }
  }

  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 BTOut(Button) {                           // called by onmouseout event

  // Settle the pet
  if (document.getElementById && top.Upper) {
    Pet = top.Upper.document.getElementById("Ninja");
    if (Pet) {
      Pet.className = "";
    }
  }

  if (Button && Button.className && Button.className == "Sel") {

    // Return button to normal
    Button.className = "";

    // Return submenus to normal
    BSSubTim = setTimeout("BSSub(top.BTCur)", 1000);
  }
}

function BTDep(Button) {                          // called by onmousedown event
  if (Button) {

    // Turn previous button off
    if (top.BTCur) {
      top.BTCur.className = "";
    }

    // Set current button
    top.BTCur = Button;

    // Depress current button
    Button.className = "Dep";
  }
}

function BTClick(Button) {                            // called by onclick event
  if (Button) {

    // Turn button on
    Button.className = "Act";

    // Set page address - this variable must survive outside function
    if (BTClick.arguments.length > 1 && BTClick.arguments[1] != null) {
      BTPageAd = Button.href + "#" + BTClick.arguments[1];
    }
    else {
      BTPageAd = Button.href;
    }

    // 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 frame count ready when site is first loading (issue with IE)
  if (!(top.FrCount && top.frames.length == FrCount)) {
    return;
  }

  // Check all frames loaded
  for (var f = 0; f < top.frames.length; f++) {
    if (!top.frames[f].Loaded) {
      return;
    }
  }

  // Initialise JukeBox and update cookie with current session start date
  // when site first loads or Upper frame is reloaded
  if (!top.SiteInit && top.HomeInit) {
    top.Upper.JukeInit ? top.Upper.JukeInit() : null;
    top.Upper.CKDataSet? top.Upper.CKDataSet() : null;
    top.SiteInit = true;
  }

  // Replace Loading page with Home Page when site is first loading
  if (!top.HomeInit) {
    setTimeout("top.Main.location = 'Site/Main/Home.html'", 1000);
    top.HomeInit = true;
    return;
  }

  // Settle the pet
  if (document.getElementById && top.Upper) {
    Pet = top.Upper.document.getElementById("Ninja");
    if (Pet) {
      Pet.className = "";
    }
  }

  // Set buttons and submenus according to currently loaded page
  if (document.links) {
    top.BTCur = null;
    top.BSCur = 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(BTList[i].href).indexOf(escape(BTPageAd)) != -1) {
            BTList[i].className = "Act";
            top.BTCur = BTList[i];
            var SubMenu = BSFind(BTList[i]);
            if (SubMenu) {
              SubMenu.className = "SubMenu";
              top.BSCur = 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.BSCur && (SubMenu && BSCur != SubMenu ||
    !SubMenu && top.BTCur == Button)) {
    BSCur.className = "SubMenu SubCl";
    BSCur = null;
  }

  // Open submenu for button object
  if (SubMenu) {
    SubMenu.className = "SubMenu";
    BSCur = SubMenu;
  }
}

