function sp_load_plugin_styles($ahahCall = false)
{
    global $spCSSLoaded, $spDevice, $spPaths, $spGlobals;
    if (!sp_get_option('sfwpheadbypass') && $spCSSLoaded) {
        return;
    }
    $curTheme = $spGlobals['theme'];
    $curTheme = apply_filters('sph_theme', $curTheme);
    $vars = '';
    $overlay = '';
    # handle chiild themes
    $parentTheme = !empty($curTheme['parent']) ? sp_get_theme_data(SPTHEMEBASEDIR . $curTheme['parent'] . '/spTheme.txt') : '';
    # handle color overlays
    if (current_theme_supports('sp-theme-child-overlays')) {
        # can use - so might be - a child theme overlay
        $overlay = !empty($curTheme['color']) ? $curTheme['color'] : '';
        if (!empty($parentTheme) && !empty($curTheme['color'])) {
            # must be a child with an overlay selected so...
            # is the overlay in the child theme or not?
            if (file_exists(SPTHEMEBASEDIR . $curTheme['theme'] . '/styles/overlays/' . $curTheme['color'] . '.php')) {
                $theme = $curTheme['theme'];
            } elseif (!empty($curTheme['color'])) {
                $theme = $curTheme['parent'];
            }
        } else {
            $theme = $curTheme['theme'];
        }
    } else {
        # no support for child overlays so do it the old eway
        $overlay = !empty($curTheme['color']) ? $curTheme['color'] : '';
        if (!empty($parentTheme) && !empty($curTheme['color'])) {
            $theme = $curTheme['parent'];
        } else {
            $theme = $curTheme['theme'];
        }
    }
    $vars = !empty($overlay) ? '?overlay=' . esc_attr($overlay) . '&theme=' . esc_attr($theme) : '';
    # add device query var string
    $vars = !empty($vars) ? "{$vars}&device={$spDevice}" : "?device={$spDevice}";
    # set the images path array
    sp_set_image_array($curTheme);
    $spCSSLoaded = true;
    # if called from the AHAH/AJAX init routine then leave now...
    if ($ahahCall) {
        return;
    }
    # handle RTL
    if (is_rtl()) {
        $vars = !empty($vars) ? "{$vars}&rtl=1" : '?rtl=1';
    }
    $reset = is_rtl() ? 'reset.rtl.css' : 'reset,css';
    # enqueue the main theme css
    if (sp_is_plugin_active('user-selection/sp-user-selection-plugin.php')) {
        if (!empty($parentTheme)) {
            $cssTheme = strpos($parentTheme['Stylesheet'], '.css') ? true : false;
            if ($cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/' . $reset)) {
                wp_enqueue_style('sp-parent-reset', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $reset);
            }
            wp_enqueue_style('sp-parent', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $parentTheme['Stylesheet'] . $vars);
            if (is_rtl() && $cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/rtl.css')) {
                wp_enqueue_style('sp-parent-rtl', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/rtl.css');
            }
        }
        $cssTheme = strpos(SPTHEMECSS, '.css') ? true : false;
        if ($cssTheme && file_exists(SPTHEMEDIR . $reset)) {
            wp_enqueue_style('sp-theme-reset', SPTHEMECSSEXTRA . $reset);
        }
        wp_enqueue_style('sp-theme', SPTHEMECSS . $vars);
        if (is_rtl() && $cssTheme && file_exists(SPTHEMEDIR . 'rtl.css')) {
            wp_enqueue_style('sp-theme-rtl', SPTHEMECSSEXTRA . 'rtl.css');
        }
    } else {
        if (!empty($parentTheme)) {
            $cssTheme = strpos($parentTheme['Stylesheet'], '.css') ? true : false;
            if ($cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/' . $reset)) {
                sp_plugin_enqueue_style('sp-parent-reset', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $reset);
            }
            sp_plugin_enqueue_style('sp-parent', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $parentTheme['Stylesheet'] . $vars);
            if (is_rtl() && $cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/rtl.css')) {
                sp_plugin_enqueue_style('sp-parent-rtl', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/rtl.css');
            }
        }
        $cssTheme = strpos(SPTHEMECSS, '.css') ? true : false;
        if ($cssTheme && file_exists(SPTHEMEDIR . $reset)) {
            sp_plugin_enqueue_style('sp-theme-reset', SPTHEMECSSEXTRA . $reset);
        }
        sp_plugin_enqueue_style('sp-theme', SPTHEMECSS . $vars);
        if (is_rtl() && $cssTheme && file_exists(SPTHEMEDIR . 'rtl.css')) {
            sp_plugin_enqueue_style('sp-theme-rtl', SPTHEMECSSEXTRA . 'rtl.css');
        }
    }
    # concat (if needed) and enqueue the plugin css
    do_action('sph_print_plugin_styles');
    $combine_css = sp_get_option('combinecss');
    if ($combine_css) {
        sp_combine_plugin_css_files();
    } else {
        global $sp_plugin_styles;
        if (!empty($sp_plugin_styles)) {
            foreach ($sp_plugin_styles->queue as $handle) {
                wp_enqueue_style($handle, $sp_plugin_styles->registered[$handle]->src);
            }
        }
    }
    do_action('sph_styles_end');
}
function sp_load_plugin_styles()
{
    $curTheme = sp_get_current_sp_theme();
    # get optional color variant to pass to stylesheet
    $curTheme = apply_filters('sph_theme', $curTheme);
    # handle chiild themes
    $parentTheme = !empty($curTheme['parent']) ? sp_get_theme_data(SPTHEMEBASEDIR . $curTheme['parent'] . '/spTheme.txt') : '';
    # handle color overlays
    $vars = !empty($curTheme['color']) ? '?color=' . esc_attr($curTheme['color']) : '';
    # handle RTL
    if (is_rtl()) {
        $vars = !empty($vars) ? "{$vars}&rtl=1" : '?rtl=1';
    }
    $reset = is_rtl() ? 'reset.rtl.css' : 'reset,css';
    # enqueue the main theme css
    if (sp_is_plugin_active('user-selection/sp-user-selection-plugin.php')) {
        if (!empty($parentTheme)) {
            $cssTheme = strpos($parentTheme['Stylesheet'], '.css') ? true : false;
            if ($cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/' . $reset)) {
                wp_enqueue_style('sp-parent-reset', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $reset);
            }
            wp_enqueue_style('sp-parent', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $parentTheme['Stylesheet'] . $vars);
            if (is_rtl() && $cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/rtl.css')) {
                wp_enqueue_style('sp-parent-rtl', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/rtl.css');
            }
        }
        $cssTheme = strpos(SPTHEMECSS, '.css') ? true : false;
        if ($cssTheme && file_exists(SPTHEMEDIR . $reset)) {
            wp_enqueue_style('sp-theme-reset', SPTHEMECSSEXTRA . $reset);
        }
        wp_enqueue_style('sp-theme', SPTHEMECSS . $vars);
        if (is_rtl() && $cssTheme && file_exists(SPTHEMEDIR . 'rtl.css')) {
            wp_enqueue_style('sp-theme-rtl', SPTHEMECSSEXTRA . 'rtl.css');
        }
    } else {
        if (!empty($parentTheme)) {
            $cssTheme = strpos($parentTheme['Stylesheet'], '.css') ? true : false;
            if ($cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/' . $reset)) {
                sp_plugin_enqueue_style('sp-parent-reset', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $reset);
            }
            sp_plugin_enqueue_style('sp-parent', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $parentTheme['Stylesheet'] . $vars);
            if (is_rtl() && $cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/rtl.css')) {
                sp_plugin_enqueue_style('sp-parent-rtl', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/rtl.css');
            }
        }
        $cssTheme = strpos(SPTHEMECSS, '.css') ? true : false;
        if ($cssTheme && file_exists(SPTHEMEDIR . $reset)) {
            sp_plugin_enqueue_style('sp-theme-reset', SPTHEMECSSEXTRA . $reset);
        }
        sp_plugin_enqueue_style('sp-theme', SPTHEMECSS . $vars);
        if (is_rtl() && $cssTheme && file_exists(SPTHEMEDIR . 'rtl.css')) {
            sp_plugin_enqueue_style('sp-theme-rtl', SPTHEMECSSEXTRA . 'rtl.css');
        }
    }
    # concat (if needed) and enqueue the plugin css
    do_action('sph_print_plugin_styles');
    $combine_css = sp_get_option('combinecss');
    if ($combine_css) {
        sp_combine_plugin_css_files();
    } else {
        global $sp_plugin_styles;
        if (!empty($sp_plugin_styles)) {
            foreach ($sp_plugin_styles->queue as $handle) {
                wp_enqueue_style($handle, $sp_plugin_styles->registered[$handle]->src);
            }
        }
    }
    do_action('sph_styles_end');
}