﻿var LOCATIONSWITCHER = {};

LOCATIONSWITCHER.Location = function(location, flagId, classToSwitch, classNotToSwitch, locationIdentiferClass) {
    this.FlagJQueryObject = $('#' + flagId);
    this.Name = location;
    this.ToSwitchJQueryObject = $("." + classToSwitch).not("." + classToSwitch + "." + classNotToSwitch);
    this.LocationIdentifier = $("." + locationIdentiferClass);
    this.switchLocation = function() {
        if (this.FlagJQueryObject.length > 0) {
            if (this.FlagJQueryObject.hasClass('on')) {
                this.FlagJQueryObject.removeClass('on');
                this.ToSwitchJQueryObject.fadeOut(100);
                if (locationIdentiferClass) {
                    this.LocationIdentifier.fadeOut(100);
                }
            }
            else {
                this.FlagJQueryObject.addClass('on');
                this.ToSwitchJQueryObject.fadeIn(100);
                if (locationIdentiferClass) {
                    this.LocationIdentifier.fadeIn(100);
                }
            }
        }
    };    
};

function reArrangeAltClass() {
    $('.panel.detail_list').each(function() {
        var css = "row";
        $(this).children(".row").each(function() {
            if (isVisible(this)) {
                switch (css) {
                    case "row":
                        if ($(this).hasClass("alt")) {
                            $(this).removeClass("alt");
                        }
                        css = "rowalt";
                        break;
                    case "rowalt":
                        if (!$(this).hasClass("alt")) {
                            $(this).addClass("alt");
                        }
                        css = "row";
                        break;
                }
            }
        });
    });
};

function isVisible(obj) {
    var flag = true;
    //alert($(obj).attr("style"));
    if ($(obj).attr("style")) {
        var objStyle = $(obj).attr("style");
        if (objStyle.indexOf("opacity: 1") != -1) {//Firefox,opera,safari
            flag = false;
        }
        else if (objStyle.indexOf("opacity=100") != -1) {//IE
            flag = false;
        }
        else if (objStyle.toLowerCase().indexOf("display: none") != -1) {
            flag = false;
        }
    }
    return flag;
}