﻿(function ($) {
    $(document).ready(function () {
        $("#divMenu *").live("click", function (evt) {
            if (this.id == "") {
                evt.stopPropagation();
                return;
            }
            $.HelperJS.Navigate("#" + this.id.substring(2).replace("-", "/"));
            evt.stopPropagation();
        });
        $("#divMenu li, a").each(function () {
            var me = this;
            $(this).children("ul").children("li").children("ul").each(function () {
                $(this).css("margin-left", $(me).outerWidth() - 6);
            });
        });
        $("#divMenu ul li").hover(function () {
            var me = this;
            var child = $(this).children("ul:first");
            $(child).show();

            $(child).width($(this).outerWidth());
            $(me).mouseout(function (evt) {
                var to = evt.toElement;
                if (!to)
                    to = evt.relatedTarget;
                if (to == me)
                    return;
                var is = false;
                $(me).find("ul, li, a").each(function () {
                    if (to == this) {
                        is = true;
                        return;
                    }
                });
                if (is)
                    return;
                //alert($(to).attr("id"));
                $(child).hide();
            });
        });
    });
})(jQuery);

$.NavBar = {
    ChangeDiv: function (div) {
        $("[id^='divMain_']").removeClass("selected");
        $("#divMain_" + div).addClass("selected");
      },
    ToggleDivs: function (div, override, ignoreNav) {
        $("[id^='nav_']").hide();
        $("[id^='div_nav_']").attr("class", "");
        $("#div_nav_" + div).attr("class", "selected");
        $("[id^='divMain_']").removeClass("selected");
        $("#divMain_" + div).addClass("selected");
        $("#nav_" + div).show();
        if (ignoreNav == true)
            return;
        if (override)
            window.location = override;
        else
            window.location = ("#" + div + "/Index");

    }
};

function findPos(obj) {
    var posX = obj.offsetLeft; var posY = obj.offsetTop;
    while (obj.offsetParent) {
        if (obj == document.getElementsByTagName('body')[0]) { break }
        else {
            posX = posX + obj.offsetParent.offsetLeft;
            posY = posY + obj.offsetParent.offsetTop;
            obj = obj.offsetParent;
        }
    }
    var posArray = [posX, posY]
    return posArray;
}
