﻿var ContentHeight = 50;
var TimeToSlide = 250.0;

var openAccordion = '';

function runAccordion(index, contentHeight, blnAnimate) {
    var nID = "Accordion" + index + "Content";

    
        ContentHeight = contentHeight;

        if (openAccordion == nID)
            nID = '';

        setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
      + openAccordion + "','" + nID + "')", 33);

        openAccordion = nID;
    
}

function animate(lastTick, timeLeft, closingId, openingId) {
    var curTick = new Date().getTime();
    var elapsedTicks = curTick - lastTick;

    var opening = (openingId == '') ? null : document.getElementById(openingId);
    var closing = (closingId == '') ? null : document.getElementById(closingId);

    if (timeLeft <= elapsedTicks) {
        if (opening != null)
            opening.style.height = ContentHeight + 'px';

        if (closing != null) {
            closing.style.display = 'none';
            closing.style.height = '0px';
        }
        return;
    }

    timeLeft -= elapsedTicks;
    var newClosedHeight = Math.round((timeLeft / TimeToSlide) * ContentHeight);

    if (opening != null) {
        if (opening.style.display != 'block')
            opening.style.display = 'block';
        opening.style.height = (ContentHeight - newClosedHeight) + 'px';
    }

    if (closing != null)
        closing.style.height = newClosedHeight + 'px';

    setTimeout("animate(" + curTick + "," + timeLeft + ",'"
      + closingId + "','" + openingId + "')", 33);
}

function DisplaySelectedMenu() {
    
    // figure out the page file name.
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
   
    // figure out and display the content menu for the page.
    var menuConentArea;
    var content;
    var totalContentAreas = 5;
    
    if (sPage.toLowerCase() != "sitemap.aspx") {
        for (i = 1; i <= totalContentAreas; i++) {

            content = document.getElementById("Accordion" + i + "Content");
            
            if (content.innerHTML.indexOf(sPage) > 0) {
                // page file name was found
                var menu;

                menu = document.getElementById("Menu" + i);

                var contentMenuHeight;
                
                // don't expand the accordion, just up the menu area.
                switch (i) {
                    case 1:
                        contentMenuHeight = "80px";
                        break;
                    case 2:
                        contentMenuHeight = "35px";
                        break;
                    case 3:
                        contentMenuHeight = "145px";
                        break;
                    case 4:
                        contentMenuHeight = "70px";
                        break;
                    case 5:
                        contentMenuHeight = "57px";
                        break;
                }
                // set the current open accodion content area to that the accordion code
                // knows to close it if switching to next accordion content area.
                openAccordion = content.id;
                
                // expand the accordion content area without animation.                
                content.style.height = contentMenuHeight;
                content.style.display = 'block';
                // remember the area index to use later for menu item seperator.
                menuConentArea = i;
                break;
            }
        }

        // call to adjust css style for browser.
         var IE7 = IsIE7();

         // place the menu item seperator to be right under the menu item for the page.
         var bottomPosition = "";

         switch (sPage.toLowerCase()) {
             case "ebn.aspx":
                 bottomPosition = "133";
                 break;
             case "unclaimedfunds.aspx":
                 bottomPosition = "111";
                 break;
             case "debtpurchases.aspx":
                 bottomPosition = "89";
                 break;
             case "debtservicingsecured.aspx":
                 bottomPosition = "67";
                 break;
             case "debtservicingunsecured.aspx":
                 bottomPosition = "45";
                 break;
			 case "bottomlinesolutions.aspx":
                 bottomPosition = "23";
                 break;
             case "aboutbline.aspx":
                 bottomPosition = "67";
                 break;
             case "executiveteam.aspx":
                 bottomPosition = "45";
                 break;
             case "contact.aspx":
                 bottomPosition = "23";
                 break;
             case "ourprocess.aspx":
                 bottomPosition = "23";
                 break;
             case "companyculture.aspx":
                 bottomPosition = "67";
                 break;
             case "opportunities.aspx":
                 bottomPosition = "45";
                 break;
             case "search.aspx":
                 bottomPosition = "45";
                 menuConentArea = 5;
                 break;
            case "todaysnews.aspx":
                bottomPosition = "23";
                break;
             default:
                 // must be the employee self service
                 break;
         }

         // override the CSS bottom style to adjust the item seperator
         if (bottomPosition != "") {
             //adjust for IE 7
             if (IE7) {
                 bottomPosition = parseInt(bottomPosition) + 5;
                
                 var menuSeperator = document.getElementById("MenuSeperator" + menuConentArea);
                 menuSeperator.style.setAttribute('bottom', bottomPosition + 'px');
             }
             else {
                 // move the image seperator to selected menu.
                 document.getElementById("MenuSeperator" + menuConentArea).style.bottom = bottomPosition + "px"; 
             }  
         }
         
     }
}

function IsIE7 () {
    
    if (navigator.appName == "Microsoft Internet Explorer") {
        var version = navigator.appVersion;
        var word = version.match("MSIE 7.0");
        
        
        if (word != null) {
            return true;
        }
        else {
            return false;
        }
    }
    
}
