﻿var theOldElement;
function togglePopup(theElement) {
    var allBios = theElement.parentNode.parentNode.parentNode.getElementsByTagName("div");
    var theElementsPopUp = theElement.parentNode.parentNode.nextSibling;
    for (inc = 0; inc < allBios.length; inc++) {
        if (allBios[inc].className == "Attorney_Popup" && allBios[inc] != theElementsPopUp) {
            allBios[inc].style.display = "none";
        } else if (allBios[inc].className == "Attorney_Popup" && allBios[inc] == theElementsPopUp) {
            theElementsPopUp.style.display = theElementsPopUp.style.display == "none" ? "" : "none";
        }
    }
    if (theOldElement) {
        theOldElement.onclick = "togglePopup(this);";
    }
    theOldElement = theElement;
}

function toggleArticles(theElement) {
    var theHiddenSibling = theElement.parentNode.parentNode.getElementsByTagName("div")[1];
    if (theHiddenSibling.tagName.toLowerCase() == "div") {
        if (theHiddenSibling.className == "hiddenArticles") {
            theHiddenSibling.className = "";
            theElement.className = "open";
        } else {
            theHiddenSibling.className = "hiddenArticles";
            theElement.className = "";
        }
    }
    theElement.blur();
}

function toggleService(theElement) {
    var theServiceDescriptors = theElement.parentNode.parentNode.getElementsByTagName('div');
    var theElementDescriptor = theElement.parentNode.nextSibling;
    for (inc = 0; inc < theServiceDescriptors.length; inc++) {
        if (theServiceDescriptors[inc].className == "hiddenService") {
            if (theServiceDescriptors[inc] != theElementDescriptor) {
                theServiceDescriptors[inc].style.display = "none";
            } else if (theServiceDescriptors[inc] == theElementDescriptor) {
                theElementDescriptor.style.display = theElementDescriptor.style.display == "block" ? "none" : "block";
            }
        }
    }
}

function CalendarTxtClicked() {
    var images = document.getElementsByTagName('img');
    for (i = 0; i < images.length; i++) {
        if (document.getElementById(images[i].id).className == "CalendarImg") {
            images[i].click();
        }
    }

    return false;
}




var fadeElement;
var imgElement;
var theHerosToFade;
var upFadeOpacity = 0;
var downFadeOpacity = 100;
var crossFadeTimer;
var crossFadeInc = 10;
var theCurrentAnchor;
var theTabImages;
var theTimer;
var slideDuration = 10000;
var heroSet = 1;
var startSwap
var theHero1;
var theHero2;
var theHero3;
var theHerosToFade;

function swapHero() {
    if (startSwap != null) {
        window.clearTimeout(startSwap);
    }

    if (heroSet == 1) {
        fadeElement = theHero2;
        heroSet = 2;
    } else if (heroSet == 2) {
        fadeElement = theHero3;
        heroSet = 3;
    } else {
        fadeElement = theHero1;
        heroSet = 1;
    }
    fadeElement.style.display = "block";
    crossFadeHeros();
}



function crossFadeHeros() {
    var isMSIE = navigator.appName.indexOf("Microsoft");
    if (crossFadeTimer) {
        window.clearTimeout(crossFadeTimer);
    }
    if (upFadeOpacity <= 100) {
        for (x = 0; x < theHerosToFade.length; x++) {
            if (theHerosToFade[x] == fadeElement) {
                //fadeElement.style.display="block";
                if (isMSIE != -1 && parseInt(navigator.appVersion) >= 4) {
                    fadeElement.filters.alpha.opacity = upFadeOpacity;
                } else {
                    fadeElement.style.opacity = upFadeOpacity / 100;
                }
            } else {
                if (isMSIE != -1 && parseInt(navigator.appVersion) >= 4 && theHerosToFade[x].filters.alpha.opacity != 0) {
                    theHerosToFade[x].filters.alpha.opacity = downFadeOpacity;
                } else if (theHerosToFade[x].style.opacity != 0) {
                    theHerosToFade[x].style.opacity = downFadeOpacity / 100;
                }
                if (downFadeOpacity == 0) {
                    theHerosToFade[x].style.display = "none";
                }
            }
        }
        upFadeOpacity = upFadeOpacity + crossFadeInc;
        downFadeOpacity = downFadeOpacity - crossFadeInc;
        crossFadeTimer = window.setTimeout("crossFadeHeros()", 100);
    } else {
        if (fadeElement.getElementsByTagName('input')[0]) {
            fadeElement.getElementsByTagName('input')[0].focus();
        }
        upFadeOpacity = 0;
        downFadeOpacity = 100;
        window.clearTimeout(crossFadeTimer);
        crossFadeTimer = null;
        startSwap = window.setTimeout(swapHero, slideDuration);
    }
}


function initPage() {

    if (document.getElementById("heroSwap")) {
        theHero1 = document.getElementById("hero1");
        theHero2 = document.getElementById("hero2");
        theHero3 = document.getElementById("hero3");
        theHero1.className = "Homepage_Hero hero1 off";
        theHero2.className = "Homepage_Hero hero2 off";
        theHero3.className = "Homepage_Hero hero3 off";
        var theRandomNumber = Math.ceil(Math.random() * 3);
        var theRandomHero = "hero" + theRandomNumber;
        document.getElementById(theRandomHero).className = "Homepage_Hero hero" + theRandomNumber;

        theHerosToFade = Array(theHero1, theHero2, theHero3);
        heroSet = theRandomNumber;


        startSwap = window.setTimeout(swapHero, slideDuration);
    }
}

    window.onload = initPage;
