window.onload = init;
window.onresize = positionSecond;

// global variables
var pos1 = -1000;
var pos2 = 0;
var t;
var nav2_tohide = 1;

// function that loads when the page is done loading
//               calls the function positionSecond()
function init() {
  positionSecond();
}

// function that finds the position of the first level navigation
//               postions the second level navigation
function positionSecond() {
  pos1 = findPos('about' + currLang);
  pos2 = findPos('capabilities' + currLang);
  if (currLang == '') {
    width_nav2_1 = 75;
    width_nav2_2 = 91;
    height_nav2_1 = 0;
    height_nav2_2 = 4;
  }
  else if (currLang == '_de') {
    width_nav2_1 = 75;
    width_nav2_2 = 113;
    height_nav2_1 = 0;
    height_nav2_2 = 3;
  }
  else if (currLang == '_fr') {
    width_nav2_1 = 125;
    width_nav2_2 = 130;
    height_nav2_1 = 0;
    height_nav2_2 = 3;
  }
  // alert('pos1 = ' + pos1 + '\npos2 = ' + pos2);
  document.getElementById('nav2_1_home_outer').style.left = pos1[0] + width_nav2_1 + 'px';
  document.getElementById('nav2_1_home_outer').style.top  = pos1[1] + 'px';
  document.getElementById('nav2_2_home_outer').style.left = pos2[0] + width_nav2_2 + 'px';
  document.getElementById('nav2_2_home_outer').style.top  = pos2[1] + height_nav2_2 + 'px';
}

// function to show the correct first level nav images when the mouse 'hovers'
function activateOne(num) {
  hideSecondNow();
  deActivateTwo();
  if (num == 1) {
    document.getElementById('nav1_about').style.backgroundPosition = '0px -20px';
    document.getElementById('nav1_capabilities').style.backgroundPosition = '0px -40px';
    document.getElementById('nav1_contact').style.backgroundPosition = '0px -40px';
  }
  else if (num == 2) {
    document.getElementById('nav1_about').style.backgroundPosition = '0px -40px';
    document.getElementById('nav1_capabilities').style.backgroundPosition = '0px -20px';
    document.getElementById('nav1_contact').style.backgroundPosition = '0px -40px';
  }
  else if (num == 3) {
    document.getElementById('nav1_about').style.backgroundPosition = '0px -40px';
    document.getElementById('nav1_capabilities').style.backgroundPosition = '0px -40px';
    document.getElementById('nav1_contact').style.backgroundPosition = '0px -20px';
  }
}

// function to show the correct first level nav images when the mouse 'outs'
function deActivateOne() {
  document.getElementById('nav1_about').style.backgroundPosition = '0px 0px';
  document.getElementById('nav1_capabilities').style.backgroundPosition = '0px 0px';
  document.getElementById('nav1_contact').style.backgroundPosition = '0px 0px';
}

// function to show the second level hover menus
function showSecond(num) {
  if (pos1 != -1000) {
    hideSecondNow();
    nav2_tohide = num;
    document.getElementById('nav2_' + num + '_home_outer').style.display = '';
  }
}

// function to hide the second level hover menus with a small delay
function hideSecond() {
  if (pos1 != -1000) {
    t = setTimeout("hideSecondNow();deActivateOne();deActivateTwo();",350);
  }
}
// function that actually hides the second level hover menu
function hideSecondNow() {
  if (t) clearTimeout(t);
  document.getElementById('nav2_' + nav2_tohide + '_home_outer').style.display = 'none';
}

// function to show the correct second level nav images when the mouse 'hovers'
function activateTwo(num) {
  if (num == 1) document.getElementById('nav2_research').style.backgroundPosition = '0px -20px';
  else if (num != 1) document.getElementById('nav2_research').style.backgroundPosition = '0px -40px';

  if (num == 2) document.getElementById('nav2_design').style.backgroundPosition = '0px -20px';
  else if (num != 2) document.getElementById('nav2_design').style.backgroundPosition = '0px -40px';

  if (num == 3) document.getElementById('nav2_prototyping').style.backgroundPosition = '0px -20px';
  else if (num != 3) document.getElementById('nav2_prototyping').style.backgroundPosition = '0px -40px';

  if (num == 4) document.getElementById('nav2_development').style.backgroundPosition = '0px -20px';
  else if (num != 4) document.getElementById('nav2_development').style.backgroundPosition = '0px -40px';

  if (num == 5) document.getElementById('nav2_operations').style.backgroundPosition = '0px -20px';
  else if (num != 5) document.getElementById('nav2_operations').style.backgroundPosition = '0px -40px';
}

// function to show the correct second level nav images when the mouse 'outs'
function deActivateTwo() {
  document.getElementById('nav2_research').style.backgroundPosition = '0px 0px';
  document.getElementById('nav2_design').style.backgroundPosition = '0px 0px';
  document.getElementById('nav2_prototyping').style.backgroundPosition = '0px 0px';
  document.getElementById('nav2_development').style.backgroundPosition = '0px 0px';
  document.getElementById('nav2_operations').style.backgroundPosition = '0px 0px';
}

// function to create hover effect on the language options
var currCountry = '';
function languageHover(country) {
  if (country == 'en') document.getElementById('language').style.backgroundPosition = '0px -60px';
  else if (country == 'de') document.getElementById('language').style.backgroundPosition = '0px -120px';
  else if (country == 'fr') document.getElementById('language').style.backgroundPosition = '0px -180px';
  currCountry = country;
}

function languageOut() {
  if (currCountry != '') document.getElementById('language').style.backgroundPosition = '0px 0px';
}

