/* --------------- STUDIO CONNECTIONS EXTERNAL JAVASCRIPT FILE -------------- */
/*                                                                            */
/*    Description: JavaScript common to all pages                             */
/*         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                                                 */


// Box width correction for IE 5.0 for Windows
ua = navigator.userAgent.toLowerCase();
n = ua.indexOf("msie");
hasWin = ua.indexOf("win")!=-1 || ua.indexOf("16bit") != -1;
hasIE = n > 0 && window.ActiveXObject ? true : false;
hasIEver = hasIE ? parseFloat(ua.substring(n + 5)) : 0;
hasNonStdBox = hasIE && hasWin && hasIEver < 6;
if (hasNonStdBox) {
  document.write('<style type="text/css">'
               + '@media screen {.BoxA {width: 783px;}}'
               + '</style>\n');
}

function BTSel(Button) {                          // called by onmouseover event

  // Highlight button
  if (!Button.className) {
    Button.className = "Sel";
  }

  // Check for corresponding Menu button
  if (top.frames.length > 0 && top.BTSel) {
    top.BTSel(BTFind(Button));
  }
}

function BTOut(Button) {                           // called by onmouseout event

  // Return button to normal
  if (Button.className && Button.className == "Sel") {
    Button.className = "";
  }

  // Check for corresponding Menu button
  if (top.frames.length > 0 && top.BTOut) {
    top.BTOut(BTFind(Button));
  }
}

function BTDep(Button) {                          // called by onmousedown event

  // Depress button
  Button.className = "Dep";

  // Bail for buttons with no href
  if (Button.href == "javascript:void(0)") {
    return;
  }

  // Turn off any other buttons or links on current page
  for (var i=0; i < document.links.length; i++) {
    if (document.links[i].className == "Act") {
      document.links[i].className = "";
    }
  }

  // Check for corresponding Menu button
  if (top.frames.length > 0 && top.BTDep) {
    top.BTDep(BTFind(Button));
  }
}

function BTClick(Button) {                            // called by onclick event

  // Return button to highlighted
  Button.className = "Sel";

  // Bail for buttons with no href
  if (Button.href == "javascript:void(0)") {
    return false;
  }

  // Get page anchor
  if (Button.href.lastIndexOf("#") != -1) {
    var Anc = Button.href.substr(Button.href.lastIndexOf("#") + 1);
  }

  // Check for corresponding Menu button
  BTFail = top.frames.length > 0 && top.BTClick ?
    top.BTClick(BTFind(Button), Anc) : true;

  if (BTFail) {

    // Set page address
    BTPageAd = Button.href;       // This variable must survive outside function

    // Delay page loading to allow button to return to correct state
    setTimeout("self.location = BTPageAd", 250);
  }

  // Disable normal link operation
  return false;
}

function BTFind(Button) {
  if (document.links) {
    for (var f = 0; f < top.frames.length; f++) {
      var BTList = top.frames[f].document.links;
      for (var i = 0; i < BTList.length; i++) {
        if (BTList[i].target == "Main" &&
          escape(Button.href).indexOf(escape(BTList[i].href)) != -1) {
          return BTList[i];
        }
      }
    }
  }
}

function JukePick(SongLink) {
  if (top.Upper && top.Upper.Loaded && top.Upper.JukeControl) {

    // Make JukeBox play the song specified in the link
    top.Upper.JukeAddr = SongLink;
    top.Upper.JukeAuto = false;
    top.Upper.JukeMode = "Play";
    top.Upper.JukeControl();
  }
  else {
    window.alert("To play a song, you must go to the full site.");
    top.location="../../index.html";
  }
}

function MiniItem(MiniSubP, MiniAddr, MiniCapt, MiniDesc) {
  this.SubP = MiniSubP;
  this.Addr = MiniAddr;
  this.Capt = MiniCapt;
  this.Desc = MiniDesc;
}

function MiniMake() {
  if (top.Upper && top.BTCur && document.links && document.getElementById) {

    // Create array
    if (!top.MiniMenu) {
      top.MiniMenu = new Array();
    }

    // Check if current contents page already in array
    for (i=0; i < top.MiniMenu.length; i++) {
      if (top.MiniMenu[i].SubP == document.location.href) {
        return;
      }
    }    

    // Add info for current contents page
    Offset = top.MiniMenu.length;
    for (i=0; i < document.links.length; i++) {
      top.MiniMenu[i + Offset] = 
        new MiniItem(document.location.href, document.links[i].href,
          document.links[i].innerText, document.links[i].title);
    }
  }  
}
