﻿// object constructor
function mainNavObj(section){
   this.sectionId = section;
   this.home = setHome(this);
   this.breadcrumb = false;
   this.highlightId = setHighlightId(this);
   this.highlightStyle = setHighlightStyle(this, false);
   this.overlayId = '';
   this.ptrActive = null;
   this.ptrSelected = null;
     
   this.menustateapplied = false;
   this.menustate = "";
   
   this.mainOnLoad = handleMainOnLoad;
   this.mainOnMouseOver = handleMainOnMouseOver;
   this.mainOnMouseOut = handleMainMouseOut;
   this.mainOnClick = handleMainClick;
   this.isMenustateCurrentSection = isMenustateCurrentSection;
}
//sectionId methods
function getSectionId(obj){
   return obj.sectionId;
}
//home methods
function getHome(obj){
   return obj.home;
}
function setHome(obj){
   if (obj.sectionId == 'home')
      return true;
   else
      return false;
}
//highlight id methods
function getHighlightId(obj){
   return obj.highlightId;
}
function setHighlightId(obj){
   if (!(getHome(obj))){
      return obj.sectionId + 'Nav';
   }
}
//highlight style methods
function getHighlightStyle(obj){
   return obj.highlightStyle;
}
function setHighlightStyle(obj, bool){
//if it's not the homepage
   if (bool)
      return obj.sectionId + 'Selected';
   else
      return obj.sectionId;
}

//overlayId methods
function setOverlayId(sectionId){
   return sectionId + 'NavOverlay';
}
//breadcrumb methods
function getBreadcrumb(obj){
   return obj.breadcrumb;
}
function setBreadcrumb(obj, bool){
   obj.breadcrumb = bool;
}
function getLang(){
   var lang = '';
   var currUrl = document.location + '';
   if (currUrl.indexOf('/en/') != -1)
      lang='en';
   else if (currUrl.indexOf('/fr/') != -1)
      lang='fr';
   else
      lang='en';
   return lang;
}

       //events//
