﻿var opera = (navigator.appName.indexOf("Opera") != -1) ? true : false;
var firefox = navigator.userAgent.toLowerCase();
    firefox = (firefox.indexOf("firefox") != -1) ? true : false;
var safari = navigator.userAgent.toLowerCase();
    safari = ((safari.indexOf("safari") != -1) && (safari.indexOf("chrome") == -1)) ? true : false;
var chrome = navigator.userAgent.toLowerCase();
    chrome = (chrome.indexOf('chrome') != -1) ? true : false;
var msie_only = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
var msie_old = false; // MSIE versions older than 7
var msie_80 = false; // MSIE version 8.0 or newer
var msie_70 = false; // MSIE version 7.0
var msie_60 = false; // only MSIE 6.0
var msie_55 = false; // only MSIE 5.5

if (msie_only) {
  fullVerStr = navigator.appVersion;
  verStr = fullVerStr.substring(fullVerStr.indexOf('MSIE') + 4, fullVerStr.length);
  verStr = verStr.substring(0, verStr.indexOf(';'));
  msie_old = (parseFloat(verStr) < 7.0) ? true : false;
  msie_80 = (parseFloat(verStr) >= 8.0) ? true : false;
  msie_70 = (parseFloat(verStr) == 7.0) ? true : false;
  msie_60 = (parseFloat(verStr) == 6.0) ? true : false;
  msie_55 = (parseFloat(verStr) == 5.5) ? true : false;
}

