<?php
// This file generates the CSS overrides from the admin interface. It will be included only
// when needed.
function weaverii_save_current_css() {
    // write the current generated CSS to a file - called only from Weaver II Admin

    if (!weaverii_f_file_access_available() || !current_user_can( 'manage_options' ) ) {
	return '';
    }

    $save_dir = weaverii_f_uploads_base_dir() . 'weaverii-subthemes';
    $save_url = weaverii_f_uploads_base_url() . 'weaverii-subthemes';

    $usename = 'style-weaverii.css';

    $wii_theme_dir_exists = weaverii_f_mkdir($save_dir);
    if (!$wii_theme_dir_exists) {
	weaverii_f_file_access_fail('Unable to create directory. Probably a file system permission problem. Directory' . $save_dir);
    }
    $wii_theme_dir_writable = $wii_theme_dir_exists;

   if (!weaverii_f_is_writable($save_dir)) {
	weaverii_f_file_access_fail('Directory not writable. Probably a file system permission problem. Directory: ' . $save_dir);
        $wii_theme_dir_writable = false;
    }

    $filename = $save_dir . '/'. $usename;    // we will add txt

    if (!$wii_theme_dir_writable || !$wii_theme_dir_exists || !($handle = weaverii_f_open($filename, 'w')) ) {
	weaverii_f_file_access_fail('Unable to create file. Probably a file system permission problem. File: ' . $filename);
	return '';
    }

    weaverii_f_write($handle,sprintf("/* WARNING: Do not edit this file. It is dynamically generated. Any edits you make will be overwritten. */
/* This file generated using %s %s subtheme: %s */\n",WEAVERII_THEMENAME, WEAVERII_VERSION, weaverii_getopt('wii_subtheme')));

    weaverii_output_style($handle);
    if (!weaverii_f_close($handle)) {
	weaverii_f_file_access_fail('Unable to create file. Probably a file system permission problem. File: ' . $filename);
	return '';
    }

    return $save_url . '/' . $usename;
}

function weaverii_output_style($sout) {
    /* This outputs the CSS overrides. It will output to a file pointer, so it can write to a .css file saved
       in the user's upload directory - just like the saved style .wvr files. It is included via a standard
       css include. It needs to be loaded only for the admin page.
    */
    weaverii_f_write($sout,sprintf("/* Weaver II styles - Version %s */\n",weaverii_getopt('wii_style_version')));


// =========================== LINKS ===============================
//	Important. Links must come before any other rules that might define a - such as the menu bars, so just
//	put them here, near the top.

    weaverii_put_link($sout,'wii_link','a', 'a:visited', 'a:hover');
    weaverii_put_link($sout,'wii_plink','.entry-title a', '.entry-title a:visited', '.entry-title a:hover');
    weaverii_put_link($sout,'wii_ilink','.entry-meta a, entry-utility a', '.entry-meta a:visited, entry-utility a:visited',
	'.entry-meta a:hover, entry-utility a:hover');
    weaverii_put_link($sout,'wii_wlink','.widget-area a', '.widget-area a:visited', '.widget-area a:hover');
    weaverii_put_link($sout,'wii_ibarlink','#infobar a', '#infobar a:visited', '#infobar a:hover');
    weaverii_put_link($sout,'wii_footerlink','#colophon a', '#colophon a:visited', '#colophon a:hover');



// ========================= GENERAL APPEARANCE ===============================

   /*  wii_useborders  */
    $b_c = weaverii_getopt('wii_border_color');	//+
    if (!$b_c) $b_c = '#222';
    $b_w = weaverii_getopt('wii_border_width_int'); //+
    if (!$b_w) $b_w = 1;
    $b_s = weaverii_getopt('wii_border_style'); //+
    if (!$b_s) $b_s = 'solid';

    if (weaverii_getopt_checked('wii_useborders') || weaverii_getopt_checked('wii_wrapper_border')) {
        weaverii_f_write($sout, sprintf("#wrapper {border: %dpx %s %s;}\n",$b_w, $b_s, $b_c));
    }
    if (weaverii_getopt_checked('wii_useborders')) {
	/* we need to use each widget area explicitly instead of simply .widget-area so the PIE works right on IE */
	weaverii_f_write($sout, sprintf("#sidebar_primary,#sidebar_right,#sidebar_left,.sidebar_top,.sidebar_bottom,.sidebar_extra,#first,#second,#third,#fourth {border: %dpx %s %s;}\n",$b_w, $b_s, $b_c));
    }

    /*  wii_rounded_corners  */
    $r = 10;
    $rm = 7;

    $newr = weaverii_getopt('wii_rounded_corners_radius');
    if ($newr) {
	$r = $newr;
	if ($r >= 8)
	    $rm = (int)(.7 * $r);
	else
	    $rm = $r;
    }

    if (weaverii_getopt('wii_rounded_corners')) { // not #access3
        weaverii_f_write($sout, sprintf("#wrapper, #branding, #colophon, .commentlist li.comment, #respond, #sidebar_primary,#sidebar_right,#sidebar_left,.sidebar_top,.sidebar_bottom,.sidebar_extra,#first,#second,#third,#fourth,.mobile_widget_area {-moz-border-radius: %dpx; -webkit-border-radius: %dpx; border-radius: %dpx;}\n",$r,$r,$r));
	weaverii_f_write($sout, sprintf("#sidebar_wrap_right.right-1-col,#sidebar_wrap_right.right-2-col,#sidebar_wrap_right.right-2-col-bottom,
#sidebar_wrap_left.left-1-col,#sidebar_wrap_left.left-2-col,#sidebar_wrap_left.left-2-col-bottom,#sidebar_wrap_left,#sidebar_wrap_right
{-moz-border-radius: %dpx; -webkit-border-radius: %dpx; border-radius: %dpx;}\n",$r,$r,$r));

	weaverii_f_write($sout, sprintf(".commentlist li.comment .comment-meta {-moz-border-radius-topleft: %dpx; -moz-border-radius-topright: %dpx;
 -webkit-border-top-left-radius: %dpx; -webkit-border-top-right-radius: %dpx; border-top-left-radius: %dpx; border-top-right-radius: %dpx;}\n",
	$rm,$rm,$rm,$rm,$rm,$rm));

	if (weaverii_getopt('wii_move_menu')) {
	    weaverii_f_write($sout, sprintf("#access2 {-moz-border-radius-bottomleft: %dpx; -moz-border-radius-bottomright: %dpx;
 -webkit-border-bottom-left-radius: %dpx; -webkit-border-bottom-right-radius: %dpx; border-bottom-left-radius: %dpx; border-bottom-right-radius: %dpx;}\n",
    $rm,$rm,$rm,$rm,$rm,$rm));
	    weaverii_f_write($sout, sprintf("#access {-moz-border-radius-topleft: %dpx; -moz-border-radius-topright: %dpx;
 -webkit-border-top-left-radius: %dpx; -webkit-border-top-right-radius: %dpx; border-top-left-radius: %dpx; border-top-right-radius: %dpx;}\n",
	$rm,$rm,$rm,$rm,$rm,$rm));
	} else {
	    weaverii_f_write($sout, sprintf("#access {-moz-border-radius-bottomleft: %dpx; -moz-border-radius-bottomright: %dpx;
 -webkit-border-bottom-left-radius: %dpx; -webkit-border-bottom-right-radius: %dpx;border-bottom-left-radius: %dpx; border-bottom-right-radius: %dpx;}\n",
	$rm,$rm,$rm,$rm,$rm,$rm));
	    weaverii_f_write($sout, sprintf("#access2 {-moz-border-radius-topleft: %dpx; -moz-border-radius-topright: %dpx;
 -webkit-border-top-left-radius: %dpx; -webkit-border-top-right-radius: %dpx;border-top-left-radius: %dpx; border-top-right-radius: %dpx;}\n",
	$rm,$rm,$rm,$rm,$rm,$rm));
	}
    }
    if (weaverii_getopt('wii_rounded_corners_content')) { // content area, too
        weaverii_f_write($sout, sprintf("#content, #content .post{-moz-border-radius: %dpx; -webkit-border-radius: %dpx; border-radius: %dpx;}\n",$r,$r,$r));
    }

    /*  wii_fadebody_bg  */

    if (weaverii_getopt('wii_fadebody_bg')) {
	weaverii_f_write($sout, sprintf("body {background-image: url(%s); background-attachment: scroll; background-repeat: repeat-x;}\n",
	       weaverii_relative_url('images/gr.png')));
    }

    /*  wii_wrap_shadow  */

    if (weaverii_getopt('wii_wrap_shadow')) {
	weaverii_f_write($sout, sprintf("#wrapper {box-shadow: 0 0 3px 3px rgba(127,127,127,0.25); -webkit-box-shadow: 0 0 3px 3px rgba(0,0,0,0.25); -moz-box-shadow: 0 0 3px 3px rgba(0,0,0,0.25);}\n"));
    }