function handleMainOnMouseOver(section){
   var lang = getLang();
   if( !(this.ptrActive) || this.ptrActive && this.ptrActive.sectionId.indexOf(section) == -1 ){
      var obj = new mainNavObj(section, false);
      
      //rollover
      if (document.images) {
         var tmpObj = document.getElementById(obj.sectionId);
     tmpObj.src = tmpObj.src.replace(/_blk\./, '_red.');
      }
      var obj = new mainNavObj(section, false);
      obj.highlightStyle = setHighlightStyle(obj, true);
      this.ptrSelected = obj;
   }
}
function handleMainMouseOut(section){
   var lang = getLang();
   if(this.ptrSelected && this.ptrSelected.sectionId.indexOf(section) != -1){
      if(this.sectionId.indexOf(section) == -1){
         var obj = this.ptrSelected;
         //rollover
         if (document.images) {
            var tmpObj = document.getElementById(obj.sectionId);
        tmpObj.src = tmpObj.src.replace(/_red\./, '_blk.');
         }
         obj.highlightStyle = setHighlightStyle(obj, false);
      }
      this.ptrSelected = null;
   }
}
//set highlight state
function handleMainOnLoad(){
   var lang = getLang();
   if (!getHome(this)){
      setBreadcrumb(this, true);
      this.highlightStyle = setHighlightStyle(this, true);
      //rollover
      if (document.images) {
         var tmpObj = document.getElementById(this.sectionId);
     tmpObj.src = tmpObj.src.replace(/_blk\./, '_red.');
      }
   }
}
function isMenustateCurrentSection(obj) {
    var returnstate = false;
    if (obj.menustate != null) {
        if (obj.menustate != "") {
            var elements = obj.menustate.split(",");
            if (obj.ptrActive)
            {
                  if ( obj.ptrActive.sectionId.indexOf(elements[0]) != -1 ) {
                      returnstate = true;
            }
            }
        }
    }
    return returnstate;
}
function getElementStyle( sectionName ) {
    var array = new Array("about", "lawyers", "transactions", "practice", "news", "publications", "students", "careers");
    var style = new Array("aboutNavBC", "lawyersNavBC", "transNavBC", "practiceNavBC", "newsNavBC", "pubNavBC", "studentsNavBC", "careersBC");
    var index = 0;
    for (var x = 0; x < array.length; x++) {
        if (array[x] == sectionName) {
            index = x;
            break;
        }
    }
    return style[index];
    return "black";
}
function applyMenustate(obj) {
    var elements = obj.menustate.split(",");
    if (elements.length > 1) {
        var elStyle = getElementStyle(elements[0]);
        for (var x = 1 ; x < elements.length; x++) {
            var e = document.getElementById(elements[x]);
            if (e != null) {
                switch (e.tagName) {
                    case "DIV": {
                        displayDiv(e);
                        break;
                    }
                    case "A": {
                        setClassName(e,elStyle);
                        break;
                    }
                    default: {
                    }
                }
            }
        }
        var e = document.getElementById( elements[ elements.length -1 ] );
        var anchors = getElements(e, "A");
        for (var x = 0; x < anchors.length; x++) {
            if ( document.location.href.indexOf( anchors[x].href ) != -1) {
                setClassName(anchors[x],elStyle);
            setStyle(anchors[x],"cursor","text")
            }
        }
    }
}
function handleMainClick(section, subNav){
   var lang = getLang();
   if (!(this.ptrActive) && (this.ptrSelected)){
      this.ptrActive = this.ptrSelected;
      this.ptrSelected = null;
      var objActive = this.ptrActive;
      objHtmlHighlight = document.getElementById(getHighlightId(objActive));
      objActive.highlightStyle = setHighlightStyle(objActive, true);
      objActive.overlayId = setOverlayId(objActive.sectionId);
      objHtml = document.getElementById(objActive.overlayId);
         if(section.indexOf('practice') == -1){
            setStyle(objHtml, 'display', 'block');
         }
   }
//ptrActive exists and it's sectionid doesn't match section,
   else if (this.ptrActive && this.ptrActive.sectionId.indexOf(section) == -1){
      if(this.sectionId.indexOf(this.ptrActive.sectionId) == -1){
         var objActive = this.ptrActive;
         objActive.overlayId = setOverlayId(objActive.sectionId);
         objHtml1 = document.getElementById(objActive.overlayId)
         setStyle(objHtml1, 'display', 'none');
         
         objHtml = document.getElementById(getHighlightId(objActive));
         objActive.highlightStyle = setHighlightStyle(objActive, false);
      //rollover
      if (document.images) {
         var tmpObj = document.getElementById(objActive.sectionId);
     tmpObj.src = tmpObj.src.replace(/_red\./, '_blk.');
      }
         this.ptrActive = this.ptrSelected;
         this.ptrSelected = null;
         this.ptrActive.overlayId = setOverlayId(this.ptrActive.sectionId);
         objHtml = document.getElementById(this.ptrActive.overlayId);
         if(section.indexOf('practice') == -1){
            setStyle(objHtml, 'display', 'block');
         }
      }
      else{
         var objTmp = this.ptrActive;
         objTmp.overlayId = setOverlayId(objTmp.sectionId);
         objHtml1 = document.getElementById(objTmp.overlayId)
         setStyle(objHtml1, 'display', 'none');
         
         this.ptrActive = this.ptrSelected;
         this.ptrSelected = null;
         var objActive = this.ptrActive;
         objHtml2 = document.getElementById(getHighlightId(objActive));
         objActive.highlightStyle = setHighlightStyle(objActive, true);
      //rollover
      if (document.images) {
         var tmpObj = document.getElementById(objActive.sectionId);
     tmpObj.src = tmpObj.src.replace(/_blk\./, '_red.');
      }
         
         this.ptrActive.overlayId = setOverlayId(this.ptrActive.sectionId);
         objHtml3 = document.getElementById(this.ptrActive.overlayId);
         setStyle(objHtml3, 'display', 'block');
      }
   }
   // ptr is active and section does match
   else if (this.ptrActive && this.ptrActive.sectionId.indexOf(section) != -1){
   
      // close block
      if (this.sectionId.indexOf(this.ptrActive.sectionId) == -1 ){
         
         var objActive = this.ptrActive;
         objActive.highlightStyle = setHighlightStyle(objActive, false);
         
         //rollover
         if (document.images) {
            var tmpObj = document.getElementById(objActive.sectionId);
        tmpObj.src = tmpObj.src.replace(/_red\./, '_blk.');    
         }
      }
      this.ptrSelected = this.ptrActive;
      this.ptrActive = null;
      this.ptrSelected.overlayId = setOverlayId(this.ptrSelected.sectionId);
      objHtml = document.getElementById(this.ptrSelected.overlayId);
      setStyle(objHtml, 'display', 'none');
   }
   
   // apply menu state
   if (!(this.menustateapplied) && isMenustateCurrentSection(this) ) {
        this.menustateapplied = true;
        applyMenustate(this);
   } 
   if (!(this.ptrActive)){
      hideSubnavs();
      this.menustateapplied = false;
   }
}
// Rollover  v2.0
// documentation: http://www.dithered.com/javascript/rollover/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)