document.writeln('<style type="text/css">\n/*<![CDATA[*/\n');
if (msie_80) {
  document.writeln('.Radio {}\n');
  document.writeln('.Radio input {}\n');
  document.writeln('.CheckBox {}\n');
  document.writeln('.CheckBox input {}\n');
  document.writeln('.RbVerticalList {}\n');
  document.writeln('.RbVerticalList input {position:relative; margin-bottom:6px; top:4px}\n');
  document.writeln('.RbVerticalList label {top:1px;}\n');
  document.writeln('.CbVerticalList {left:-6px; top:-2px;}\n');
  document.writeln('.CbVerticalList input {position:relative; top:3px}\n');
  document.writeln('.AccessCBList label {top:-2px;}\n');
  document.writeln('.PublicFormTable .TextArea {width:233px;}\n');
}
if (msie_70) {
  document.writeln('.Radio {left:-4px;}\n');
  document.writeln('.Radio input {margin-bottom:0px; margin-right:0px;}\n');
  document.writeln('.CheckBox {left:-4px;}\n');
  document.writeln('.CheckBox input {margin-bottom:0px; margin-right:0px;}\n');
  document.writeln('.RbVerticalList {left:-5px;}\n');
  document.writeln('.RbVerticalList input {position:relative; top:2px}\n');
  document.writeln('.RbVerticalList label {top:1px;}\n');
  document.writeln('.CbVerticalList {left:-6px; top:-2px;}\n');
  document.writeln('.CbVerticalList input {position:relative; top:3px}\n');
  document.writeln('.AccessCBList label {top:-2px;}\n');
  document.writeln('.RightBox .DropDown {height:21px;}\n');
  document.writeln('.PublicFormTable .TextArea {width:233px;}\n');
}
if (msie_old) {
  document.writeln('.Radio {left:-4px;}\n');
  document.writeln('.Radio input {margin-bottom:0px; margin-right:0px;}\n');
  document.writeln('.CheckBox {left:-4px;}\n');
  document.writeln('.CheckBox input {margin-bottom:0px; margin-right:0px;}\n');
  document.writeln('.CbVerticalList {left:-6px; top:-2px;}\n');
  document.writeln('.RbHorizontalList input {left:-7px; top:3px}\n');
  document.writeln('.RbHorizontalList label {left:-7px;}\n');
  document.writeln('.RbVerticalList {left:-5px;}\n');
  document.writeln('.RbVerticalList label {top:-1px;}\n');
  document.writeln('.RbVerticalList input {}\n');
  document.writeln('.MainDiv .ContentTopWide .ContentTop .Column1         {height:300px;}\n');
  document.writeln('.MainDiv .ContentTopWide .ContentTop .Column1Narrower {height:300px;}\n');
  document.writeln('.MainDiv .ContentTopWide .ContentTop .Column2         {height:300px;}\n');
  document.writeln('.MainDiv .ContentBottomWide .ContentBottom {height:90px;}\n');
  document.writeln('.MainDiv .ContentBottomWide .ContentBottom .Column1 {height:90px;}\n');
  document.writeln('.MainDiv .ContentBottomWide .ContentBottom .Column2 {height:90px;}\n');
  document.writeln('.MainDiv .ContentBottomWide .ContentBottom .Column3 {height:90px;}\n');
  document.writeln('.MainDiv .ContentBottomWide .ContentBottom .Column4 {height:90px;}\n');
  document.writeln('.GlobalNavInner .Inactive .Centre  {height:14px; padding:5px 4px 5px 4px;}\n');
  document.writeln('.Content .LeftColumn {height:400px;}\n');
  document.writeln('.AccessCBList label {top:-2px; left:-2px; margin-right:12px;}\n');
  document.writeln('.BottomHeading {height:25px;}\n');
  document.writeln('.BottomHeadingLink {height:25px;}\n');
  document.writeln('.PublicFormTable .TextArea {width:233px;}\n');
  document.writeln('.TwoColumnContentLayoutTable td.ColRight .MinHeight1 {min-height:400px;}\n');
}
if (opera) {
  document.writeln('.Radio {}\n');
  document.writeln('.Radio input {}\n');
  document.writeln('.CheckBox {}\n');
  document.writeln('.CheckBox input {}\n');
  document.writeln('.RbHorizontalList input {}\n');
  document.writeln('.RbHorizontalList label {top:0px;}\n');
  document.writeln('.RbVerticalList {}\n');
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:2px;}\n');
  document.writeln('.CbVerticalList {left:-1px;}\n');
  document.writeln('.CbVerticalList input {margin-top:2px; margin-bottom:3px;}\n');
  document.writeln('.AccessCBList label {top:1px;}\n');
  document.writeln('.PublicFormTable .TextArea {width:232px;}\n');
}
if (firefox) {
  document.writeln('.Radio {}\n');
  document.writeln('.Radio input {}\n');
  document.writeln('.CheckBox {}\n');
  document.writeln('.CheckBox input {}\n');
  document.writeln('.RbHorizontalList label {top:-3px;}\n');
  document.writeln('.RbVerticalList {left:-1px;}\n');
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.RbVerticalList label {position:relative; top:-3px; margin-left:6px;}\n');
  document.writeln('.CbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.CbVerticalList label {position:relative; top:-3px; margin-left:6px;}\n');
  document.writeln('.AccessCBList label {top:-2px;}\n');
}
if (safari) {
  document.writeln('.Radio {}\n');
  document.writeln('.Radio input {}\n');
  document.writeln('.CheckBox {}\n');
  document.writeln('.CheckBox input {}\n');
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.RbVerticalList label {top:-3px; margin-left:7px;}\n');
  document.writeln('.CbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.CbVerticalList label {margin-left:7px;}\n');
  document.writeln('.AccessCBList label {top:-2px;}\n');
  document.writeln('.FormTable .DropDown  {line-height:17px;}\n');
  document.writeln('.RightBox .DropDown {height:23px;}\n');
  document.writeln('.PublicFormTable .TextArea {width:236px;}\n');
}
if (chrome) {
  document.writeln('.Radio {}\n');
  document.writeln('.Radio input {}\n');
  document.writeln('.CheckBox {}\n');
  document.writeln('.CheckBox input {}\n');
  document.writeln('.RbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.RbVerticalList label {top:-2px; margin-left:5px;}\n');
  document.writeln('.CbVerticalList input {margin-top:4px; margin-bottom:3px;}\n');
  document.writeln('.CbVerticalList label {position:relative; top:-2px; margin-left:7px;}\n');
  document.writeln('.AccessCBList label {top:-3px;}\n');
  document.writeln('.PublicFormTable .TextArea {width:232px;}\n');
}
document.writeln('.ValidationComplianceTag {display:none;}\n');
document.writeln('/*]]>*/\n</style>\n');

