﻿function MultipleSelection() {
}
MultipleSelection.CurrentDomain = "";
MultipleSelection.BackgroundColor = "";
MultipleSelection.Color = "";

MultipleSelection.ProcessOnMouseOver = function (source, team1, team2, domain, containerId, containerId2) {
    if (MultipleSelection.CurrentDomain == domain || MultipleSelection.CurrentDomain == "") {
        MultipleSelection.CurrentDomain = domain;

        var selectorString = "#" + containerId + " div";
        if (containerId2 != null && containerId2 != "")
            selectorString += (", #" + containerId2 + " div");

        $(selectorString).each(function (index, value) {
            var element = $(this);
            var idProp = element.attr("id");

            if (source.getAttribute("id") != idProp) {
                if (team1 != null) {
                    var hasTeam1 = idProp.indexOf("_T" + team1 + "$") != -1;
                    if (hasTeam1 == true)
                        MultipleSelection.SetChildsBackgroundOver(element);
                }
                if (team2 != null) {
                    var hasTeam2 = idProp.indexOf("_T" + team2 + "$") != -1;
                    if (hasTeam2 == true)
                        MultipleSelection.SetChildsBackgroundOver(element);
                }
            }
        });
    }
}

MultipleSelection.SetChildsBackgroundOver = function (element) {
    element.css("background-color", MultipleSelection.BackgroundColor);
    element.children().css("background-color", MultipleSelection.BackgroundColor);
    element.children().css("color", MultipleSelection.Color);

//    if (element.children().length > 0) {
//        $.each(element.children(), function (index, value) {
//            MultipleSelection.SetChildsBackgroundOver($(this));
//        });
//    }
}

MultipleSelection.SetChildsBackgroundOut = function (element) {
    element.css("background-color", "");
    element.children().css("background-color", "");
    element.children().css("color", "");

//    if (element.children().length > 0) {
//        $.each(element.children(), function (index, value) {
//            MultipleSelection.SetChildsBackgroundOut($(this));
//        });
//    }
}

MultipleSelection.ProcessOnMouseOut = function (source, domain, containerId, containerId2) {
    if (MultipleSelection.CurrentDomain == domain) {
        MultipleSelection.CurrentDomain = "";

        var selectorString = "#" + containerId + " div";
        if (containerId2 != null && containerId2 != "")
            selectorString += (", #" + containerId2 + " div");

        $(selectorString).each(function (index, value) {
            var element = $(this);

            if (source.getAttribute("id") != element.attr("id")) {
                MultipleSelection.SetChildsBackgroundOut(element);
            }
        });
    }
}