function isDefined(property) {
  return (typeof property != 'undefined');
}
var rolloverInitialized = false;
function rolloverInit() {
   if (!rolloverInitialized && isDefined(document.images)) {
      
      // get all images (including all <input type="image">s)
      // use getElementsByTagName() if supported
      var images = new Array();
      if (isDefined(document.getElementsByTagName)) {
         images = document.getElementsByTagName('img');
         var inputs = document.getElementsByTagName('input');
         for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == 'image') {
               images[images.length] = inputs[i];
            }
         }
      }
      
      // otherwise, use document.images and document.forms collections
      // remove if not supporting IE4, Opera 4-5
      else {
         images = document.images;
         inputs = new Array();
         for (var formIndex = 0; formIndex < document.forms.length; formIndex++) {
            for (var elementIndex = 0; elementIndex < document.forms.elements.length; elementIndex++) {
               if (isDefined(document.forms.elements[i].src)) {
                  inputs[inputs.length] = document.forms.elements[i];
               }
            }
         }
      }
      
      // get all images with '_off.' in src value
      for (var i = 0; i < images.length; i++) {
         if (images[i].src.indexOf('_off.') != -1) {
            var image = images[i];
            
            // store the off state filename in a property of the image object
            image.offImage = new Image();
            image.offImage.src = image.src;
            
            // store the on state filename in a property of the image object
            // (also preloads the on state image)
            image.onImage = new Image();
            image.onImage.imageElement = image;
            
            // add onmouseover and onmouseout event handlers once the on state image has loaded
            // can't use image.onImage.onload to attach event handlers in Safari - this==document instead of image
            if (navigator.userAgent.toLowerCase().indexOf('safari') != -1) {
               image.onmouseover = function() {
                  this.src = this.onImage.src;
               };
               image.onmouseout = function() {
                  this.src = this.offImage.src;
               };
            }
            else {
               image.onImage.onload = function() {
                  this.imageElement.onmouseover = function() {
                     this.src = this.onImage.src;
                  };
                  this.imageElement.onmouseout = function() {
                     this.src = this.offImage.src;
                  };
               };
            }
            
            // set src after defining onload event handler so onload while fire if _on image is cached
            image.onImage.src = image.src.replace(/_off\./, '_on.');
         }
      }
   }
   rolloverInitialized = true;
}
// call rolloverInit when document finishes loading
if (isDefined(window.addEventListener)) {
   window.addEventListener('load', rolloverInit, false);
}
else if (isDefined(window.attachEvent)) {
   window.attachEvent('onload', rolloverInit);
}