//Limits length of text in textarea "element" (dom reference), writes information in "info" (id), counts characters
function checkLength(element, info, max_length) {
  var actual_length = element.value.length;
  var characters_left = max_length - actual_length;
  if (characters_left < 0) characters_left = 0;

  if (actual_length == 0) {
    document.getElementById(info).innerHTML = "Maximum text length is " + max_length + " characters.";
  }
  if ((actual_length > 0) && (actual_length <= max_length)) {
    document.getElementById(info).innerHTML = "You may enter " + characters_left + " more characters.";
  }
  if (actual_length > max_length) {
    element.value = element.value.substr(0, max_length);
    document.getElementById(info).innerHTML = "You may enter " + characters_left + " more characters.";
  }
}

//init a textarea, textarea_container - id, for charaacters limit
function initLengthInfo(textarea_container, info_id, max_length) {
  if (document.getElementById(textarea_container)) {
    element_ref = document.getElementById(textarea_container).getElementsByTagName("textarea")[0];
    checkLength(element_ref, info_id, max_length);
  }
}

//trims only spaces from the end of a string
function trim(text) {
  while (text.charAt(text.length - 1) == " ") {
    text = text.substr(0, (text.length - 1));
  }
  return (text);
}

//Returns value stored in cookie with given id, or -1 if cookie didn't exist (or is expired), multi value cookies safe.
function toCookie(cookie_id, value) {
  var exp = new Date();
  exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 365));
  var cookie_name = "HarrisHill" + cookie_id + "=" + value;
  var cookie_expires = "expires=" + exp.toGMTString();
  document.cookie = cookie_name + ";" + cookie_expires + "; path=/";
}

//Returns value stored in cookie with given id, or -1 if cookie didn't exist (or is expired), multi value cookies resistant.
function fromCookie(cookie_id) {
  var labelName = "HarrisHill" + cookie_id;
  var labelLen = labelName.length;
  var cookieData = document.cookie;
  var cLen = cookieData.length;
  var i = 0;
  var cEnd;
  while (i < cLen) {
    var j = i + labelLen;
    if (cookieData.substring(i, j) == labelName) {
      cEnd = cookieData.indexOf(";", j);
      if (cEnd == -1) {
        cEnd = cookieData.length;
      }
      return unescape(cookieData.substring(j + 1, cEnd));
    }
    i++;
  }
  return "-1";
}

function getYear() {
  var d = new Date();
  document.getElementById('GetYear').innerHTML = d.getFullYear();
}

// hide 0 or one element and show another element, indicated by id
// css width property is required for every switchable element. Can be in pixels or percents
function hideShow(id_hide, id_show, type) {
  switch (type) {
    case 'fade':
      if (id_hide == "-") {//only show, but wait to synchronize with other elements
        window.setTimeout("$('#" + id_show + "').fadeIn(400);",450);
      } else {
        $('#' + id_hide).fadeOut(200, function(){
          $('#' + id_show).fadeIn(400);
        });
      }
    break;
    case 'slide':
      if (id_hide == "-") {
        window.setTimeout("$('#" + id_show + "').slideDown(400);",450);
      } else {
        $('#' + id_hide).slideUp(200, function(){
          $('#' + id_show).slideDown(400);
        });
      }
    break;
    case 'blink':
      $('#' + id_hide).hide();
      $('#' + id_show).show();
    break;
  }
}

//show single element with given id
function show(id_show, type) {
  switch (type) {
    case 'fade':
      $('#' + id_show).fadeIn(400);
    break;
    case 'slide':
      $('#' + id_show).slideDown(400);
    break;
    case 'blink':
      $('#' + id_show).show();
    break;
  }
}

//hide single element with given id
function hide(id_hide, type) {
  switch (type) {
    case 'fade':
      $('#' + id_hide).fadeOut(200);
    break;
    case 'slide':
      $('#' + id_hide).slideUp(200);
    break;
    case 'blink':
      $('#' + id_hide).hide();
    break;
  }
}