// ========================= LAYOUT / SIDEBAR AREAS ===============================

    $themew = weaverii_getopt('wii_theme_width_int');
    if (!$themew) $themew = 940;	// nothing will work right if this doesn't have a value
    if (weaverii_getopt_checked('wii_theme_width_fixed'))
    	weaverii_f_write($sout,sprintf("#wrapper{width:%dpx;}\n",$themew));
    else
	weaverii_f_write($sout,sprintf("#wrapper{max-width:%dpx;}\n",$themew));

    if (($val = weaverii_getopt('wii_wrapper_padding')) != '') {			// wrapper padding
        weaverii_f_write($sout, sprintf("#wrapper {padding: %dpx;}\n", $val));
    }

    $sb_areas = array ('primary' => '#sidebar_primary,.mobile_widget_area', 'right' => '#sidebar_right', 'left' => '#sidebar_left',
	'top' => '.sidebar_top', 'bottom' => '.sidebar_bottom',
	'footer' => '#first,#second,#third,#fourth', 'widget'=>'.widget');
    /* _bgcolor,  _margin_T, _margin_B, _std_border */

    foreach ($sb_areas as $area => $tag) {
	$id = 'wii_widget_' . $area;
	if ($tag == '.sidebar_top') $tag .= ',.sidebar_extra';	// extra rule for extra sidebar

	weaverii_put_bgcolor($sout, $id . '_bgcolor', $tag);
	$mt = weaverii_getopt($id . '_margin_T');
	$mb = weaverii_getopt($id . '_margin_B');
	// make each separate because might not want to override defaults
	$rule = '';
	$rule .= $mt ? 'margin-top:' . $mt . 'px;' : '';
	$rule .= $mb ? 'margin-bottom:' . $mb . 'px;' : '';
	if ($rule) {
	    weaverii_f_write($sout, $tag . '{' . $rule . "}\n");
	}
	if (weaverii_getopt_checked($id . '_std_border')) {
	    if (!weaverii_getopt_checked('wii_useborders') || $tag == '.widget')
		weaverii_f_write($sout, sprintf("%s {border: %dpx %s %s;}\n",$tag,$b_w, $b_s, $b_c));
	}
    }

    // 'wii_widget_top_indent_int', bottom
    if (($val = weaverii_getopt('wii_widget_top_indent_int')) != '') {
	weaverii_f_write($sout, sprintf(".sidebar_top,.sidebar_extra {margin-left: %.3f%%;margin-right: %.3f%%;}\n", $val,$val));
    }
        if (($val = weaverii_getopt('wii_widget_bottom_indent_int')) != '') {
	weaverii_f_write($sout, sprintf(".sidebar_bottom {margin-left: %.3f%%;margin-right: %.3f%%;}\n", $val,$val));
    }

    // widget areas and widget margins interact - need to adjust depending on what widget margin are

    $ww_mtop = weaverii_getopt('wii_widget_widget_margin_T');
    $ww_mbot = weaverii_getopt('wii_widget_widget_margin_B');
    $w_pad = weaverii_getopt("wii_widget_padding_int");

    if ($w_pad || $ww_mtop || $ww_mbot) {	// either set top val or need to adjust
	$wmbot = $ww_mbot ? $ww_mbot : '10';

	if ($w_pad == '') $w_pad = '10';
	$t = '0'; $b = '0';
	if ($w_pad != '0') {
	    $t = $w_pad - $ww_mtop;
	    if ($t < 0) $t = '0';
	    $b = $w_pad - $wmbot;
	    if ($b < 0) $b = '0';
	}
	weaverii_f_write($sout, sprintf(".widget-area {padding: %dpx %dpx %dpx %dpx;}\n", $t,$w_pad,$b,$w_pad));
    }


    if ($ww_mtop && $ww_mbot) {	// combine?
	weaverii_f_write($sout, sprintf(".widget {margin-bottom: %dpx;margin-top: %dpx;}\n", $ww_bot,$ww_top));
    } else {
	if ($ww_mtop != '') weaverii_f_write($sout, sprintf(".widget {margin-top: %dpx;}\n", $ww_top));
	if ($ww_mbot != '') weaverii_f_write($sout, sprintf(".widget {margin-bottom: %dpx;}\n", $ww_bot));
    }

// 'wii_widget_widget_padding_int'
    if (($val = weaverii_getopt("wii_widget_widget_padding_int")) != '') {
	weaverii_f_write($sout, sprintf(".widget {padding: %dpx;}\n", $val));
    }


