/* TriHards Javascript File */

function rotateMh(pre) {
  var i = Math.floor( Math.random() * 10 );
  var mhImg = document.getElementById("mhImg");
  if ( mhImg != null )
  {
    mhImg.src =  pre + "images/mh/masthead" + i + ".png";
  }
}

function loadPage( pre, exp, navto)
{
  rotateMh( pre );
  expand( exp );
  navTo( navto );
}

function rotateTips() {
  var i = Math.floor( Math.random() * 10 );
  var tipArray = new Array("Never try new gear on race day",
                           "Half fill your drinking bladder and freeze it laying down the night before the race for icey-cold drinks during the event the next day.",
                           "Get a good navigator or, better yet, learn to navigate!",
                           "Don&rsquo;t follow other teams",
                           "Make sure you have a bike emergency kit!",
                           "Remember your bike helmet!",
                           "Put a drink bottle of fresh water on your bike at the bike drop.",
                           "Make sure your bike is street legal",
                           "Plan your course",
                           "Carry a spare compass", 
                           "Get good waterproof containers!",
                           "Secure your control card.",
                           "Stuffing your wet shoes with newspaper helps them dry faster.",
                           "Pin Gu packets by the top to your hydration pack using a safety pin - then you can tear them off one-handed during a race.",
                           "Don&rsquo;t forget the sunscreen!");
  
  var tip = document.getElementById("tip");
  if ( tip != null ) {
    tip.innerHTML = tipArray[i]
  }
}

function showMonth( oldMonth, newMonth )
{
  var old = document.getElementById( oldMonth );
  var cur = document.getElementById( newMonth );
  if ( old != null  && cur != null)
  {
    old.className="notCurrent";
    cur.className = "Current";
  }
}

function expand( id )
{
  var block = document.getElementById( id );
  if ( block != null ) {
    if ( block.className == "collapsed")
      block.className = "expanded";
    else
      block.className = "collapsed";
  }
}

function expander( divId, imgId )
{
  expand( divId );
  var expImg = document.getElementById( imgId );
  if ( expImg != null )
  {
    if ( expImg.src == "http://trihards.net/images/liimg.png") {
      expImg.src = "http://trihards.net/images/liimgdn.png";
    } else {
      expImg.src = "http://trihards.net/images/liimg.png";
    }
  }
}

function navTo( id )
{
  var block = document.getElementById( id );
  if ( block != null ) {
    if ( block.className == "subList")
    {
      block.className = "subListCurrent";
      return;
    }
    if ( block.className == "lvl2List")
    {
      block.className = "lvl2ListCurrent";
      return;
    }
    if ( block.className == "topList")
    {
      block.className = "topListCurrent";
    }
  }
}

    	// Hide the lightbox.
    	function hideLight() {
    	  document.getElementById('light').style.display = 'none';
    	  document.getElementById('lightBack').style.display = 'none';
	  var bigImg = document.getElementById( 'ltImage' );
	  bigImg.style.display='none';
	  bigImg.src = "";
	  document.getElementById('spinner').style.display = 'block';
    	}
	
	function lbImageLoaded()
	{
	  var ibigImg = document.getElementById( 'ltImage' );
	  ibigImg.style.display = 'block';
	  document.getElementById('spinner').style.display = 'none';
	}
	
    	function getIEOffset( imgObj )
	{
	  var top = 0;
	  if ( imgObj.offsetParent )
	  {
	    do { top += imgObj.offsetTop; } while ( imgObj == imgObj.offsetParent );
	  }
	  return top;
	}
	
	
    	function showLight( img, imgId )
    	{
	  document.getElementById('light').style.display = 'block';
	  document.getElementById('lightBack').style.display = 'block';
	  var bigImg = document.getElementById( 'ltImage' );
	  bigImg.style.display = 'none';
	  bigImg.src = img;
	  document.getElementById( 'ltText' ).innerHTML = document.getElementById( imgId ).title;
	  var imTop;
	  if (navigator.appName == 'Microsoft Internet Explorer') {
	    imTop = getIEOffset( document.getElementById( imgId ));
	   } else {
	    imTop = document.getElementById( imgId ).offsetTop;
	  }
	  document.getElementById('light').style.top = imTop + 'px';
    	}