// hide 0 or more elements and show 0 or more oter elements, indicated by id
// css width property is required for every switchable element. Can be in pixels or percents
// use example1: hideShowList(["id1","id2","id3"],["id6"],"blink");
// use example2: hideShowList(["-"],["id6","id7","id8"],"fade");
function hideShowList(hide_array, show_array, type) {
  if (hide_array[0] != '-') {
    for(var i=0; i<hide_array.length; i++) {
      hide(hide_array[i], type);
    }
  }
  
  if (show_array[0] != '-') {
    for(var i=0; i<show_array.length; i++) {
      show(show_array[i], type);
    }
  }
}

//information box on validation image rollover - old validation mechanism, update with JQ
function validationInfo(operation, img_ref){
  if(operation == "show") {
    if (img_ref.alt.length > 0) img_ref.previousSibling.innerHTML = img_ref.alt;
    img_ref.alt = "";
    img_ref.previousSibling.style.display = "block";
  }
  if(operation == "hide") img_ref.previousSibling.style.display = "none";
}

//for search panel
function clearSearchField(field_to_clear) {
  var tmp_obj = field_to_clear.previousSibling;
  tmp_obj = tmp_obj.previousSibling;
  var initial_value = tmp_obj.value;
  if (initial_value == field_to_clear.value) field_to_clear.value = "";
}

//for search panel
function fillSearchField(field_to_fill) {
  var tmp_obj = field_to_fill.previousSibling;
  tmp_obj = tmp_obj.previousSibling;
  var initial_value = tmp_obj.value;
  if (field_to_fill.value == "") field_to_fill.value = initial_value;
}

/* begin ADMIN access page */
function selectAllAccessItem(button_ref) {
  $(button_ref).parent().parent().find("input").attr("checked", "checked");
  return false;
}

function deselectAllAccessItem(button_ref) {
  $(button_ref).parent().parent().find("input").removeAttr("checked");
  return false;
}

function selectAllAccessGlobal() {
  $("#ForJSAllCheckboxesInside").find("input").attr("checked", "checked");
  return false;
}

function deselectAllAccessGlobal() {
  $("#ForJSAllCheckboxesInside").find("input").removeAttr("checked");
  return false;
}
/* end ADMIN access page */


//initial example value in a form field; disappears on focus, appears back on blur if is empty
function clearField (field_to_clear, initial_value) {
  if (initial_value==field_to_clear.value) field_to_clear.value="";
} 
function fillField (field_to_clear, initial_value) {
  if (field_to_clear.value=="") field_to_clear.value=initial_value;
}