// The widths: 'wii_theme_width_int' 'sb_right_2_col_width_int' 'sb_left_1_col_width_int' 'sb_left_2_col_width_int'
// 'sb_split_left_width_int' 'sb_split_right_width_int' 'sb_2_left_area_int'

    $sbw = weaverii_getopt('sb_default_width_int');
    if ($sbw != '') {
	$sbwl = $sbw; $sbwr = $sbw;
	weaverii_f_write($sout,
	    sprintf("#container_wrap.right-1-col{width:%.3f%%;} #sidebar_wrap_right.right-1-col{width:%.3f%%;} \n",100-$sbw,$sbw));
	weaverii_f_write($sout,
	    sprintf("#container_wrap.right-2-col, #container_wrap.right-2-col-bottom{width:%.3f%%;} #sidebar_wrap_right.right-2-col, #sidebar_wrap_right.right-2-col-bottom{width:%.3f%%;}\n",100-$sbw,$sbw));
	weaverii_f_write($sout,
	    sprintf("#container_wrap.left-1-col{width:%.3f%%;} #sidebar_wrap_left.left-1-col{width:%.3f%%;}\n",100-$sbw,$sbw));
	weaverii_f_write($sout,
	    sprintf("#container_wrap.left-2-col, #container_wrap.left-2-col-bottom{width:%.3f%%;} #sidebar_wrap_left.left-2-col,#sidebar_wrap_left.left-2-col-bottom{width:%.3f%%;}\n",100-$sbw,$sbw));
	weaverii_f_write($sout,
	    sprintf("#container_wrap{width:%.3f%%;} #sidebar_wrap_left{width:%.3f%%;} #sidebar_wrap_right{width:%.3f%%;}\n",
	    100-$sbwl-$sbwr,$sbwl,$sbwr));
    } else {

    $sbw = weaverii_getopt('sb_right_1_col_width_int');	//+ ALL
    if ($sbw) {
	weaverii_f_write($sout,
	    sprintf("#container_wrap.right-1-col{width:%.3f%%;} #sidebar_wrap_right.right-1-col{width:%.3f%%;}\n",100-$sbw,$sbw));
    }
    $sbw = weaverii_getopt('sb_right_2_col_width_int');
    if ($sbw != '') {
	weaverii_f_write($sout,
	    sprintf("#container_wrap.right-2-col,#container_wrap.right-2-col-bottom{width:%.3f%%;} #sidebar_wrap_right.right-2-col,#sidebar_wrap_right.right-2-col-bottom{width:%.3f%%;}\n",100-$sbw,$sbw));
    }
    $sbw = weaverii_getopt('sb_left_1_col_width_int');
    if ($sbw != '') {
	weaverii_f_write($sout,
	    sprintf("#container_wrap.left-1-col{width:%.3f%%;} #sidebar_wrap_left.left-1-col{width:%.3f%%;}\n",100-$sbw,$sbw));
    }
    $sbw = weaverii_getopt('sb_left_2_col_width_int');
    if ($sbw != '') {
	weaverii_f_write($sout,
	    sprintf("#container_wrap.left-2-col,#container_wrap.left-2-col-bottom{width:%.3f%%;} #sidebar_wrap_left.left-2-col,#sidebar_wrap_left.left-2-col-bottom{width:%.3f%%;}\n",100-$sbw,$sbw));
    }

    $sbwl = weaverii_getopt('sb_split_left_width_int');
    $sbwr = weaverii_getopt('sb_split_right_width_int');
    if ($sbwl != '' && $sbwr != '') {
	weaverii_f_write($sout,
	    sprintf("#container_wrap{width:%.3f%%;} #sidebar_wrap_left{width:%.3f%%;} #sidebar_wrap_right{width:%.3f%%;}\n",
	    100-$sbwl-$sbwr,$sbwl,$sbwr));
    }
    } // end no default specified

// Margins for sidebar widget areas

    $m = weaverii_getopt('wii_sidbar_widget_margins_L');
    if ($m != '')
	weaverii_f_write($sout,
	    sprintf("#sidebar_primary,#sidebar_left,#sidebar_right,.mobile_widget_area {margin-left:%spx !important;}\n",$m));
    $m = weaverii_getopt('wii_sidbar_widget_margins_R');
    if ($m != '')
	weaverii_f_write($sout,
	    sprintf("#sidebar_primary,#sidebar_left,#sidebar_right,.mobile_widget_area {margin-right:%spx !important;}\n",$m));


    $sbw = weaverii_getopt('sb_2_left_area_int');
    if ($sbw != '') {
	weaverii_f_write($sout,
	    sprintf("#sidebar_wrap_2_left_left, #sidebar_wrap_2_right_left {width:%.3f%%;margin-right:1%%;}\n#sidebar_wrap_2_left_right, #sidebar_wrap_2_right_right {width:%.3f%%;}\n",$sbw-1,100-$sbw));
    }

    $t = weaverii_getopt('wii_site_margins_T');
    $b = weaverii_getopt('wii_site_margins_B');
    $l = weaverii_getopt('wii_site_margins_L');
    $r = weaverii_getopt('wii_site_margins_R');

    if ($t != '' || $b != '' || $l != '' || $r != '') {
	if ($t == '') $t = 20;	// default if not set
	if ($b == '') $b = 20;
	if ($l == '') $l = 20;
	if ($r == '') $r = 20;
	weaverii_f_write($sout, sprintf("body {padding: %dpx %dpx %dpx %dpx; }\n",$t,$r,$b,$l));
    }


// === HEADER HORIZONTAL WIDGET AREA

    weaverii_put_bgcolor($sout,'_wii_hdr_widg_bgcolor','#sidebar_header');
    if (($val = weaverii_getopt_color('_wii_hdr_widg_h_int'))) {
	weaverii_f_write($sout, sprintf("#sidebar_header {height:".$val."px; }\n"));
    }
    if (($val = weaverii_getopt_color('_wii_hdr_widg_fontsize'))) {
	weaverii_f_write($sout, sprintf("#sidebar_header {font-size:".$val."%%; }\n"));
    }
    for ($i = 1; $i < 5 ; $i++) {
	weaverii_put_bgcolor($sout,'_wii_hdr_widg_' . $i .'_bgcolor','#sidebar_header .header-widget-' . $i);
	if (($val = weaverii_getopt('_wii_hdr_widg_' . $i .'_w_int')) != '') {		// wii_after_header
	    if ($val == '0')
		weaverii_f_write($sout, sprintf(".sidebar-header .header-widget-%d {display:none;}\n", $i));
	    else {
		weaverii_f_write($sout, sprintf(".sidebar-header .header-widget-%d {width:%d%% !important;}\n", $i, $val));
	    }
	}
	if (($valm = weaverii_getopt('_wii_hdr_widg_' . $i .'_w_mobile_int')) != '') {		// wii_after_header
	    if ($valm == '0')
		weaverii_f_write($sout, sprintf(".sidebar-header-mobile .header-widget-%d {display:none;}\n", $i));
	    else
		weaverii_f_write($sout, sprintf(".sidebar-header-mobile .header-widget-%d {width:%d%%;}\n", $i, $valm));
	} else if ($val  != '') {	// if not a sidebar value, then use regular value
	    if ($val == '0')
		weaverii_f_write($sout, sprintf(".sidebar-header-mobile .header-widget-%d {display:none;}\n", $i));
	    else
		weaverii_f_write($sout, sprintf(".sidebar-header-mobile .header-widget-%d {width:%d%%;}\n", $i, $val));
	}
    }

// =========================== HEADER OPTIONS ===============================

    if (($val = weaverii_getopt("wii_after_header_int")) != '') {		// wii_after_header
	weaverii_f_write($sout, sprintf("#main {padding: %dpx 0 0 0;}\n", $val));
    }

    if (($val = weaverii_getopt('wii_title_font_size')) != '') {			// wii_title_font_size
	weaverii_f_write($sout,sprintf("#site-title {font-size:%.3f%%;}\n",$val));
    }

    if (($val = weaverii_getopt('wii_desc_font_size'))) {			// wii_desc_font_size
	weaverii_f_write($sout,sprintf("#site-description {font-size:%.3f%%;}\n",$val));
    }

