/////////////////////////////////////////////////////////////////////////////////////////
//
// Client-side scripts for my Red Rocks Climbing Page.
//
// Jake Burkey, 08-24-2005.
//
/////////////////////////////////////////////////////////////////////////////////////////


// //////////////////////////////////////////////////////////////////////////////////////
//
// Cross-browser carriage return/line feed constant.

var jsCrLf;

if (!(navigator.userAgent.indexOf("Mac") >= 0)) {

  if (navigator.appName.indexOf("Netscape") >= 0) {
    jsCrLf = "\n";
  }
  else {
    jsCrLf = "\r\n";
  }
}
else {
  jsCrLf = "\r";
}



// //////////////////////////////////////////////////////////////////////////////////////
//
// Scripts for text rollovers.  RollOn is for onmouseover, RollOff is for onmouseout.

function RollOn(id) {
  var elem = document.getElementById(id);
  elem.style.fontSize = "18px";
  elem.style.fontWeight = "bold";
}


function RollOff(id) {
  var elem = document.getElementById(id);
  elem.style.fontSize = "";
  elem.style.fontWeight = "";
}



// //////////////////////////////////////////////////////////////////////////////////////
//
// Scripts for popup windows.

// Use the following line to call this function from the web page.
// <a href="#" onclick="return ShowPhoto('images/photo.jpg')">

function ShowPhoto(url) {
  var winTop = 0;
  var winLeft = 0;

  var winOptions = "";
  winOptions = winOptions + "left=" + winLeft + ",";
  winOptions = winOptions + "top=" + winTop + ",";
  winOptions = winOptions + "resizable,scrollbars";

  var newWin = window.open("","",winOptions);
  newWin.document.open();
  var sHtml = "<html>" + jsCrLf + "<head>" + jsCrLf;
  sHtml = sHtml + "<meta http-equiv='imagetoolbar' content='no'>" + jsCrLf;
  sHtml = sHtml + "<script type='text/javascript' src='scripts/rrc.js'></script>" + jsCrLf;
  sHtml = sHtml + "<link rel='stylesheet' href='styles/rrc.css' type='text/css'>" + jsCrLf;
  sHtml = sHtml + "<style>body{margin: 0em;} table{margin: 0em;}</style>" + jsCrLf;
  sHtml = sHtml + "</head>" + jsCrLf + "<body onload='FitPhoto()'>" + jsCrLf;
  sHtml = sHtml + "<table border='0' cellpadding='0' cellspacing='0'>" + jsCrLf;
  sHtml = sHtml + " <tr>" + jsCrLf + "  <td>" + "<img src='" + url + "'></td>" + jsCrLf;
  sHtml = sHtml + " </tr>" + jsCrLf + " <tr>" + jsCrLf + "  <td class='photo'>" + jsCrLf;
  sHtml = sHtml + "    " + "<a href='#' onclick='window.close()'>";
  sHtml = sHtml + "Close Window</a>" + jsCrLf;
  sHtml = sHtml + "  </td>" + jsCrLf + " </tr>" + jsCrLf + "</table>" + jsCrLf;
  sHtml = sHtml + "</body>" + jsCrLf + "</html>";
  newWin.document.write(sHtml);
  newWin.document.close();
  return false;
}

function FitPhoto() {

// The conditional ternary operator is used throughout this function, 
// and should be interpreted as:

// variable = (test statement)?value if true:value if false;

  var NS = (navigator.appName.indexOf("Netscape") >= 0)?true:false;
  var iWidth = (NS)?window.innerWidth:document.body.clientWidth;
  var iHeight = (NS)?window.innerHeight:document.body.clientHeight;
  var iLeft = document.images[0].width - iWidth;
  var iTop = document.images[0].height - iHeight + 16;
  window.resizeBy(iLeft,iTop);

  iWidth = (NS)?window.outerWidth:document.body.offsetWidth;
  iHeight = (NS)?window.outerHeight:document.body.offsetHeight + 20;
  iLeft = (iWidth > screen.availWidth)?screen.availWidth - iWidth:0;
  iTop = (iHeight > screen.availHeight)?screen.availHeight - iHeight:0;
  if (iLeft < 0 || iTop < 0) {window.resizeBy(iLeft,iTop);}

  if (iLeft < 0) {iLeft = (NS)?screen.availLeft:0;}
  else {iLeft = (screen.availWidth - iWidth)/2;}
  if (iTop < 0) {iTop = (NS)?screen.availTop:0;}
  else {iTop = (screen.availHeight - iHeight)/2;}
  window.moveTo(iLeft,iTop);
  self.focus();
}



// //////////////////////////////////////////////////////////////////////////////////////
//
// Scripts for addressing attributes of CSS classes.

// Script positions second and third photos relative to previous ones.

function ImgYPos(iTopMargin, iOffset) {

  if (document.getElementsByTagName) {
  
    var aImgNodes, i, oElemPrev, iTopPrev, iHeightPrev, oElemCurr;
    aImgNodes = document.getElementsByTagName("img");
    
    for (var i = 0; i < aImgNodes.length; i++) {
    
      oElemCurr = aImgNodes.item(i);
      if (i == 0) {
        oElemCurr.style.top = iTopMargin + 'px';
        }
      else {
        oElemPrev = aImgNodes.item(i-1);
        iTopPrev = parseInt(oElemPrev.style.top);
        iHeightPrev = parseInt(oElemPrev.height);
        oElemCurr.style.top = iTopPrev + iHeightPrev + iOffset + 'px';
      }
        
    }
      
  }
    
}



// //////////////////////////////////////////////////////////////////////////////////////
//
// SCRIPT ARCHIVE - Old scripts, do not use these functions.

// Script creates array of all nodes for a common CSS style class.
// e.g. makeNodeArrayClass("img", "betapage2")

// aNodeClass = new Array();

function makeNodeArrayClass(elem, cls) {

  if (document.getElementsByTagName) {
    var aNodes = document.getElementsByTagName(elem);
    
    for (var i = 0; i < aNodes.length; i++) {
      var oNode = aNodes.item(i);
      
      for (var j = 0; j < oNode.attributes.length; j++) {
        var oAttr = oNode.attributes.item(j);
        
        if (oAttr.nodeName == 'class' && oAttr.nodeValue == cls) {
          aNodeClass[aNodeClass.length] = oNode;
        }
          
      }
        
    }
      
  }
    
}


// Script positions second and third photos relative to previous ones.

function ImgYPos1(topMargin) {

  var i, oElemPrev, oElemCurr, iTop, iHeight;
  
  for (i = 0; i < document.images.length; i++) {
    oElemCurr = document.getElementById(document.images[i].id);
    
    if (i == 0) {
      oElemCurr.style.top = topMargin;
      }
    else {
      oElemPrev = document.getElementById(document.images[i-1].id);
      iTop = parseInt(oElemPrev.style.top);
      iHeight = parseInt(oElemPrev.height);
      oElemCurr.style.top = iTop + iHeight + 80 + 'px';
    }
      
  }
    
}