function htmlEncode(s) {
  var str = new String(s);
  str = str.replace(/&/g, "&amp;");
  str = str.replace(/</g, "&lt;");
  str = str.replace(/>/g, "&gt;");
  str = str.replace(/"/g, "&quot;");
  return str;
}

function openWysiwyg(html_source_id, html_destination_id, editor_width, editor_height, popup_left, popup_top, style_filename, content_type) {
  //content_type = "email" for emails and "page" for page contents editing
  editor_width = parseInt(editor_width) + 18; //18px for editor scrollbars
  var popup_width = parseInt(editor_width) + 20;
  var popup_height = parseInt(editor_height) + 50;

  var dynamic_url = "http://" + document.domain;
  if (document.URL.indexOf(":81/") > -1) dynamic_url += ":81";
  if (document.URL.indexOf("localhost") > -1) dynamic_url = "http://harrishill.obs-group.co.uk:81"

  var email_prefix = (content_type == "email") ? "email-" : "";

  var ww = window.open("", "EditorWindow", "resizable=no,width=" + popup_width + ",height= " + popup_height + ",top=" + popup_top + ",left= " + popup_left);

  ww.document.open();
  ww.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>\n<title>WYSIWYG content editor</title>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n</head>\n<body>');
  ww.document.writeln('<div style="margin-left:auto; margin-right:auto; width:' + editor_width + 'px;">');
  ww.document.writeln('<object type="application/x-xstandard" id="editor1" width="' + editor_width + '" height="' + editor_height + '">');
  ww.document.writeln('<param name="Value" value="' + htmlEncode(document.getElementById(html_source_id).value) + '" />');

  ww.document.writeln('<param name="ImageLibraryURL"      value="' + dynamic_url + '/xstandard/' + email_prefix + 'imagelibrary.aspx" />');
  ww.document.writeln('<param name="AttachmentLibraryURL" value="' + dynamic_url + '/xstandard/' + email_prefix + 'attachmentlibrary.aspx" />');
  ww.document.writeln('<param name="LinkLibraryURL"       value="' + dynamic_url + '/xstandard/linklibrary.aspx" />');
  //ww.document.writeln('<param name="SpellCheckerURL"      value="' + dynamic_url + '/xstandard/spellchecker.aspx" />'); //http://soap.xstandard.com/spellchecker.aspx for test
  ww.document.writeln('<param name="Styles"               value="' + dynamic_url + '/xstandard/' + email_prefix + 'editor-styles.xml" />');
  ww.document.writeln('<param name="License"              value="' + dynamic_url + '/xstandard/license.txt" />');
  ww.document.writeln('<param name="CSS"                  value="' + dynamic_url + '/xstandard/' + email_prefix + style_filename + '" />');

 //ww.document.writeln('<param name="SpellCheckerLangFilter" value="en-gb, en-us" />');
  ww.document.writeln('<param name="SpellCheckerLang" value="en-us" />');
  ww.document.writeln('<param name="ProxySetting" value="direct" />'); //if default proxy settings stop it from working
  ww.document.writeln('<param name="EnableTimestamp" value="no" />'); //the comment inserted at the begining of html
  ww.document.writeln('<param name="EnablePasteMarkup" value="no" />'); //copying from word with formating retained - doesn't work good enough
  ww.document.writeln('<param name="Lang" value="en" />');
  ww.document.writeln('<param name="Dir" value="ltr" />');
  ww.document.writeln('<param name="Debug" value="no" />');
  ww.document.writeln('<param name="IndentOutput" value="Yes" />');
  ww.document.writeln('<param name="Options" value="2136" />');  //wrap text in source view, hide line numbers, make images decorative by default, make divs don't disappear during edition.
  ww.document.writeln('<param name="ClassImageFloatLeft"  value="LeftImage" />');
  ww.document.writeln('<param name="ClassImageFloatRight" value="RightImage" />');
  ww.document.writeln('<param name="ToolbarWysiwyg" value="ordered-list, unordered-list, definition-list, draw-layout-table, separator, image, hyperlink, attachment, source, preview, help" />'); // spellchecker,
  ww.document.writeln('<param name="ToolbarPreview" value="wysiwyg, source, preview" />');
  ww.document.writeln('<param name="ToolbarSource" value="word-wrap, validate, wysiwyg, source, preview" />');
  ww.document.writeln('<param name="ShowStyles" value="yes" />'); //styles ddlist in the editor
  ww.document.writeln('<param name="Base" value="' + dynamic_url + '/cms-uploaded/" />'); //URL used to resolve relative URLs for images defined in markup.
  ww.document.writeln('</object>');

  ww.document.writeln('<div>\n<span style="float:right; height:16px; display:block; margin-top:10px; background-color:#003366;"><a style="font-weight:bold; font-size:10px; font-family:Verdana; text-decoration:none; color:#fff; padding:1px 8px 2px 8px; display:block;" href="javascript:self.opener.document.getElementById(\'' + html_destination_id + '\').value=document.getElementById(\'editor1\').value; self.close();" title="Update the page form and close the editor">Close</a></span>\n</div>');
  ww.document.writeln('</body>\n</html>');
  ww.document.close();
}

/* Function creates 2 row table from simplier repeater based table. Table should be hidden initially */
function makeTwoColumns(table_id) {
  var table_ref = document.getElementById(table_id);
  
  for (var i=1; i<table_ref.getElementsByTagName("tr").length; i++) { // 1 starts from second row
    table_ref.getElementsByTagName("tr")[i-1].getElementsByTagName("td")[1].innerHTML = table_ref.getElementsByTagName("tr")[i].getElementsByTagName("td")[0].innerHTML;
  }
  
  $(table_ref).find("tr:odd").remove();
  
  table_ref.style.display = "";
}

/* a standard popup window */
function openPopup(url) {
  var win_handle = window.open(url, 'PopUpWindow', 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=690,height=640,top=100,left=150');
  win_handle.focus();
}


/******* 3 lavel nav functions ********/
var job_search_img_ref; // <- overlay image for IE6 select item always on the top issue

var level2_timeout_id;
var level3_timeout_id;
var level1_highlight_timeout_id;
var level2_highlight_timeout_id;
var level3_highlight_timeout_id;

function menuHighlight(element) {
  var parent_li_class_name = $(element).parent().attr("class");
  
  if (parent_li_class_name.indexOf("Level1") != -1)  $(element).parent().addClass("Level1Highlighted");
  if (parent_li_class_name.indexOf("Level2") != -1)  $(element).parent().addClass("Level2Highlighted");
  if (parent_li_class_name.indexOf("Level3") != -1)  $(element).parent().addClass("Level3Highlighted");
  
  if ((msie_old) && (parent_li_class_name.indexOf("Level1") != -1) && (job_search_img_ref != null)) { //IE6 only correction
    job_search_img_ref.style.display = "block";
    $("#ForJsJobSearchSelectsInside select").css("visibility","hidden");
  }
}

function showChildAnimated(element_ref) {  //element_ref - link reference
  if ($(element_ref).attr("class") == "Level2") { //different animation for level 2 and 3 expand
    $(element_ref).parent().children("ul").show(200);
  } else {
    $(element_ref).parent().children("ul").slideDown(200);
  }

  if ((msie_old) && ($(element_ref).next("ul").length > 0)) $(element_ref).parent().addClass("IE6Correction");  //correct IE6 issue
}

function hideAllHighlightLevel1Now() {
  $("#NavContainer li.Level1").removeClass("Level1Highlighted");
  
  if ((msie_old) && (job_search_img_ref != null)) { //IE6 only correction
    job_search_img_ref.style.display = "none";
    $("#ForJsJobSearchSelectsInside select").css("visibility","visible");
  }
}

function hideAllHighlightLevel2Now() {
  $("#NavContainer li.Level2").removeClass("Level2Highlighted"); 
}

function hideAllHighlightLevel3Now() {
  $("#NavContainer li.Level3").removeClass("Level3Highlighted"); 
}

function hideAllChildrenLevel2Now() {
  $("#NavContainer ul.Level2").stop(true,true).hide(0);
}

function hideAllChildrenLevel3Now() {
  $("#NavContainer ul.Level3").stop(true,true).hide(0);
  if (msie_old) $("#NavContainer li.Level2").removeClass("IE6Correction"); //remove IE6 issue correction
}

function hideAllHighlightLevel1Delayed(link_ref) {
  if (($(link_ref).next("ul").length == 0) && ($(link_ref).attr("class") == "Level1")) hideAllHighlightLevel1Now(); //if no children in Level1 option
  level1_highlight_timeout_id = window.setTimeout("hideAllHighlightLevel1Now()",500); 
}
  
function hideAllHighlightLevel2Delayed(link_ref) {
  level2_highlight_timeout_id = window.setTimeout("hideAllHighlightLevel2Now()",500); 
}

function hideAllHighlightLevel3Delayed(link_ref) {
  level3_highlight_timeout_id = window.setTimeout("hideAllHighlightLevel3Now()",500); 
}

function hideAllChildrenLevel2Delayed(link_ref) {
  level2_timeout_id = window.setTimeout("hideAllChildrenLevel2Now()",500); 
}

function hideAllChildrenLevel3Delayed(link_ref) {
  level3_timeout_id = window.setTimeout("hideAllChildrenLevel3Now()",500); 
}

function level1Over(link_ref) {
  window.clearTimeout(level1_highlight_timeout_id);
  window.clearTimeout(level2_highlight_timeout_id);
  window.clearTimeout(level2_timeout_id);
  window.clearTimeout(level3_timeout_id);
  hideAllHighlightLevel1Now();
  hideAllHighlightLevel2Now();
  hideAllHighlightLevel3Now();
  hideAllChildrenLevel2Now();
  hideAllChildrenLevel3Now();
  menuHighlight(link_ref); //Level1 highlight on
  showChildAnimated(link_ref);
}

function level1Out(link_ref) {
  hideAllHighlightLevel1Delayed(link_ref);
  hideAllChildrenLevel2Delayed(link_ref);
}

function level2Over(link_ref) {
  window.clearTimeout(level1_highlight_timeout_id);
  window.clearTimeout(level2_highlight_timeout_id);
  window.clearTimeout(level3_highlight_timeout_id);
  window.clearTimeout(level2_timeout_id);
  window.clearTimeout(level3_timeout_id);
  hideAllHighlightLevel2Now(); 
  hideAllHighlightLevel3Now();
  hideAllChildrenLevel3Now();
  menuHighlight($(link_ref).parent().parent()); // Level1 highlight on (parent option)
  menuHighlight(link_ref);  // Level2 highlight on
  showChildAnimated(link_ref); //start of level 3 functions
}

function level2Out(link_ref) {
  hideAllHighlightLevel1Delayed(link_ref);
  hideAllHighlightLevel2Delayed(link_ref);
  hideAllChildrenLevel2Delayed(link_ref);
  hideAllChildrenLevel3Delayed(link_ref);
}

function level3Over(link_ref) {
  window.clearTimeout(level1_highlight_timeout_id);
  window.clearTimeout(level2_highlight_timeout_id);
  window.clearTimeout(level3_highlight_timeout_id);
  window.clearTimeout(level2_timeout_id);
  window.clearTimeout(level3_timeout_id);
  hideAllHighlightLevel3Now();
  menuHighlight($(link_ref).parent().parent().parent().parent()); // Level1 highlight on (parent parent option)
  menuHighlight($(link_ref).parent().parent()); // Level2 highlight on (parent option)
  menuHighlight(link_ref); //Level3 highlight on 
}

function level3Out(link_ref) {
  hideAllHighlightLevel1Delayed(link_ref);
  hideAllHighlightLevel2Delayed(link_ref);
  hideAllHighlightLevel3Delayed(link_ref);
  hideAllChildrenLevel2Delayed(link_ref);
  hideAllChildrenLevel3Delayed(link_ref);
}

var image_preload = new Image();
image_preload.src = "/Images/Default/nav-level1-bg.gif";

/******* end 3 lavel nav functions ********/

$(document).ready(function(){

  //3 level top navigation - on_DOM_ready functionality
  job_search_img_ref = window.document.getElementById("ForJsJobSearchOverlayImg");
  
  if (document.getElementById("NavContainer")) {
    $("#NavContainer > ul").addClass("Level1");
    $("#NavContainer > ul.Level1 > li").addClass("Level1");
    $("#NavContainer > ul.Level1 > li.Level1 > a").addClass("Level1");
     
    $("#NavContainer ul.Level1 > li.Level1 > ul").addClass("Level2");
    $("#NavContainer ul.Level1 > li.Level1 > ul.Level2 > li").addClass("Level2");
    $("#NavContainer ul.Level1 > li.Level1 > ul.Level2 > li.Level2 > a").addClass("Level2");

    $("#NavContainer ul.Level2 > li.Level2 > ul").addClass("Level3");
    $("#NavContainer ul.Level2 > li.Level2 > ul.Level3 > li").addClass("Level3");
    $("#NavContainer ul.Level2 > li.Level2 > ul.Level3 > li.Level3 > a").addClass("Level3");
    
    $("#NavContainer li.Level1 > a").bind("mouseover", function() {level1Over(this);});
    $("#NavContainer li.Level1 > a").bind("mouseout",  function() {level1Out(this);});
    
    $("#NavContainer li.Level2 > a").bind("mouseover", function() {level2Over(this);});
    $("#NavContainer li.Level2 > a").bind("mouseout",  function() {level2Out(this);});
    
    $("#NavContainer li.Level3 > a").bind("mouseover", function() {level3Over(this);});
    $("#NavContainer li.Level3 > a").bind("mouseout",  function() {level3Out(this);});
    
    $("#NavContainer a").attr("title","");
    $("#NavContainer").css("display","block");
 }
}); //ready