/*  wii_title_on_header */

    if (weaverii_getopt_checked('wii_title_on_header')) {
	$tx = 40; $ty = 44; // default values for offsets
	$dx = 48; $dy = 90;
	$val = weaverii_getopt('wii_title_on_header_xy_X'); if ($val != '') $tx = (int) $val;
	$val = weaverii_getopt('wii_title_on_header_xy_Y'); if ($val != '') $ty = (int) $val;
	$val = weaverii_getopt('wii_title_on_header_xy_desc_X'); if ($val != '') $dx = (int) $val;
	$val = weaverii_getopt('wii_title_on_header_xy_desc_Y'); if ($val != '') $dy = (int) $val;

	weaverii_f_write($sout, sprintf("#site-title {overflow:hidden; padding:0; margin:0; position:absolute; left:%dpx; top: %dpx; z-index:20;}\n",$tx,$ty));
	weaverii_f_write($sout, sprintf(".weaver-mobile #site-title {position: relative; z-index:20;}\n",$tx,$ty));
	weaverii_f_write($sout, sprintf("#site-description {overflow:hidden; margin:0; padding:0; clear: both; position:absolute; left: %dpx; top: %dpx; z-index:20;}\n",$dx,$dy));
	$tpc = 99 - (($tx/768)*100);	// force title, description to fit withing tablet width - works for either 768 or 800
	$dpc = 99 - (($dx/768)*100);
	weaverii_f_write($sout, sprintf(".weaver-tablet #site-title.title-on-header{white-space:nowrap;margin-left:0;margin-right:0; overflow:hidden;width:%d%%;}",$tpc));
	weaverii_f_write($sout, sprintf(".weaver-tablet #site-description.title-on-header{margin-left:0;margin-right:0;white-space:nowrap;overflow:hidden;width:%d%%;}",$dpc));
    }

    if (($val = weaverii_getopt('wii_header_width_int')) != '') { // doesn't work right if use max-width
	if ($val > $themew) {
	    weaverii_f_write($sout, sprintf("#branding {width:%dpx; margin-left:-%dpx;}\n",$val, ($val-$themew)/2));
	} else if ($val != $themew) {
	    weaverii_f_write($sout, sprintf("#branding {width:%dpx; margin-left:%dpx;}\n",$val, ($themew-$val)/2));
	}
    }


// =========================== FOOTER OPTIONS ===============================

/*  wii_footer_border_color  */
    $fh = weaverii_getopt('wii_footer_border_int');
    if ($fh == '') $fh = '4';
    $fc = weaverii_getopt_color('wii_footer_border_color');
    if ($fc == '') $fc = '#888';

    if ($fh != '4' || $fc != '#888') {	// write if not defaults
	weaverii_f_write($sout, sprintf("#colophon { border-top: %dpx solid %s;  }\n",$fh, $fc));
    }
    if (($val = weaverii_getopt("wii_footer_border_color_css"))) {
	weaverii_css_css($sout,'#colophon',$val);
    }

    if (($val = weaverii_getopt('wii_footer_width_int')) != '') {
	if ($val > $themew) {
	    weaverii_f_write($sout, sprintf("#colophon {width:%dpx; margin-left:-%dpx;}\n",$val, ($val-$themew)/2));
	}
    }

    if (weaverii_getopt('_wii_hide_poweredby'))
	weaverii_f_write($sout, "#site-info {width:80%;}\n");

