/* Minification failed. Returning unminified contents.
(4,10): run-time error CSS1031: Expected selector, found 'namespace('
(4,10): run-time error CSS1025: Expected comma or open brace, found 'namespace('
(18,10): run-time error CSS1031: Expected selector, found 'setBrowserToFullScreen('
(18,10): run-time error CSS1025: Expected comma or open brace, found 'setBrowserToFullScreen('
(31,10): run-time error CSS1031: Expected selector, found 'setBrowserToNormalScreen('
(31,10): run-time error CSS1025: Expected comma or open brace, found 'setBrowserToNormalScreen('
(44,1): run-time error CSS1019: Unexpected token, found '('
(44,11): run-time error CSS1031: Expected selector, found '('
(44,11): run-time error CSS1025: Expected comma or open brace, found '('
(98,2): run-time error CSS1019: Unexpected token, found ')'
(98,3): run-time error CSS1019: Unexpected token, found '('
(98,4): run-time error CSS1019: Unexpected token, found 'namespace('
(98,14): run-time error CSS1019: Unexpected token, found '"fx.util.theme"'
(98,29): run-time error CSS1019: Unexpected token, found ')'
(98,30): run-time error CSS1019: Unexpected token, found ')'
 */
//Maybe its time for name space to become magical polyfill global scope methods


function namespace(namespaceString) {
    var parts = namespaceString.split('.'),
        parent = window,
        currentPart;
    
    for (var i = 0, length = parts.length; i < length; i++) {
        currentPart = parts[i];
        parent[currentPart] = parent[currentPart] || {};
        parent = parent[currentPart];
    }

    return parent;
}

function setBrowserToFullScreen() {
    if ((document.fullScreenElement && document.fullScreenElement !== null) ||
                (!document.mozFullScreen && !document.webkitIsFullScreen)) {
        if (document.documentElement.requestFullScreen) {
            document.documentElement.requestFullScreen();
        } else if (document.documentElement.mozRequestFullScreen) {
            document.documentElement.mozRequestFullScreen();
        } else if (document.documentElement.webkitRequestFullScreen) {
            document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
        }
    }
}

function setBrowserToNormalScreen() {
    if ((document.fullScreenElement || document.fullScreenElement !== null) ||
   (document.mozFullScreen && document.webkitIsFullScreen)) {
        if (document.cancelFullScreen) {
            document.cancelFullScreen();
        } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        } else if (document.webkitCancelFullScreen) {
            document.webkitCancelFullScreen();
        }
    }
}

(function (fxUtilTheme) {
    const dataThemeKey = 'data-theme';
    const webThemeKey = 'web-theme';

    fxUtilTheme.setTheme = function (theme) {
        setDataTheme(theme);
    }

    fxUtilTheme.setDashboardTheme = function (theme) {
        setDataTheme(theme);
    }

    function setDataTheme(theme) {
        if (theme) {
            document.documentElement.setAttribute(dataThemeKey, theme);
            localStorage.setItem(dataThemeKey, theme);
        }
    }

    function setWebTheme(theme) {
        if (theme) {
            document.documentElement.setAttribute(webThemeKey, theme);
            localStorage.setItem(webThemeKey, theme);
        }
    }

    fxUtilTheme.setWebTheme = function (theme) {
        setWebTheme(theme);
    }

    fxUtilTheme.getWebTheme = function () {
        return localStorage.getItem(webThemeKey);
    }

    fxUtilTheme.getTheme = function () {
        return localStorage.getItem(dataThemeKey);
    }

    fxUtilTheme.isDarkTheme = function () {
        var theme = fxUtilTheme.getTheme();
        if (theme)
            return theme.search('darkTheme') != -1;
        else
            return false;
    }

    fxUtilTheme.initTheme = function () {
        var theme = fxUtilTheme.getTheme();
        webTheme = theme;
        fxUtilTheme.setTheme(theme);
    }

    fxUtilTheme.initTheme();

})(namespace("fx.util.theme"));
