/******************************************************************************
* function adjustContentHeight()
* This function determines and sets the height of the content div
******************************************************************************/
function adjustNavHeight()
{
  // Get all the divs we need    
  var headerDiv = document.getElementById('header');  
  var navBar = document.getElementById('navbar');
  var content = document.getElementById('content');  
  var nav = document.getElementById('nav');
  var footer = document.getElementById('footer');
  
  //Do all exist?
  if ((nav != null) && (content != null) && (headerDiv != null) && (navBar != null) && (footer != null))
  { 
    //Determine the new left nav height
    var navDivNewHeight = content.offsetHeight;    
    //Minimum height is 650
    if (navDivNewHeight < 650)
    {  navDivNewHeight = 650; }
    nav.style.height =  navDivNewHeight + 'px';    

    //Determine the new footer position
    var footerTopPos = headerDiv.offsetHeight +
                     + navBar.offsetHeight 
                     + content.offsetHeight
                     + 20;
    //minimum height is 754                     
    if (footerTopPos < 754)
    {  footerTopPos = 754; }
    footer.style.top = footerTopPos  + 'px';
    
    //Set the left position of the footer
    var footerLeftPos = headerDiv.offsetLeft;
    footer.style.left = footerLeftPos  + 'px';    
  }
}


//Function for counting instances in a string
function countInstances(string, word) {
  var substrings = string.split(word);
  return substrings.length - 1;
}

//Function for setting the image bottom left
function setNavImage()
{
  //Build up array of background settings
  images = new Array(3);
  images[0] = "url(/images/nav_left1.jpg) no-repeat 50% bottom";
  images[1] = "url(/images/nav_left2.jpg) no-repeat 50% bottom";
  images[2] = "url(/images/nav_left3.jpg) no-repeat 50% bottom";

  //Get a random background
  index = Math.floor(Math.random() * images.length);

  //Get the nav div
  var divNav = document.getElementById("nav");      
  
  //Determine how many slashes there are in the url. We don't want to change the homepage image
  var iSlashAmount = countInstances(location.href, "/");
  if ((divNav != null) && (iSlashAmount > 3))
  { 
    divNav.style.background = images[index];
  }
}
