function setup(authenticated) {
  /* Fixes for IE */
  if (false == jQuery.support.boxModel) {
    $(".auth_input").css("height", "15px");
    $(".search_input").css("height", "15px");
  }
}

var openSubMenu = new Number(-1);

function resetMenus(parentCategoryID) {
  var objArray = new Array();
  objArray[1] = 'div_nav_admin';
  objArray[2] = 'div_nav_home';
  objArray[3] = 'div_nav_about_us';
  objArray[4] = 'div_nav_products';
  objArray[5] = 'div_nav_industries';
  objArray[6] = 'div_nav_services';
  objArray[7] = 'div_nav_locations';
  objArray[8] = 'div_nav_news';
  objArray[9] = 'div_nav_downloads';
  objArray[10] = 'div_nav_links';
  objArray[11] = 'td_online_shop';
  for (var i=1; i < objArray.length; i++) {
    if (parentCategoryID != i) {
      hideMenu(i, objArray[i]);
    }
  }
}

function isHidden(obj) {
  var count = new Number(0);
  $('#'+obj+':hidden').each(function(){
    count++;
  });
  return count;
}

function showSubMenu(categoryID) {
  if (isHidden('sub_menu_three_'+categoryID) == 0) {
    return;
  }
  hideAllSubMenus();
  var pos = $('#place_'+categoryID).position();
  if ($G.isIE()) {
    var top = pos.top - 3;
  } else if ($.browser.safari) {
    var top = pos.top - 4;  
  } else {
    var top = pos.top - 14;
  }
  var left = pos.left + 160;
  $('#sub_menu_three_'+categoryID).css('top', top+'px');
  $('#sub_menu_three_'+categoryID).css('left', left+'px');
  $('#sub_menu_three_'+categoryID).show();
}

function hideSubMenu(categoryID) {
  $('#div_sub_nav_'+categoryID).hide();
}

function hideAllSubMenus() {
  $('.div_nav_three').hide();
}

function hideAllMenus() {
  $('.div_sub_nav').each(function(){
    $(this).hide();
  });
}

function resetAllMenus(parentCategoryID) {
  resetMenus(parentCategoryID);
  hideAllMenus();
  hideAllSubMenus();
}

function showMenu(parentCategoryID, parentObj, overClass) {
  resetAllMenus(parentCategoryID);
  if (undefined == overClass) {
    overClass = 'top_nav_hover';
  }
  adjustWidthStyle(parentObj, overClass);
  var pos = $('#'+parentObj).position();
  var top = pos.top + 27;
  $('#div_sub_nav_'+parentCategoryID).css('top',top);
  $('#div_sub_nav_'+parentCategoryID).css('left',pos.left); 
  $('#div_sub_nav_'+parentCategoryID).show();
  $('#sub_nav_footer_'+parentCategoryID).show();
  $('#div_sub_nav_'+parentCategoryID).hover(
    function(){
      $('#'+parentObj+' a').css('color', '#414142');
    },
    function(){
      if (parentObj != 'td_online_shop') {
        $('#'+parentObj+' a').css('color', '#ffffff');
      }
      hideMenu(parentCategoryID, parentObj);
      hideAllSubMenus();
    }
  );
}

function hideMenu(parentCategoryID, parentObj) {
  hideAllSubMenus();
  adjustWidthStyleRemove(parentObj, 'top_nav_hover');
  $('#div_sub_nav_'+parentCategoryID).hide();
}

function adjustWidthStyle(id, className) {
  try {
    var width = new Number($('#'+id+'_width').val());
    $('#'+id).css('width', (width - 2) + 'px');
    $('#'+id).addClass(className); 
  } catch (e) { 
    // 
  }
}

function adjustWidthStyleRemove(id, className) {
  try {
    var str = $('#'+id).css('width');
    var width = new Number($('#'+id+'_width').val());
    $('#'+id).css('width', (width) + 'px');
    $('#'+id).removeClass(className); 
  } catch (e) { 
    // 
  }
}

