﻿
var curPath = "";
var byClick = false;
$(document).ready(function() {
    //fix ie7 issue... grrr
    if (($.browser) && ($.browser.msie) && ($.browser.msie == true) && ($.browser.version) && ($.browser.version == "7.0")) {
        var el = document.getElementById("bottomRightMonolith");
        if (el) {
            el.style.left = "343px";
        }
    }
    $.address.change(addressChange);
    //$.address.change(function(c) { alert('hi'); });
    var startAddress = getAddress();
    // do stuff when DOM is ready
    navigateTo(startAddress, startUpCallBack);
    //loadTopMenu(startUpCallBack, startAddress);

    //    $(".servicesMenu div").hover(function() {
    //        $(this).next("em").animate({ opacity: "show", top: "-75" }, "slow");
    //    }, function() {
    //        $(this).next("em").animate({ opacity: "hide", top: "-85" }, "fast");
    //    });
    $(".servicesTable").find("em").css("opacity", 0);

    //    $(".servicesTable").hover(function() {
    //        $(this).find("em").stop().animate({ opacity: 0.85, top: "-115" }, "slow"); //, width: "158px", height: "45px"
    //    }, function() {
    //        $(this).find("em").stop().animate({ opacity: .01, top: "20" }, "fast"); //, width: "1px", height: "1px"
    //    });

});

function startUpCallBack() {

    var startAddress = $.address.value();
    //alert("start callback");
    //var startAddress = null;
    if ((startAddress) && (startAddress != "") && (startAddress != "/")) {
        //alert(startAddress);
        //loadSideMenuFromPath(startAddress);
        //loadTemplateFromPath(startAddress);
    } else {
        startAddress = "/" + escape(startUpMenu);
    }

    if ((startAddress) && (startAddress != "") && (startAddress != "/")) {
        if ((startUpMenu) && (startUpTemplate) && (startUpContent)) {

            var arrAddress = startAddress.split("/");
            var rootAddress = "";
            if ((arrAddress) && (arrAddress.length > 1)) {
                rootAddress = arrAddress[1];
            }
            var arrCurMenuItem = $("td[path=" + rootAddress + "]");
            var curMenuItem = null;
            if ((arrCurMenuItem) && (arrCurMenuItem.length) && (arrCurMenuItem.length > 0)) {
                curMenuItem = arrCurMenuItem[0];
            }
            if (!startAddress.match(/home/)) {
                var sideMenu = $("#sideMenu");
                sideMenu.css("display", "inline");
                sideMenu.attr("alternateMenu", "false");
            }

            //if (!curMenuItem) {
            //    loadSideMenuFromPath(startAddress);
            //    loadTemplateFromPath(startAddress);
            //} else if (curMenuItem.click) {
            //    curMenuItem.click();
            // }
        }
    }

}

function getAddress() {
    var address = "";

    var startAddress = $.address.value();

    if ((startAddress) && (startAddress != "") && (startAddress != "/")) {
        address = startAddress;
    } else {
        address = "/" + escape(startUpMenu);
    }

    return address;
}


function addressChange(c) {

    if (byClick == false) {
        navigateTo(c.value);
    } else {
        byClick = false;
    }

}