// =========================== MENU OPTIONS ===============================
/*
text_color = 0.213 * this.rgb[0] +
	    0.715 * this.rgb[1] +
	    0.072 * this.rgb[2]
	    < 0.5 ? '#FFF' : '#000';
*/


    weaverii_put_rule_if_checked($sout,'wii_bold_menu','.menu_bar a, .mobile_menu_bar a {font-weight:bold;}');	// weaverii_put_rule_if_checked
    weaverii_put_rule_if_checked($sout,'wii_bold_submenu','.menu_bar ul ul a {font-weight:bold;}');	// wii_bold_submenu
    weaverii_put_rule_if_checked($sout,'wii_menubar_curpage_em',
	'.menu_bar .current_page_item > a, .menu_bar .current_page_ancestor > a {font-style:italic;}');	// wii_menubar_curpage_em
    weaverii_put_rule_if_checked($sout,'wii_menubar_curpage_bold',
	'.menu_bar .current_page_item > a, .menu_bar .current_page_ancestor > a {font-weight:bold;}');

    if (($val = weaverii_getopt('wii_menu_height_int')) != '') {		//+ wii_menu_height_int
	weaverii_f_write($sout,sprintf("#nav-bottom-menu, #nav-top-menu {min-height:%dpx;}\n",$val));
	weaverii_f_write($sout,sprintf(".menu_bar a {line-height:%dpx !important;}\n",$val));
	weaverii_f_write($sout,sprintf(".menu_bar ul ul a {line-height:%dpx !important;}\n",$val-20));
	weaverii_f_write($sout,sprintf(".menu_bar ul ul {top:%dpx;}\n",$val));
    }

    $val = weaverii_getopt('wii_menu_leftpad_int');	//+
    if ($val !== false && $val != '') {
	weaverii_f_write($sout,sprintf("#access .menu {padding-left:%spx;}\n",$val));
    }
    $val = weaverii_getopt('wii_menu_leftpad2_int');	//+
    if ($val !== false && $val != '') {
	weaverii_f_write($sout,sprintf("#access2 .menu {padding-left:%spx;}\n",$val));
    }

    if (($val = weaverii_getopt('wii_menu_spacing_int')) != '') {	//+
	weaverii_f_write($sout, sprintf(".menu_bar a {padding: 0 %dpx;}\n",$val));
    }

    $separator_width = 2;
    $val = weaverii_getopt('wii_separator_width_int');	//+
    if ((int) $val > 0) $separator_width = $val;

    $separator_color = weaverii_getopt('wii_menubar_text_color');
    if ($separator_color == '') $separator_color = '#FFF';

    if (weaverii_getopt_checked('wii_menubar_sep')) {	//+
	weaverii_f_write($sout,sprintf(".menu_bar ul li {border-left:%dpx solid %s;}\n",
	    $separator_width,$separator_color));
	weaverii_f_write($sout,sprintf(".menu_bar ul li:last-child, .menu_bar ul ul li {border-right:%dpx solid %s;}\n",
	    $separator_width,$separator_color));

	weaverii_f_write($sout,".menu_bar ul ul ul li {margin-left:0px;}\n");
    }

    $separator_color = weaverii_getopt('wii_submenubar_text_color');
    if ($separator_color == '') $separator_color = '#FFF';
    if (weaverii_getopt('wii_submenu_bars')) {	//+
	weaverii_f_write($sout,sprintf(".menu_bar ul ul li {border-left:%dpx solid %s;border-right:%dpx solid %s;border-bottom:%dpx solid %s;}\n",
	       $separator_width,$separator_color,$separator_width,$separator_color,$separator_width,$separator_color));
	weaverii_f_write($sout,sprintf(".menu_bar ul ul li:first-child{border-top:%dpx solid %s;}\n",
	       $separator_width,$separator_color));
    }
    $val = weaverii_getopt('wii_menu_liwidth');	//+
    if ((int) $val > 0) {
	weaverii_f_write($sout,sprintf(".menu_bar ul li{width:%dpx;}\n",$val));
    }
    if (weaverii_getopt_checked('wii_submenu_dotted')) {	//+
	$separator_color = weaverii_getopt('wii_submenubar_text_color');
	if ($separator_color == '') $separator_color = '#000';
	weaverii_f_write($sout, sprintf(".menu_bar ul ul a {border-bottom: 1px dotted %s;}\n",$separator_color));
    }

    /*  wii_gradient_menu  */
    if (weaverii_getopt('wii_gradient_menu')) {
	$urlfade = weaverii_relative_url('images/theme/fade.png');
	$urlfadeup = weaverii_relative_url('images/theme/fadeup.png');
	weaverii_f_write($sout, sprintf(".menu_bar, .weaveriip_vertical_menu .menu_bar li { background-image: url(%s);}\n", $urlfade));

	weaverii_f_write($sout, sprintf(".menu_bar ul ul a, .menu_bar li:hover > a, .menu_bar ul ul :hover > a { background-image: url(%s);}\n",
	       $urlfadeup));
    }

    if (weaverii_getopt_checked('wii_menu_shadow')) {
	if (($headerw = weaverii_getopt('wii_footer_width_int')) == '')	//+
	    $headerw = $themew;
	weaverii_f_write($sout, sprintf('.menu_bar {-webkit-box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 2px;
-moz-box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 2px; box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 2px;margin-left:1px;max-width:%dpx;}',$headerw-2));
    }


/*	wii_use_superfish	*/
    //if (!weaverii_getopt('wii_use_superfish')) {
    //		need to fix up access a if NOT using SuperFish - at least with Weaver, maybe not here
    //	weaverii_f_write($sout, sprintf(".menu_bar a { padding-left:10px; padding-right:10px;}\n"));
    // }
    if (weaverii_getopt('wii_use_superfish') || weaverii_mobile_usesf()) {
	weaverii_f_write($sout,".menu_bar ul ul a {padding:10px 20px;}\n"); // make room for arrow
    	$arrows = weaverii_getopt('wii_superfish_arrows');
	if ($arrows && $arrows != '000000') {	/* assumes 000000 is default arrow color */
	    if (is_rtl() || WEAVERII_FORCE_RTL)
		$url = weaverii_relative_url('js/superfish/images/rtl-arrows-' . $arrows . '.png');
	    else
		$url = weaverii_relative_url('js/superfish/images/arrows-' . $arrows . '.png');
	    weaverii_f_write($sout,
		sprintf(".sf-sub-indicator {background: url(%s) no-repeat -10px -100px;}\n",$url));
	}
    }

    weaverii_put_color($sout,'wii_menubar_text_color','.menu_bar, .menu_bar a,.menu_bar a:visited,.mobile_menu_bar a');
    weaverii_put_bgcolor($sout,'wii_menubar_hover_bgcolor','.menu_bar li:hover > a, .menu_bar a:focus');	// wii_menubar_hoverbg_color
    weaverii_put_color($sout,'wii_menubar_hover_color','.menu_bar li:hover > a, .menu_bar a:focus');	// wii_menubar_hover_color
    weaverii_put_bgcolor($sout,'wii_submenubar_bgcolor','.menu_bar ul ul a');	// wii_submenubar_bgcolor
    weaverii_put_color($sout,'wii_submenubar_text_color','.menu_bar ul ul a,.menu_bar ul ul a:visited');	// wii_submenubar_text_color
    weaverii_put_bgcolor($sout,'wii_submenubar_hover_bgcolor','.menu_bar ul ul :hover > a');	// wii_submenubar_hover_bgcolor
    weaverii_put_color($sout,'wii_submenubar_hover_color','.menu_bar ul ul :hover > a');	// wii_submenubar_hover_color
    weaverii_put_color($sout,'wii_menubar_curpage_color',
	'.menu_bar .current_page_item > a, .menu_bar .current_page_ancestor > a',true);	// wii_menubar_curpage_color

    weaverii_put_bgcolor($sout,'wii_menubar_bgcolor','.menu_bar, .mobile_menu_bar');	// wii_menubar_bgcolor

/* info bar */
//  wii_info_color wii_info_padding

    weaverii_put_bgcolor($sout,'wii_infob_bgcolor','#infobar');
    weaverii_put_color($sout,'wii_infob_color','#infobar');
    if (($val = weaverii_getopt('wii_infob_padding_L')) != '') {		// wvr_info_padding_L
	    weaverii_f_write($sout,sprintf("#infobar {padding-left:%dpx;}\n",$val));
	}
    if (($val = weaverii_getopt('wii_infob_padding_R')) != '') {		// wvr_info_padding_R
	    weaverii_f_write($sout,sprintf("#infobar {padding-right:%dpx;}\n",$val));
	}
    if (($val = weaverii_getopt('wii_infob_padding_T')) != '') {		// wvr_info_padding_T
	    weaverii_f_write($sout,sprintf("#infobar {padding-top:%dpx;}\n",$val));
	}
    if (($val = weaverii_getopt('wii_infob_padding_B')) != '') {		// wvr_info_padding_B
	    weaverii_f_write($sout,sprintf("#infobar {padding-bottom:%dpx;}\n",$val));
	}

/* vertical menu */
    $mb_bg = weaverii_getopt('wii_menubar_bgcolor');		// Build the simple vertical menu based on existing
    $mb_sub = weaverii_getopt('wii_menubar_bgcolor');		// theme menu colors.
    $mb_hover = weaverii_getopt('wii_menubar_hover_bgcolor');
    $text_color = weaverii_getopt('wii_menubar_text_color');
    $text_hover = weaverii_getopt('wii_menubar_hover_color');
    $cur_page = weaverii_getopt('wii_menubar_curpage_color');
    $cur_page_css = weaverii_getopt('wii_menubar_curpage_color_css');
    if (weaverii_getopt('wii_bold_menu')) $bold = 'font-weight:bold;';
    else $bold = '';

    weaverii_f_write($sout,sprintf(".mobile-menu-link {border-color:%s;}\n",$text_color));

    $menu = sprintf(".menu-vertical {clear:both;background:transparent;margin:0;width:100%% !important;overflow:hidden !important;border-bottom:3px solid %s;border-top:1px solid %s;%s;}
.menu-vertical ul {margin: 0 !important; padding: 0 !important; list-style-type: none !important;  list-style-image:none !important;font-family: inherit;}
.menu-vertical li a, .menu-vertical a:visited {color: %s !important;  background-color: %s !important;
 display: block !important; padding: 5px 10px !important; text-decoration: none !important;
 border-top:2px solid %s;}
.menu-vertical a:hover,.menu-vertical a:focus {color: %s !important; background-color: %s !important;text-decoration: none !important;}
.menu-vertical ul ul li { margin: 0 !important; }
.menu-vertical ul ul a {color: %s !important; background-color: %s !important;
 display: block !important; padding: 4px 5px 4px 25px !important; text-decoration: none !important;border:0;
 border-top:1px solid %s;}
.menu-vertical ul ul a:hover {color: %s !important; background-color: %s !important; text-decoration: none !important;}
.menu-vertical ul ul ul a {padding: 4px 5px 4px 35px !important;}
.menu-vertical ul ul ul ul a {padding: 4px 5px 4px 45px !important;}
.menu-vertical ul ul ul ul ul a {padding: 4px 5px 4px 55px !important;}
.menu-vertical ul li.current_page_item > a, .menu-vertical ul li.current-menu-item > a  {color:%s !important;}\n",
$text_color, $text_color, $bold, $text_color, $mb_bg, $text_color, $text_hover, $mb_hover,
$text_color, $mb_sub, $text_color, $text_hover, $mb_hover, $cur_page );
    if ($cur_page_css)
        $menu .= sprintf(".menu-vertical ul li.current_page_item > a, .menu-vertical ul li.current-menu-item > a %s\n", $cur_page_css);
    if (weaverii_getopt('wii_menubar_curpage_em'))
        $menu .= ".menu-vertical ul li.current_page_item > a, .menu-vertical ul li.current-menu-item > a {font-style:italic;}\n";
    if (weaverii_getopt('wii_menubar_curpage_bold'))
        $menu .= ".menu-vertical ul li.current_page_item > a, .menu-vertical ul li.current-menu-item > a {font-weight:bold;}\n";

    weaverii_f_write($sout,$menu);

// =========================== CONTENT AREAS ===============================


/*   wii_entrytitle_size_int */
    if (($val = weaverii_getopt('wii_entrytitle_size_int')) != '') {
	    weaverii_f_write($sout,sprintf("#content .entry-title {font-size:%d%%;}\n",$val));
	}

    $val = weaverii_getopt('wii_contentlist_bullet');
    if ($val != '' && $val != 'disc') {
	if ($val == 'custom') {
	    $url = weaverii_getopt('wii_contentlist_bullet_custom_url');
	    if ($url != '')
		weaverii_f_write($sout, sprintf("#content ul {list-style-image:url(%s);}\n",$url));
	} else {
	    weaverii_f_write($sout, sprintf("#content ul {list-style-type:%s;}\n",$val));
	}
    }

    $val = (int)weaverii_getopt('wii_header_underline_int');       /* bar under headers */
    if ($val != '' && $val != 0) {
        $titleColor = weaverii_getopt('wii_page_title_color');
	if ($titleColor == '') $titleColor = '#222';
        weaverii_f_write($sout, sprintf(".entry-title {border-bottom: $val"."px solid $titleColor;}\n"));
    }


    /*  wii_content_color  */
    weaverii_put_color($sout,'wii_content_color','#content, .entry-content h1, .entry-content h2');

    /*  wii_content_headings_color  */
    weaverii_put_color($sout,'wii_content_headings_color',
	'#content h1, #content h2, #content h3, #content h4, #content h5, #content h6, #content dt, #content th,
h1, h2, h3, h4, h5, h6,.entry-author-info h2');


/*  wii_page_title_color - MUST come after wii_content_headings_color! */

    weaverii_put_color($sout, 'wii_page_title_color','#content .entry-title');

/* Comments */

    weaverii_put_color($sout, 'wii_comment_headings_color', '#comments-title h3, #comments-title h4, #respond h3' );
    weaverii_put_bgcolor($sout, 'wii_comment_content_bgcolor', '.commentlist li.comment, #respond' );
    weaverii_put_bgcolor($sout,'wii_comment_submit_bgcolor','#respond input#submit');
    weaverii_put_rule_if_checked($sout,'wii_form_allowed_tags','#commentform .form-allowed-tags {display:block;}');
    weaverii_put_rule_if_checked($sout,'wii_hide_comment_bubble', '#comments-title {background-image:none;padding-left:0px;font-size:140%;}');
    weaverii_put_rule_if_checked($sout,'wii_hide_comment_hr', 'hr.comments-hr {display:none;}');
    weaverii_put_rule_if_checked($sout,'wii_hide_comment_borders', '.commentlist li.comment, #respond,.commentlist li.comment .comment-author img.avatar {border:none;}');

/*  wii_weaverii_tables  */
    $table = weaverii_getopt('wii_weaverii_tables');

    if ($table == 'wide') {	// make backward compatible with 1.4 and before when Twenty Ten was default
	weaverii_f_write($sout, sprintf("#content table {border: 1px solid #e7e7e7;margin: 0 -1px 24px 0;text-align: left;width: 100%%;}
#content tr th, #content thead th {color: #888;font-size: 12px;font-weight: bold;line-height: 18px;padding: 9px 24px;}
#content tr td {border-style:none; border-top: 1px solid #e7e7e7; padding: 6px 24px;}
#content tr.odd td {background: #f2f7fc;}\n"));
    } else
    if ($table == 'bold') {
	weaverii_f_write($sout, sprintf("#content table {border: 2px solid #888;}
#content tr th, #content thead th {font-weight: bold;}
#content tr td {border: 1px solid #888;}\n"));
    } else
    if ($table == 'noborders') {
	weaverii_f_write($sout, sprintf("#content table {border-style:none;}
#content tr th, #content thead th {font-weight: bold;border-bottom: 1px solid #888;background-color:transparent;}
#content tr td {border-style:none;}\n"));
    } else
    if ($table == 'fullwidth') {
	weaverii_f_write($sout, sprintf("#content table {width:100%%;}
#content tr th, #content thead th {font-weight:bold;}\n"));
    } else
    if ($table == 'plain') {
	weaverii_f_write($sout, sprintf(
"#content table {border: 1px solid #888;text-align:left;margin: 0 0 0 0;width:auto;}
#content tr th, #content thead th {color: inherit;background:none;font-weight:normal;line-height:normal;padding:4px;}
#content tr td {border: 1px solid #888; padding:4px;}\n"));
    }

    if (($val = weaverii_getopt('wii_media_lib_border_int')) != '') {		// wvr_post_padding_L
	weaverii_f_write($sout,sprintf("#content .size-full, #content .size-large, #content .size-medium, #content .size-thumbnail,#content .size-thumbnail, #content .gallery img,#content .gallery-thumb img,.entry-attachment img,#content .wp-caption img {padding:%dpx;}\n",$val));
    }

    if (($val = weaverii_getopt('wii_featured_page_width')) != '') {
	weaverii_f_write($sout,sprintf("#content .page .featured-image .attachment-thumbnail {height: auto; width:%spx !important;}\n",$val));
    }

    if (($val = weaverii_getopt('wii_featured_blog_width')) != '') {
	weaverii_f_write($sout,sprintf("#content .post .featured-image .attachment-thumbnail {height: auto; width:%spx !important;}\n",$val));
    }
    if (($val = weaverii_getopt('wii_featured_single_width')) != '') {
	weaverii_f_write($sout,sprintf("#content .featured-image .attachment-thumbnail-single {height: auto; max-width:%spx !important;}\n",$val));
    }

    if (weaverii_getopt_checked('wii_hide_img_borders')) {
	weaverii_f_write($sout,"#content .size-full, #content .size-large, #content .size-medium, #content .size-thumbnail,#content .size-thumbnail, #content .gallery img,#content .gallery-thumb img,.entry-attachment img {background-color:transparent;}\n");
	weaverii_f_write($sout, "#content img,#author-avatar img {-webkit-box-shadow: none !important; -moz-box-shadow: none !important;box-shadow: none !important;}\n");
    }
    if (weaverii_getopt_checked('wii_hide_img_shadows') && !weaverii_getopt_checked('wii_hide_img_borders')) {
	weaverii_f_write($sout, "#content img,#author-avatar img {-webkit-box-shadow: none !important; -moz-box-shadow: none !important;box-shadow: none !important;}\n");
    }

    if (($val = weaverii_getopt('wii_content_padding_L')) != '') {		// wvr_post_padding_L
	weaverii_f_write($sout,sprintf("#content {padding-left:%dpx;}\n",$val));
    }
    if (($val = weaverii_getopt('wii_content_padding_R')) != '') {		// wvr_post_padding_R
	weaverii_f_write($sout,sprintf("#content {padding-right:%dpx;}\n",$val));
    }
    if (($val = weaverii_getopt('wii_content_padding_T')) != '') {		// wvr_post_padding_T
	weaverii_f_write($sout,sprintf("#content {padding-top:%dpx;}\n",$val));
    }
    if (($val = weaverii_getopt('wii_content_padding_B')) != '') {		// wvr_post_padding_B
	weaverii_f_write($sout,sprintf("#content {padding-bottom:%dpx;}\n",$val));
    }
   /*  wii_caption_color  */
    weaverii_put_color($sout,'wii_caption_color','#content .wp-caption p.wp-caption-text, #content .gallery .gallery-caption,.entry-attachment .entry-caption');

    /* wii_media_lib_border */

    weaverii_put_bgcolor($sout,'wii_media_lib_border_color',
'#content .size-full, #content .size-large, #content .size-medium, #content .size-thumbnail,#content .size-thumbnail, #content .gallery img,#content .gallery-thumb img,.entry-attachment img,#content .wp-caption img');

// =========================== POST SPECIFIC AREAS ===============================

    weaverii_put_rule_if_checked($sout, 'wii_show_comments_closed','.nocomments {display:block;}');

    weaverii_put_rule_if_checked($sout, 'wii_nav_show_first','#nav-above{display:block;}'); // put this one first, so hide can override
    weaverii_put_rule_if_checked($sout, 'wii_nav_hide_above','#nav-above,.paged #nav-above{display:none;margin:0;}');
    weaverii_put_rule_if_checked($sout, 'wii_nav_hide_below','#nav-below{display:none;margin:0;}');

    if (weaverii_getopt('wii_single_nav_style') == 'hide' || weaverii_getopt_checked('wii_single_nav_hide_above')) {
	weaverii_f_write($sout,".single #nav-above{display:none;margin:0;}\n");
    }
    if (weaverii_getopt('wii_single_nav_style') == 'hide' || weaverii_getopt_checked('wii_single_nav_hide_below')) {
	weaverii_f_write($sout,".single #nav-below{display:none;margin:0;}\n");
    }
    $nav = weaverii_getopt('wii_nav_style');	// paged can take more than 50%
    if ($nav == 'paged_left')
	weaverii_f_write($sout,".nav-previous {width:95%;}\n");
    if ($nav == 'paged_right')
	weaverii_f_write($sout,".nav-next {width:95%;}\n");

    weaverii_put_rule_if_checked($sout, 'wii_mobile_post_info_hide_top','.weaver-mobile .entry-meta{display:none;}');
    weaverii_put_rule_if_checked($sout, 'wii_mobile_post_info_hide_bottom','.weaver-mobile .entry-utility{display:none;}');

    /*  wii_stickypost_bgcolor  */
    weaverii_put_bgcolor($sout,'wii_stickypost_bgcolor', '.home .sticky, #entry-author-info, #container.page-with-posts .sticky, #container.index-posts .sticky');

    if (($val = weaverii_getopt('wii_post_padding_L')) != '') {		// wvr_post_padding_L
	weaverii_f_write($sout,sprintf("#content .post {padding-left:%dpx;}\n",$val));
    }
    if (($val = weaverii_getopt('wii_post_padding_R')) != '') {		// wvr_post_padding_R
	weaverii_f_write($sout,sprintf("#content .post {padding-right:%dpx;}\n",$val));
    }
    if (($val = weaverii_getopt('wii_post_padding_T')) != '') {		// wvr_post_padding_T
	weaverii_f_write($sout,sprintf("#content .post {padding-top:%dpx;}\n",$val));
    }
    if (($val = weaverii_getopt('wii_post_padding_B')) != '') {		// wvr_post_padding_B
	weaverii_f_write($sout,sprintf("#content .post {padding-bottom:%dpx;}\n",$val));
    }

    weaverii_put_color($sout,'wii_post_format_color','#content .entry-format');	// wii_post_format_color

    weaverii_put_color($sout,'wii_info_color','.entry-meta, .entry-content label, .entry-utility');		/*  wii_info_color  */

    weaverii_put_rule_if_checked($sout, 'wii_post_hide_single_author','.single-author .entry-meta .by-author {display:none;}');

// ============================== WIDGET AREAS ===================================


    $val = weaverii_getopt('wii_widgetlist_bullet');
    if ($val != '' && $val != 'disc') {
	if ($val == 'custom') {
	    $url = weaverii_getopt('wii_widgetlist_bullet_custom_url');
	    if ($url != '')
		weaverii_f_write($sout, sprintf(".widget ul {list-style-position:inside; list-style-image:url(%s);}\n",$url));
	} else {
	    weaverii_f_write($sout, sprintf(".widget ul {list-style-type:%s;}\n",$val));
	}
	if ($val == 'none') {
	    weaverii_f_write($sout, sprintf(".widget-area ul li {margin-left:1em;}\n"));
	}
    }

// ================================== FONTS =====================================

    if (($val = weaverii_getopt('wii_site_fontsize_int')) != '') {		// idxxxx
	    weaverii_f_write($sout,sprintf("body {font-size:%dpx;}\n",$val));
    }
    if (($val = weaverii_getopt('wii_content_font')) != '') {		// idxxxx
	    weaverii_f_write($sout,sprintf("body {font-family:%s;}\n",$val));
    }
    if (($val = weaverii_getopt('wii_title_font')) != '') {		// idxxxx
	    weaverii_f_write($sout,sprintf("h3#comments-title,h3#reply-title,.menu_bar,.mobile_menu_bar,
#author-info,#infobar,#nav-above, #nav-below,#cancel-comment-reply-link,.form-allowed-tags,
#site-info,#site-title,#wp-calendar,#comments-title,.comment-meta,.comment-body tr th,.comment-body thead th,
.entry-content label,.entry-content tr th,.entry-content thead th,.entry-format,.entry-meta,.entry-title,
.entry-utility,#respond label,.navigation,.page-title,.pingback p,.reply,.widget-title,
.wp-caption-text,input[type=submit] {font-family:%s;}\n",$val));
    }

// ================================ COLORS ===================================
// Colors need to go last because they might have CSS +
   /* background areas */

    weaverii_put_bgcolor($sout,'wii_body_bgcolor','body');		// body
    weaverii_put_color($sout,'wii_body_color','body');		// body
    weaverii_put_bgcolor($sout,'wii_page_bgcolor','#wrapper');	// #wrapper
    weaverii_put_bgcolor($sout,'wii_main_bgcolor','#main');	// #main
    weaverii_put_bgcolor($sout,'wii_container_bgcolor','#container_wrap');	// #container
    weaverii_put_bgcolor($sout,'wii_content_bgcolor','#content');	// #content
    weaverii_put_bgcolor($sout,'wii_post_bgcolor','.post');	// .post
    weaverii_put_bgcolor($sout,'wii_header_bgcolor','#branding');	// #header
    weaverii_put_bgcolor($sout,'wii_footer_bgcolor','#colophon');	// #footer
    weaverii_put_bgcolor($sout,'wii_footer_widget_bgcolor','#first,#second, #third, #fourth');	// #first,#second, #third, #fourth
    weaverii_put_bgcolor($sout,'wii_hr_color','hr');		// hr
    weaverii_put_bgcolor($sout,'wii_infotop_bgcolor','.entry-meta');	// .entry-meta
    weaverii_put_bgcolor($sout,'wii_infobottom_bgcolor','.entry-utility');	// .entry-utility
    /* input, text area */
    weaverii_put_bgcolor($sout,'wii_input_bgcolor','input, textarea, ins, pre');
    weaverii_put_color($sout,'wii_input_color','input, textarea');

    // Sidebar wrappers

    $sb_bg = array(
    'sb_right_1_col_bgcolor' => '#sidebar_wrap_right.right-1-col',	//+ ALL
    'sb_right_2_col_bgcolor' => '#sidebar_wrap_right.right-2-col,#sidebar_wrap_right.right-2-col-bottom',
    'sb_left_1_col_bgcolor' => '#sidebar_wrap_left.left-1-col',
    'sb_left_2_col_bgcolor' => '#sidebar_wrap_left.left-2-col,#sidebar_wrap_left.left-2-col-bottom',
    'sb_split_left_bgcolor' => '#sidebar_wrap_left',
    'sb_split_right_bgcolor' => '#sidebar_wrap_right' );

    foreach ($sb_bg as $id => $tag) {
	weaverii_put_bgcolor($sout,$id,$tag);	// #header
    }

   weaverii_put_bgcolor($sout,'sb_container_bgcolor','#container_wrap'); //+ container wrap
   // wii_widget_color wii_widget_title_color
/*  wii_widget_header_underline_int  */

    weaverii_put_color($sout,'wii_widget_color', '.widget');

    $titleColor = weaverii_getopt('wii_widget_title_color');

    if ($titleColor == '') $titleColor = weaverii_getopt('wii_page_title_color');
    if ($titleColor == '') $titleColor = '#222'; /* if they want a border, this is the fallback color */

    if (($val = weaverii_getopt('wii_widget_header_underline_int')) != '') {
        weaverii_f_write($sout, sprintf(".widget-title {border-bottom: $val"."px solid $titleColor; margin-bottom:5px;padding-bottom:3px;}\n"));
     }

/*  wii_widget_item_bgcolor */
    weaverii_put_bgcolor($sout,'wii_widget_widget_bgcolor','.widget-container');	// #wrapper

/*  wii_widget_title_color  */

    if (($wigtitleColor = weaverii_getopt_color('wii_widget_title_color'))) {
	weaverii_css_color($sout,'.widget-title, .widget_search label, #wp-calendar caption', $wigtitleColor);
    }
    if (($wigtitleColor = weaverii_getopt_color('wii_widget_title_color_css'))) {
	weaverii_css_css($sout,'.widget-title', $wigtitleColor);
    }
// site title/description
    if (($val = weaverii_getopt_color('wii_title_color'))) {			// wii_title_color
	weaverii_f_write($sout, sprintf("#site-title a {color: ".$val."; }\n"));
    }
    if (($val = weaverii_getopt('wii_title_color_css'))) {
	weaverii_css_css($sout,'#site-title, #site-title a',$val);
    }
    weaverii_put_color($sout,'wii_desc_color','#site-description');		// wii_desc_color

// ================================ PRO AREAS ===================================

    weaverii_pro_output_style($sout);


   $add_css = weaverii_getopt('wii_add_css');

    if (!empty($add_css))
	weaverii_f_write($sout,$add_css);

    weaverii_f_write($sout, "\n/* end Weaver II CSS */\n");

// ================================ DIAGNOSTICS - LAST ===================================

/*
	if (($val = weaverii_getopt('idxxxx')) != '') {		// idxxxx
	    weaverii_f_write($sout,sprintf("code\n",$val));
	}
*/
}

function weaverii_css_color($sout, $name, $color, $altstyle='') {
        /* output a CSS color rule */
	if ($color == WEAVERII_DEFAULT_COLOR)
	    return;
	weaverii_f_write($sout, sprintf("$name {color: $color;$altstyle}\n"));
}

function weaverii_css_css($sout, $name, $style) {
        /* output a CSS css rule */
	weaverii_f_write($sout, sprintf("%s %s\n",$name, stripslashes($style))); // stripslashes is required artifact from 2010 Weaver II
}

function weaverii_put_link($sout,$id, $a, $avisited, $ahover) {
    weaverii_put_color($sout,$id.'_color',$a);
    weaverii_put_color($sout,$id.'_visited_color',$avisited);
    weaverii_put_color($sout,$id.'_hover_color',$ahover);

    $link_u = weaverii_getopt_checked('wii_link_u');	// always fetch standard link attributes
    $link_em = weaverii_getopt_checked('wii_link_em');
    $link_strong = weaverii_getopt_checked('wii_link_strong');
    if ($id == 'wii_link') {
	weaverii_put_rule_if_checked($sout,'wii_link_u',$ahover . '{text-decoration:underline;}');
	weaverii_put_rule_if_checked($sout,'wii_link_em',$a.'{font-style:italic;}');
	weaverii_put_rule_if_checked($sout,'wii_link_strong',$a . '{font-weight:bold;}');
    } else {
	$def_u = weaverii_getopt_checked($id.'_u');
	$def_em = weaverii_getopt_checked($id.'_em');
	$def_strong = weaverii_getopt_checked($id.'_strong');
	if ($link_u)
	    weaverii_put_rule_if_not_checked($sout,$id.'_u',$ahover . '{text-decoration:none;}');
	else
	    weaverii_put_rule_if_checked($sout,$id.'_u',$ahover . '{text-decoration:underline;}');
	if ($link_em)
	    weaverii_put_rule_if_not_checked($sout,$id.'_em',$a.'{font-style:normal;}');
	else
	    weaverii_put_rule_if_checked($sout,$id.'_em',$a.'{font-style:italic;}');
	if ($link_strong)
	    weaverii_put_rule_if_not_checked($sout,$id.'_strong',$a . '{font-weight:normal;}');
	else
	    weaverii_put_rule_if_checked($sout,$id.'_strong',$a . '{font-weight:bold;}');
    }
}

function weaverii_put_bgcolor($sout, $id, $tag) {
    // put bgcolor and CSS+

    if (($color = weaverii_getopt($id))) {
	weaverii_f_write($sout, sprintf("$tag {background-color:$color;}\n"));
    }

    if (($style = weaverii_getopt($id . '_css')) ) {
	weaverii_f_write($sout, sprintf("%s %s\n",$tag,$style));
    }
}

function weaverii_put_color($sout, $id, $tag, $important=false) {
    // put color and CSS+

    if (($color = weaverii_getopt($id))) {
	if ($important)
	weaverii_f_write($sout, sprintf("$tag {color:$color !important;}\n"));
	else
	    weaverii_f_write($sout, sprintf("$tag {color:$color;}\n"));
    }

    if (($style = weaverii_getopt($id . '_css')) ) {
	weaverii_f_write($sout, sprintf("%s %s\n",$tag,$style));
    }
}

function weaverii_put_rule_if_checked($sout, $id, $rule) {
    // put just a rule if checked

    if (weaverii_getopt_checked($id)) {
	weaverii_f_write($sout, $rule . "\n");
    }
}

function weaverii_put_rule_if_not_checked($sout, $id, $rule) {
    // put just a rule if not checked

    if (!weaverii_getopt_checked($id)) {
	weaverii_f_write($sout, $rule . "\n");
    }
}


function weaverii_css_bgcolor($sout, $name, $color, $altstyle='') {
    /* output a CSS background-color rule */
    if ($color == WEAVERII_DEFAULT_COLOR)
	    return;
    weaverii_f_write($sout, sprintf("$name {background-color: $color;$altstyle}\n"));
}
?>
