/********************************************************************
 * Scripts to adjust the height of the vertical logo to the 
 * available viewport height 
 ********************************************************************/ 

/* Adjust the height after the page has been loaded */ 
$(document).ready(function(){
  /* Since the default height is 120px, we have to reduce it to 90px */ 
  $("#servicenav").height(90);
  $("#servicenav").css('min-height', 90);
  
  /* Adjust the height */ 
  adjustServicenavHeight();
});


/* Adjust the height on every resize event */ 
$(window).resize(function(){
  adjustServicenavHeight();
});


/* Get the current height of the browser window's viewport */
function getViewportHeight() {
  var y;
  if (self.innerHeight) // all except Explorer
  {
    y = self.innerHeight;
  }
  else
  {
    // Explorer 6 Strict Mode
    if (document.documentElement && document.documentElement.clientHeight)
    {
      y = document.documentElement.clientHeight;
    }
    // other Explorers
    else 
    {
      if (document.body) 
      {
        y = document.body.clientHeight;
      }
    }
  }
  return y;
}


/* Get the position of the given object */
function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) 
  {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return curtop;
}


/* Adjust the height of the service navigation, according to it's position */ 
function adjustServicenavHeight() {
  var outer, inner;
  outer = getViewportHeight();
  inner = findPos(document.getElementById('servicenav'));
  
  if (outer - inner > 120) 
  { 
    // fix to real height of vertical logo
    $("#servicenav").height(120);
  } 
  else 
  {
    if (outer - inner > 90) {
      // limit the height of vertical logo to the available space 
      $("#servicenav").height(outer-inner);
    } else {
      // limit the height of vertical logo to 90px 
      $("#servicenav").height(90);
    }
  }
}

