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

    if (!weaver_f_file_access_available()) {
	weaver_f_file_access_fail('Limited file access. Probably running with reduced functionality.');
	return '';
    }

    $save_dir = weaver_f_uploads_base_dir() . 'weaver-subthemes';
    $save_url = weaver_f_uploads_base_url() . 'weaver-subthemes';

    $usename = 'style-weaver.css';

    $ttw_theme_dir_exists = weaver_f_mkdir($save_dir);
    if (!$ttw_theme_dir_exists) {
	weaver_f_file_access_fail('Unable to create directory. Probably a file system permission problem. Directory' . $save_dir);
    }
    $ttw_theme_dir_writable = $ttw_theme_dir_exists;

   if (!weaver_f_is_writable($save_dir)) {
	weaver_f_file_access_fail('Directory not writable. Probably a file system permission problem. Directory: ' . $save_dir);
        $ttw_theme_dir_writable = false;
    }

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

    if (!$ttw_theme_dir_writable || !$ttw_theme_dir_exists || !($handle = weaver_f_open($filename, 'w')) ) {
	weaver_f_file_access_fail('Unable to create file. Probably a file system permission problem. File: ' . $filename);
	return '';
    }

    weaver_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",WEAVER_THEMENAME, WEAVER_VERSION, weaver_getopt('ttw_subtheme')));

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

    require_once('wvr-editorcss.php');
    weaver_save_editor_css($save_dir);

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

function weaver_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.
    */

// Put a options that can be overridden by the CSS option at the top!

    weaver_f_write($sout, sprintf("/* General Options */\n"));

/*  ttw_after_header  */

    if (($optVal = weaver_getopt("ttw_after_header")) !== false) {
	weaver_f_write($sout, sprintf("#main {padding: %spx 0 0 0;}\n", $optVal));
    }

/*  ttw_bold_menu  */

    if (weaver_getopt("ttw_bold_menu")) {
	weaver_f_write($sout, sprintf("#access, #access li ul ul > a, #access2, #access2 li ul ul > a, #access3, #access3 li ul ul > a {font-weight:bold;}\n"));
    }

/*  ttw_contentlist_bullet  */

    $val = weaver_getopt("ttw_contentlist_bullet");       /* add a new lsit bullet */
    if ($val && $val != '' && $val != 'default') {
	if ($val == 'none' || $val == 'circle' || $val == 'disc' || $val == 'square')
	    weaver_f_write($sout, sprintf("ul {list-style:%s;}\n",$val));
	else
            weaver_f_write($sout, sprintf("ul {list-style:none;list-style-image: url(%s/images/bullets/%s.gif);}\n",
		get_template_directory_uri(),$val));
    }


/*  ttw_content_font  */

    if (($useFont = weaver_get_font_value('ttw_content_font')) != '') {
	weaver_css_fontfamily($sout,'body, input, textarea, .page-title span, .pingback a.url', $useFont);
    }

/*  ttw_fadebody_bg  */

    if (weaver_getopt('ttw_fadebody_bg')) {
	$url = weaver_relative_url('images/gr.png');
	weaver_f_write($sout, sprintf("body {background-image: url(%s); background-attachment: scroll; background-repeat: repeat-x;}\n",
	       $url));
    }

/*  ttw_gradient_menu  */

    if (weaver_getopt('ttw_gradient_menu')) {
	$url = weaver_relative_url('images/weaver/fade.png');
	$urlup = weaver_relative_url('images/weaver/fadeup.png');
	weaver_f_write($sout, sprintf("#access, #access2, #access3 { background-image: url(%s);}\n",
	       $url));
	weaver_f_write($sout, sprintf("#access ul ul a, #access li:hover > a, #access ul ul :hover > a { background-image: url(%s);}\n",
	       $urlup));
	weaver_f_write($sout, sprintf("#access2 ul ul a, #access2 li:hover > a, #access2 ul ul :hover > a { background-image: url(%s);}\n",
	       $urlup));
	weaver_f_write($sout, sprintf("#access3 ul ul a, #access3 li:hover > a, #access3 ul ul :hover > a { background-image: url(%s);}\n",
	       $urlup));
   }

/*  ttw_hide_post_fill  (also used in post icons) */

    if (weaver_getopt('ttw_hide_post_fill')) {
	weaver_f_write($sout, sprintf(".entry-utility-prep {display: none;}\n.meta-prep-author {display:none;}\n.meta-sep {display: none;}\n"));
    }


/*  ttw_large_tagline  */

    if (weaver_getopt('ttw_large_tagline')) {
	weaver_f_write($sout, sprintf('#site-description {font-size:130%%; font-weight:bold;}'));
    }

/*  ttw_list_bullet  */

    $val = weaver_getopt('ttw_list_bullet');       /* add a new lsit bullet */
    if ($val && $val != '' && $val != 'default') {
	if ($val == 'none' || $val == 'circle' || $val == 'disc' || $val == 'square')
	    weaver_f_write($sout, sprintf(".widget-area ul ul {list-style:%s;}\n",$val));
	else {
	    $url = weaver_relative_url('images/bullets/' . $val . '.gif');
	    weaver_f_write($sout, sprintf(".widget-area ul ul {list-style:none; list-style-position:inside; list-style-image: url(%s);}\n",
	       $url));
	}
    }

/*  ttw_post_icons  */

   if (weaver_getopt('ttw_post_icons')) {
	$leftm = '8';
	$url = weaver_relative_url('images/icons/edit-1.png');
	if (!weaver_getopt('ttw_hide_post_fill')) $leftm = '0';	// no left margin if not hiding fill in
	weaver_f_write($sout, sprintf(".edit-link{ background: url(%s) no-repeat 1px;padding-top:3px;padding-left:21px;margin-left:%spx;}\n",
	       $url,$leftm));
   }


/*  ttw_small_content_font  */

    if (weaver_getopt('ttw_small_content_font')) {
	weaver_f_write($sout, sprintf("#content {font-size: 120%%; line-height: 125%%; }\n"));  /* stange, but true! */
	weaver_f_write($sout, sprintf("#comments {font-size: 90%%; line-height: 90%%; }\n"));  /* stange, but true! */
    }

/*  ttw_title_font  */

if (($useFont = weaver_get_font_value('ttw_title_font')) != '') {
	weaver_css_fontfamily($sout,
'h3#comments-title, h3#reply-title, #access .menu, #access div.menu ul, #access2 .menu, #access2 div.menu ul,
#access3 .menu, #access3 div.menu ul,
#cancel-comment-reply-link, .form-allowed-tags, #site-info, #site-title, #wp-calendar,
.comment-meta, .comment-body tr th, .comment-body thead th, .entry-content label, .entry-content tr th,
.entry-content thead th, .entry-meta, .entry-title, .entry-utility, #respond label, .navigation,
.page-title, .pingback p, .reply, .widget_search label, .widget-title, input[type=submit]', $useFont);
    }



/*  ttw_useborders  */

    if (weaver_getopt('ttw_useborders')) {
        weaver_f_write($sout, sprintf("#wrapper {border: 1px solid #222222; padding-right: 20px; margin-top: 15px; margin-bottom: 15px;}\n"));
        weaver_f_write($sout, sprintf("#header {margin-top: 0px;}\n"));
	weaver_f_write($sout, sprintf("#primary, #secondary, #altleft, #altright, #altleft, #altright {border: 1px solid #222222;}\n"));
    }

if (weaver_getopt('ttw_useborders') || weaver_getopt('ttw_useborders_topbot')) {
 	weaver_f_write($sout, sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {border: 1px solid #222222;}\n"));
    }

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

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

    if (weaver_getopt('ttw_rounded_corners')) { // not #access3
        weaver_f_write($sout, sprintf("#container, #primary, #secondary, #altleft, #altright, #ttw-top-widget, #ttw-bot-widget,
  #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {-moz-border-radius: %dpx; -webkit-border-radius: %dpx; border-radius: %dpx;}\n",$r,$r,$r));
	if (weaver_getopt('ttw_move_menu')) {
	    weaver_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));
	    weaver_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 {
	    weaver_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));
	    weaver_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));
	}
        weaver_f_write($sout, sprintf("#wrapper {-moz-border-radius: %dpx; -webkit-border-radius: %dpx; border-radius: %dpx; margin-top: 15px; margin-bottom: 15px;}\n",
	    $r,$r,$r));
    }

/*	ttw_use_superfish	*/
    if (!weaver_getopt('ttw_use_superfish')) {
	/* need to fix up access a if NOT using SuperFish */
	weaver_f_write($sout, sprintf("#access a, #access2 a, #access3 a { padding-left:10px; padding-right:10px;}\n"));
    }

// ------------------------------------------- end of overrideable options -------------------------------
/* Generate the sidebar CSS last since it might override some other settings */
    weaver_f_write($sout, sprintf("/* Sidebar arrangement */\n"));

    weaver_sidebar_css($sout);	// complicated code in its own function...

/*  ttw_title_on_header  - needs to be here... */

    weaver_f_write($sout, sprintf("/* Color and custom CSS */\n"));

    if (weaver_getopt('ttw_title_on_header')) {
	$tx = 40; $ty = 44; // default values for offsets
	$dx = 40; $dy = 90;
	$val = weaver_getopt('ttw_title_on_header_xy_X'); if (!empty($val)) $tx = (int) $val;
	$val = weaver_getopt('ttw_title_on_header_xy_Y'); if (!empty($val)) $ty = (int) $val;
	$val = weaver_getopt('ttw_title_on_header_xy_desc_X'); if (!empty($val)) $dx = (int) $val;
	$val = weaver_getopt('ttw_title_on_header_xy_desc_Y'); if (!empty($val)) $dy = (int) $val;

	weaver_f_write($sout, sprintf("#site-title {left:0px; position: absolute; margin-left: %dpx; margin-top: %dpx;z-index:20;}\n",$tx,$ty));
	weaver_f_write($sout, sprintf("#site-description {left:0px; width:50%%; text-align:left; clear: both; float: left; position:absolute; margin-left: %dpx; margin-top: %dpx; z-index:20;}\n",$dx,$dy));
    }

/*  ttw_body_bgcolor  */

    if (($optVal = weaver_getopt_color('ttw_body_bgcolor'))) {
	weaver_css_bgcolor($sout,'body',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_body_bgcolor_css'))) {
	weaver_css_css($sout,'body',$optVal);
    }

/*  ttw_container_bgcolor  */

    if (($optVal = weaver_getopt("ttw_container_bgcolor"))) {
	weaver_css_bgcolor($sout,'#container',$optVal);
    }
    if (($optVal = weaver_getopt("ttw_container_bgcolor_css"))) {
	weaver_css_css($sout,'#container',$optVal);
    }

/*  ttw_content_bgcolor  */

    if (($optVal = weaver_getopt("ttw_content_bgcolor"))) {
	weaver_css_bgcolor($sout,'#content',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_content_bgcolor_css'))) {
	weaver_css_css($sout,'#content',$optVal);
    }

/*  ttw_content_color  */
    if (($optVal = weaver_getopt_color('ttw_content_color')) ) {
	weaver_css_color($sout,'#content, #content input, #content textarea',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_content_color_css')) ) {
	weaver_css_css($sout,'#content, #content input, #content textarea',$optVal);
    }

/*  ttw_desc_color  */

    if (($optVal = weaver_getopt_color('ttw_desc_color'))) {
	weaver_f_write($sout, sprintf("#site-description {color: ".$optVal.";}\n"));
    }
    if (($optVal = weaver_getopt('ttw_desc_color_css'))) {
	weaver_css_css($sout,"#site-description", $optVal);
    }

/*  ttw_excerpt_length - no CSS */

/*  ttw_footer_bgcolor  */

    if (($optVal = weaver_getopt("ttw_footer_bgcolor"))) {
	weaver_css_bgcolor($sout,'#footer',$optVal);
    }
    if (($optVal = weaver_getopt("ttw_footer_bgcolor_css"))) {
	weaver_css_css($sout,'#footer',$optVal);
    }

/*  ttw_footer_border_color  */

    if (($optVal = weaver_getopt_color('ttw_footer_border_color'))) {
	weaver_f_write($sout, sprintf("#colophon { border-top: 4px solid $optVal ;  }\n"));
    }
    if (($optVal = weaver_getopt("ttw_footer_border_color_css"))) {
	weaver_css_css($sout,'#colophon',$optVal);
    }

/*    ttw_footer_widget_bgcolor */

    if (($optVal = weaver_getopt('ttw_footer_widget_bgcolor'))) {
	weaver_css_bgcolor($sout,'#first,#second, #third, #fourth',$optVal,'padding-left: 10px; padding-top: 10px; margin-bottom: 5px;');
    }
    if (($optVal = weaver_getopt('ttw_footer_widget_bgcolor_css'))) {
	weaver_css_css($sout,'#first,#second, #third, #fourth',$optVal);
    }

/*  ttw_force_widg_frontpage - no CSS */

/*  ttw_header_bgcolor  */

    if (($optVal = weaver_getopt("ttw_header_bgcolor"))) {
	weaver_css_bgcolor($sout,'#header',$optVal);
    }
    if (($optVal = weaver_getopt("ttw_header_bgcolor_css"))) {
	weaver_css_css($sout,'#header',$optVal);
    }

/*  ttw_header_image_height - no CSS*/
/*  ttw_header_image_width - no CSS (used in width calculations, however)  */

/*  ttw_header_underline  */

    $val = (int)weaver_getopt('ttw_header_underline');       /* bar under headers */
    if ($val != '' && $val != 0) {
        $titleColor = weaver_getopt('ttw_text_color');
        weaver_f_write($sout, sprintf(".entry-title {border-bottom: $val"."px solid $titleColor;}\n"));
    }

/*  ttw_hide_menu - no CSS */
/*  ttw_hide_site_title - no CSS */
/*  ttw_hide_widg_pages - no CSS */
/*  ttw_hide_widg_posts - no CSS */

/*  ttw_hr_color  */

    if (($optVal = weaver_getopt_color('ttw_hr_color'))) {
	weaver_css_bgcolor($sout,'hr',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_hr_color_css'))) {
	weaver_css_css($sout,'hr',$optVal);
    }

/*  ttw_ilink_color  */
/*  ttw_ilink_visited_color  */
/*  ttw_ilink_hover_color  */

    if (($optVal = weaver_getopt_color("ttw_ilink_color"))) { /* post title links */
	weaver_css_color($sout,'.page-title a:link', $optVal);
	weaver_css_color($sout,'.entry-meta a:link', $optVal);
	weaver_css_color($sout,'.entry-utility a:link', $optVal);
	weaver_css_color($sout,'.navigation a:link', $optVal);
	weaver_css_color($sout,'.comment-meta a:link', $optVal);
	weaver_css_color($sout,'.reply a:link, a.comment-edit-link:link', $optVal);
    }
    if (($optVal = weaver_getopt_color("ttw_ilink_visited_color"))) {
	weaver_css_color($sout,'.page-title a:visited', $optVal);
	weaver_css_color($sout,'.entry-meta a:visited', $optVal);
	weaver_css_color($sout,'.entry-utility a:visited', $optVal);
	weaver_css_color($sout,'.navigation a:visited', $optVal);
	weaver_css_color($sout,'.comment-meta a:visited', $optVal);
	weaver_css_color($sout,'.reply a:visited, a.comment-edit-link:visited', $optVal);
    }
    if (($optVal = weaver_getopt_color("ttw_ilink_hover_color"))) {
	weaver_css_color($sout,'.page-title a:active, .page-title a:hover', $optVal);
	weaver_css_color($sout,'.entry-meta a:hover, .entry-meta a:active', $optVal);
	weaver_css_color($sout,'.entry-utility a:hover, .entry-utility a:active', $optVal);
	weaver_css_color($sout,'.navigation a:active, .navigation a:hover', $optVal);
	weaver_css_color($sout,'.comment-meta a:active, .comment-meta a:hover', $optVal);
	weaver_css_color($sout,'.reply a:active, a.comment-edit-link:active, .reply a:hover, a.comment-edit-link:hover', $optVal);
    }
    if (($optVal = weaver_getopt("ttw_ilink_color_css"))) { /* post title links */
	weaver_css_css($sout,'.page-title a:link', $optVal);
	weaver_css_css($sout,'.entry-meta a:link', $optVal);
	weaver_css_css($sout,'.entry-utility a:link', $optVal);
	weaver_css_css($sout,'.navigation a:link', $optVal);
	weaver_css_css($sout,'.comment-meta a:link', $optVal);
	weaver_css_css($sout,'.reply a:link, a.comment-edit-link:link', $optVal);
    }
    if (($optVal = weaver_getopt("ttw_ilink_visited_color_css"))) {
	weaver_css_css($sout,'.page-title a:visited', $optVal);
	weaver_css_css($sout,'.entry-meta a:visited', $optVal);
	weaver_css_css($sout,'.entry-utility a:visited', $optVal);
	weaver_css_css($sout,'.navigation a:visited', $optVal);
	weaver_css_css($sout,'.comment-meta a:visited', $optVal);
	weaver_css_css($sout,'.reply a:visited, a.comment-edit-link:visited', $optVal);
    }
    if (($optVal = weaver_getopt("ttw_ilink_hover_color_css"))) {
	weaver_css_css($sout,'.page-title a:active, .page-title a:hover', $optVal);
	weaver_css_css($sout,'.entry-meta a:hover, .entry-meta a:active', $optVal);
	weaver_css_css($sout,'.entry-utility a:hover, .entry-utility a:active', $optVal);
	weaver_css_css($sout,'.navigation a:active, .navigation a:hover', $optVal);
	weaver_css_css($sout,'.comment-meta a:active, .comment-meta a:hover', $optVal);
	weaver_css_css($sout,'.reply a:active, a.comment-edit-link:active, .reply a:hover, a.comment-edit-link:hover', $optVal);
    }


/*  ttw_info_color  */

    if (($infoColor = weaver_getopt_color('ttw_info_color'))) {
        weaver_css_color($sout,'#comments .pingback p', $infoColor);
	weaver_css_color($sout,'#respond label, #respond dt, #respond dd', $infoColor);
	weaver_css_color($sout,'.entry-meta, .entry-content label, .entry-utility', $infoColor);
	weaver_css_color($sout,'#content .wp-caption, #content .gallery .gallery-caption', $infoColor);
	weaver_css_color($sout,'.navigation', $infoColor);
    }
    if (($infoColor = weaver_getopt('ttw_info_color_css'))) {
        weaver_css_css($sout,'#comments .pingback p', $infoColor);
	weaver_css_css($sout,'#respond label, #respond dt, #respond dd', $infoColor);
	weaver_css_css($sout,'.entry-meta, .entry-content label, .entry-utility', $infoColor);
	weaver_css_css($sout,'#content .wp-caption, #content .gallery .gallery-caption', $infoColor);
	weaver_css_css($sout,'.navigation', $infoColor);
    }

/* ttw_post_title_color */

   if (($infoColor = weaver_getopt_color('ttw_post_title_color'))) {
        weaver_css_color($sout,'.entry-format', $infoColor.'!important');
    }
    if (($infoColor = weaver_getopt('ttw_post_title_color_css'))) {
        weaver_css_css($sout,'.entry-format', $infoColor);
    }

/*  ttw_infotop_bgcolor, ttw_infobottom_bgcolor  */

    if (($optVal = weaver_getopt('ttw_infotop_bgcolor'))) {
	weaver_css_bgcolor($sout,'.entry-meta',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_infotop_bgcolor_css'))) {
	weaver_css_css($sout,'.entry-meta',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_infobottom_bgcolor'))) {
	weaver_css_bgcolor($sout,'.entry-utility',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_infobottom_bgcolor_css'))) {
	weaver_css_css($sout,'.entry-utility',$optVal);
    }

/*  ttw_input_bgcolor  */

    if (($optVal = weaver_getopt('ttw_input_bgcolor'))) {
	weaver_css_bgcolor($sout,'input[type="text"], textarea, input[type="submit"], ins',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_input_bgcolor_css'))) {
	weaver_css_css($sout,'input[type="text"], textarea, input[type="submit"], ins',$optVal);
    }

/*  ttw_link_color  */
/*  ttw_link_visited_color  */
/*  ttw_link_hover_color  */

    if (($optVal = weaver_getopt_color('ttw_link_color'))) {
	weaver_css_color($sout,'a:link', $optVal);
    }
    if (($optVal = weaver_getopt_color('ttw_link_visited_color'))) {
	weaver_css_color($sout,'a:visited', $optVal);
    }
    if (($optVal = weaver_getopt_color('ttw_link_hover_color'))) {
	weaver_css_color($sout,'a:active, a:hover', $optVal);
    }

    if (($optVal = weaver_getopt('ttw_link_color_css'))) {
	weaver_css_css($sout,'a:link', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_link_visited_color_css'))) {
	weaver_css_css($sout,'a:visited', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_link_hover_color_css'))) {
	weaver_css_css($sout,'a:active, a:hover', $optVal);
    }


/*  ttw_link_site_image - no CSS */

/*  ttw_main_bgcolor  */

    if (($optVal = weaver_getopt('ttw_main_bgcolor'))) {
	weaver_css_bgcolor($sout,'#main',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_main_bgcolor_css'))) {
	weaver_css_css($sout,'#main',$optVal);
    }

    /*  ttw_caption_color  */

    if (($optVal = weaver_getopt_color('ttw_caption_color'))) {
	weaver_css_color($sout,'#content .wp-caption p.wp-caption-text, #content .gallery .gallery-caption',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_caption_color_css'))) {
	weaver_css_css($sout,'#content .wp-caption p.wp-caption-text, #content .gallery .gallery-caption',$optVal);
    }

/*    ttw_media_lib_border    */

    if (($optVal = weaver_getopt('ttw_media_lib_border')) !== false) {
	weaver_f_write($sout, sprintf("#content .size-full, #content .size-large, #content .size-medium, #content .size-thumbnail,#content .size-thumbnail {background-color: %s;}\n",
	    $optVal  ));
    }
    if (($optVal = weaver_getopt('ttw_media_lib_border_css'))) {
	weaver_css_css($sout,'#content .size-full, #content .size-large, #content .size-medium, #content .size-thumbnail',$optVal);
    }

/*    ttw_media_lib_captioned_border    */

    if (($optVal = weaver_getopt('ttw_media_lib_captioned_border')) !== false) {
	weaver_f_write($sout, sprintf("#content .wp-caption p.wp-caption-text,
#content .wp-caption .size-full, #content .wp-caption .size-large, #content .wp-caption .size-medium,
#content .wp-caption .size-thumbnail, #content .wp-caption .size-thumbnail {background-color: %s;}\n",
	    $optVal  ));
    }
    if (($optVal = weaver_getopt('ttw_media_lib_captioned_border_css'))) {
	weaver_css_css($sout,'#content .wp-caption p.wp-caption-text,
#content .wp-caption .size-full, #content .wp-caption .size-large, #content .wp-caption .size-medium,
#content .wp-caption .size-thumbnail, #content .wp-caption .size-thumbnail',
	    $optVal);
    }

/*  ttw_menubar_color  */

    if (($optVal = weaver_getopt_color('ttw_menubar_color'))) {
	weaver_css_bgcolor($sout,'#access, #access2, #access3', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_menubar_color_css'))) {
	weaver_css_css($sout,'#access, #access2, #access3', $optVal);
    }

/*  ttw_menubar_curpage_color  */

    if (($optVal = weaver_getopt_color('ttw_menubar_curpage_color'))) {
	weaver_css_color($sout,'#access ul li.current_page_item > a, #access ul li.current-menu-ancestor > a,
#access ul li.current-menu-item > a, #access ul li.current-menu-parent > a', $optVal);
	weaver_css_color($sout,'#access2 ul li.current_page_item > a, #access2 ul li.current-menu-ancestor > a,
#access2 ul li.current-menu-item > a, #access2 ul li.current-menu-parent > a', $optVal);
	weaver_css_color($sout,'#access3 ul li.current_page_item > a, #access3 ul li.current-menu-ancestor > a,
#access3 ul li.current-menu-item > a, #access3 ul li.current-menu-parent > a', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_menubar_curpage_color_css'))) {
	weaver_css_css($sout,'#access ul li.current_page_item > a, #access ul li.current-menu-ancestor > a,
#access ul li.current-menu-item > a, #access ul li.current-menu-parent > a', $optVal);
	weaver_css_css($sout,'#access2 ul li.current_page_item > a, #access2 ul li.current-menu-ancestor > a,
#access2 ul li.current-menu-item > a, #access2 ul li.current-menu-parent > a', $optVal);
	weaver_css_css($sout,'#access3 ul li.current_page_item > a, #access3 ul li.current-menu-ancestor > a,
#access3 ul li.current-menu-item > a, #access3 ul li.current-menu-parent > a', $optVal);
    }

/*  ttw_menubar_hover_color  */
/*  ttw_menubar_hoverbg_color  */
/*  ttw_menubar_text_color  */

    if (($optVal = weaver_getopt_color('ttw_menubar_hover_color'))) {
	weaver_css_color($sout,'#access li:hover > a, #access ul ul :hover > a', $optVal);
	weaver_css_color($sout,'#access2 li:hover > a, #access2 ul ul :hover > a', $optVal);
	weaver_css_color($sout,'#access3 li:hover > a, #access3 ul ul :hover > a', $optVal);
    }
    if (($optVal = weaver_getopt_color('ttw_menubar_hoverbg_color'))) {
	weaver_css_bgcolor($sout,'#access ul ul a, #access li:hover > a, #access ul ul :hover > a ', $optVal);
	weaver_css_bgcolor($sout,'#access2 ul ul a, #access2 li:hover > a, #access2 ul ul :hover > a ', $optVal);
	weaver_css_bgcolor($sout,'#access3 ul ul a, #access3 li:hover > a, #access3 ul ul :hover > a ', $optVal);
    }
    if (($optVal = weaver_getopt_color('ttw_menubar_text_color'))) {
	weaver_css_color($sout,'#access a, #access2 a, #access3 a', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_menubar_hover_color_css'))) {
	weaver_css_css($sout,'#access li:hover > a, #access ul ul :hover > a', $optVal);
	weaver_css_css($sout,'#access2 li:hover > a, #access2 ul ul :hover > a', $optVal);
	weaver_css_css($sout,'#access3 li:hover > a, #access3 ul ul :hover > a', $optVal);

    }
    if (($optVal = weaver_getopt('ttw_menubar_hoverbg_color_css'))) {
	weaver_css_css($sout,'#access ul ul a, #access li:hover > a, #access ul ul :hover > a ', $optVal);
	weaver_css_css($sout,'#access2 ul ul a, #access2 li:hover > a, #access2 ul ul :hover > a ', $optVal);
	weaver_css_css($sout,'#access3 ul ul a, #access3 li:hover > a, #access3 ul ul :hover > a ', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_menubar_text_color_css'))) {
	weaver_css_css($sout,'#access a,#access2 a,#access3 a', $optVal);
    }

/*  ttw_move_menu - no CSS (used by rounded corners) */

/*  ttw_page_bgcolor  */

    if (($optVal = weaver_getopt('ttw_page_bgcolor'))) {
	weaver_css_bgcolor($sout,'#wrapper',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_page_bgcolor_css'))) {
	weaver_css_css($sout,'#wrapper',$optVal);
    }

/*  ttw_plink_color  */
/*  ttw_plink_visited_color  */
/*  ttw_plink_hover_color  */

    if (($optVal = weaver_getopt_color('ttw_plink_color'))) { /* post title links */
    	weaver_css_color($sout,'.entry-title a:link', $optVal);
	weaver_css_color($sout,'.widget_rss a.rsswidget:link', $optVal);
    }
    if (($optVal = weaver_getopt_color('ttw_plink_visited_color'))) {
    	weaver_css_color($sout,'.entry-title a:visited', $optVal);
    	weaver_css_color($sout,'.widget_rss a.rsswidget:visited', $optVal);
    }
    if (($optVal = weaver_getopt_color('ttw_plink_hover_color'))) {
    	weaver_css_color($sout,'.entry-title a:active, .entry-title a:hover', $optVal);
    	weaver_css_color($sout,'.widget_rss a.rsswidget:active, .widget_rss a.rsswidget:hover', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_plink_color_css'))) { /* post title links */
    	weaver_css_css($sout,'.entry-title a:link', $optVal);
	weaver_css_css($sout,'.widget_rss a.rsswidget:link', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_plink_visited_color_css'))) {
    	weaver_css_css($sout,'.entry-title a:visited', $optVal);
    	weaver_css_css($sout,'.widget_rss a.rsswidget:visited', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_plink_hover_color_css'))) {
    	weaver_css_css($sout,'.entry-title a:active, .entry-title a:hover', $optVal);
    	weaver_css_css($sout,'.widget_rss a.rsswidget:active, .widget_rss a.rsswidget:hover', $optVal);
    }

    /*  ttw_post_bgcolor  */

    if (($optVal = weaver_getopt('ttw_post_bgcolor'))) {
	weaver_css_bgcolor($sout,'.post',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_post_bgcolor_css'))) {
	weaver_css_css($sout,'.post',$optVal);
    }

/*  ttw_side1_bgcolor  */
/*  ttw_side2_bgcolor  */
/*  ttw_side3_bgcolor  */

    if (($optVal = weaver_getopt('ttw_side1_bgcolor'))) {
	weaver_css_bgcolor($sout,'#primary',$optVal, 'padding-left: 10px; padding-top: 10px; margin-bottom: 5px;');
    }
    if (($optVal = weaver_getopt('ttw_side2_bgcolor'))) {
	weaver_css_bgcolor($sout,'#secondary',$optVal, 'padding-left: 10px; padding-top: 10px; margin-bottom: 5px;');
    }
    if (($optVal = weaver_getopt('ttw_side3_bgcolor'))) {
	weaver_css_bgcolor($sout,'#altright, #altleft',$optVal,'padding-left: 10px; padding-top: 10px; margin-bottom: 5px;');
    }
    if (($optVal = weaver_getopt('ttw_side1_bgcolor_css'))) {
	weaver_css_css($sout,'#primary',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_side2_bgcolor_css'))) {
	weaver_css_css($sout,'#secondary',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_side3_bgcolor_css'))) {
	weaver_css_css($sout,'#altright, #altleft',$optVal);
    }

/*  ttw_sidebar_width  */
/*  ttw_sidebars  */
/* 	The CSS for sidebars is generated last because it might override some other settings  */

    $optVal = weaver_getopt('ttw_site_margins');
    if (strlen($optVal) > 0) {
	weaver_f_write($sout, sprintf("#header {padding-top: %spx;}
#wrapper {padding: 0 %spx;}
#footer {margin-bottom: %spx;}\n", $optVal+10, $optVal, $optVal, $optVal));
	if (!weaver_getopt('ttw_title_on_header')) {
	    weaver_f_write($sout, sprintf("#site-title{padding-left: 4px;}
#site-title, #site-description {margin: %spx 0px 0px 0px;}\n",($optVal+2)/2));
	}
    }


/*  ttw_stickypost_bgcolor  */

    if (($optVal = weaver_getopt('ttw_stickypost_bgcolor'))) {
	weaver_css_bgcolor($sout,'.home .sticky, #entry-author-info, #container.page-with-posts .sticky',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_stickypost_bgcolor_css'))) {
	weaver_css_css($sout,'.home .sticky, #entry-author-info, #container.page-with-posts .sticky',$optVal);
    }

/*  ttw_text_color  */

    if (($textColor = weaver_getopt_color('ttw_text_color'))) {
	weaver_css_color($sout,'#content h1, #content h2, #content h3, #content h4, #content h5, #content h6, #content dt, #content th',$textColor);
	weaver_css_color($sout,'h1, h2, h3, h4, h5, h6',$textColor);
	weaver_css_color($sout,'.page-title',$textColor);
	weaver_css_color($sout,'.page-link',$textColor);
	weaver_css_color($sout,'#entry-author-info h2',$textColor);
	weaver_css_color($sout,'h3#comments-title, h3#reply-title',$textColor);
	weaver_css_color($sout,'.comment-author cite',$textColor);
	weaver_css_color($sout,'.entry-content fieldset legend',$textColor);
    }
    if (($textColor = weaver_getopt('ttw_text_color_css'))) {
	weaver_css_css($sout,'#content h1, #content h2, #content h3, #content h4, #content h5, #content h6, #content dt, #content th',$textColor);
	weaver_css_css($sout,'h1, h2, h3, h4, h5, h6',$textColor);
	weaver_css_css($sout,'.page-title',$textColor);
	weaver_css_css($sout,'.page-link',$textColor);
	weaver_css_css($sout,'#entry-author-info h2',$textColor);
	weaver_css_css($sout,'h3#comments-title, h3#reply-title',$textColor);
	weaver_css_css($sout,'.comment-author cite',$textColor);
	weaver_css_css($sout,'.entry-content fieldset legend',$textColor);
    }

/*  ttw_page_title_color - MUST come after ttw_text_color! */

   if (($textColor = weaver_getopt_color('ttw_page_title_color'))) {
	weaver_css_color($sout,'#content .entry-title',$textColor);
    } else if (($textColor = weaver_getopt_color('ttw_text_color'))) {	// this gives backward compatibility pre-1.5
	weaver_css_color($sout,'#content .entry-title',$textColor);
    }
    if (($textColor = weaver_getopt('ttw_page_title_color_css'))) {	// not pre-1.5, so no worry
	weaver_css_css($sout,'#content .entry-title',$textColor);
    }


/*  ttw_title_color  */

    if (($optVal = weaver_getopt_color('ttw_title_color'))) {
	weaver_f_write($sout, sprintf("#site-title a { color: ".$optVal."; }\n"));
    }
    if (($optVal = weaver_getopt('ttw_title_color_css'))) {
	weaver_css_css($sout,'#site-title',$optVal);
    }

/*  ttw_topbottom_bgcolor  */

    if (($optVal = weaver_getopt('ttw_topbottom_bgcolor'))) {
	weaver_css_bgcolor($sout,'#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget',
		      $optVal, 'padding-left: 10px; padding-top: 10px; margin-bottom: 10px;');
    }
    if (($optVal = weaver_getopt('ttw_topbottom_bgcolor_css'))) {
	weaver_css_css($sout,'#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget',$optVal);
    }

/*  ttw_weaver_tables  */
    $table = weaver_getopt('ttw_weaver_tables');

    if ($table != 'None') {		// Need to write default style values
    weaver_f_write($sout, "table { border-collapse:collapse;border-spacing:0;}
th { text-align:left; padding:4px 4px; }
td { margin:0;padding:4px 4px; }\n");

	if ($table != 'Default') {		// Non-default styles based on Weaver table style
	    weaver_f_write($sout, "#content table { border: 2px solid #AAA; text-align: left; margin: auto; margin-bottom: 5px; width: auto; }
#content tr th, #content thead th { color: inherit; background-color: rgba(0,0,0,.1); font-size: medium;
   font-weight: normal; line-height: normal; padding: 5px 10px; }
#content tr td { border: 1px solid #AAA; padding: 5px 10px; }
#content tr.odd td { background: inherit; }\n");
	}
    }

     if ($table == 'Default') {	// make backward compatible with 1.4 and before when Twenty Ten was default
	weaver_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 Headings') {
	weaver_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 == 'No Borders') {
	weaver_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 == 'Full Width') {
	weaver_f_write($sout, sprintf("#content table {width:100%%;}
#content tr th, #content thead th {font-weight:bold;}\n"));
    } // else 'Weaver' - handled previously


/*  ttw_wide_top_bottom - used by sidebar calcs */

/*  ttw_widget_color  */

    if (($widgetColor = weaver_getopt_color('ttw_widget_color'))) {
	weaver_css_color($sout,'.widget-area',$widgetColor);
    }
    if (($widgetColor = weaver_getopt('ttw_widget_color_css'))) {
	weaver_css_css($sout,'.widget-area',$widgetColor);
    }

/*  ttw_widget_header_underline  */

    $val = (int)weaver_getopt('ttw_widget_header_underline');       /* bar under widget */
    if ($val != '' && $val != 0) {
        $titleColor = weaver_getopt('ttw_widget_title_color');
        weaver_f_write($sout, sprintf(".widget-title {border-bottom: $val"."px solid $titleColor; margin-bottom:5px;}\n"));
     }

/*  ttw_widget_item_bgcolor */

    if (($optVal = weaver_getopt('ttw_widget_item_bgcolor'))) {
	weaver_css_bgcolor($sout,'.widget-container',$optVal);
    }
    if (($optVal = weaver_getopt('ttw_widget_item_bgcolor_css'))) {
	weaver_css_css($sout,'.widget-container',$optVal);
    }

/*  ttw_widget_title_color  */

    if (($wigtitleColor = weaver_getopt_color('ttw_widget_title_color'))) {
	weaver_css_color($sout,'.widget-title', $wigtitleColor);
	weaver_css_color($sout,'.widget_search label', $wigtitleColor);
	weaver_css_color($sout,'#wp-calendar caption', $wigtitleColor);
    }
    if (($wigtitleColor = weaver_getopt_color('ttw_widget_title_color_css'))) {
	weaver_css_css($sout,'.widget-title', $wigtitleColor);
	weaver_css_css($sout,'.widget_search label', $wigtitleColor);
	weaver_css_css($sout,'#wp-calendar caption', $wigtitleColor);
    }

/*  ttw_wlink_color  */
/*  ttw_wlink_visited_color  */
/*  ttw_wlink_hover_color  */

    if (($optVal = weaver_getopt_color('ttw_wlink_color'))) {
	weaver_css_color($sout,'#primary a:link, #secondary a:link, #altleft a:link, #altright a:link, #footer-widget-area a:link', $optVal);
    }
    if (($optVal = weaver_getopt_color('ttw_wlink_visited_color'))) {
	weaver_css_color($sout,'#primary a:visited, #secondary a:visited, #altleft a:visited, #altright a:visited, #footer-widget-area a:visited', $optVal);
    }
    if (($optVal = weaver_getopt_color('ttw_wlink_hover_color'))) {
	weaver_css_color($sout,'#primary a:hover, #secondary a:hover, #altleft a:hover, #altright a:hover, #footer-widget-area a:hover', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_wlink_color_css'))) {
	weaver_css_css($sout,'#primary a:link, #secondary a:link, #altleft a:link, #altright a:link, #footer-widget-area a:link', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_wlink_visited_color_css'))) {
	weaver_css_css($sout,'#primary a:visited, #secondary a:visited, #altleft a:visited, #altright a:visited, #footer-widget-area a:visited', $optVal);
    }
    if (($optVal = weaver_getopt('ttw_wlink_hover_color_css'))) {
	weaver_css_css($sout,'#primary a:hover, #secondary a:hover, #altleft a:hover, #altright a:hover, #footer-widget-area a:hover', $optVal);
    }


/*  ttw_wrap_shadow  */

    if (weaver_getopt('ttw_wrap_shadow')) {
	weaver_f_write($sout, sprintf("#wrapper {box-shadow: 0 0 3px 3px rgba(0,0,0,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"));
    }
    do_action('wvrx_plus_output_style',$sout);

    $add_css = weaver_getopt('ttw_add_css');

    if (!empty($add_css))
	weaver_f_write($sout,weaver_getopt('ttw_add_css'));

    weaver_f_write($sout, "\n/* end Weaver CSS */\n");
}

define ('WVR_WIDTH', 940);
function weaver_sidebar_css($sout) {
    /* output the CSS to support different sidebars at different widths */

    $sidebars = weaver_getopt('ttw_sidebars');
    $themewidth = weaver_getopt('ttw_header_image_width');
    if (! $themewidth) $themewidth = '940';
    $sidebarwidth = weaver_getopt('ttw_sidebar_width');
    $sb_adjust = (int) weaver_getopt('ttw_border_adjust_sidebar');
    $fw_use = 4;
    $fw_new_count = weaver_getopt('ttw_footer_widget_count');
    if (!empty($fw_new_count)) {
	$val = (int) $fw_new_count;	// try to get an int
	if ($val > 0  && $val < 4)	// ignore all but valid values
	    $fw_use = $val;
    }

    /* SIDEBAR layout - need to calculate and override items if change width.
     *	First, calculate and emit everything that is constant for each alternative:
     *	Footer width, site-info, site-generator, site-title, site-description.
     */
    $mw = (int) $themewidth;		/* main width */
    $fw = (int)((($mw+($fw_use*5)-2)/$fw_use)-25);	/* footer widget width ((mainwidth+(num*5)/num)-25  */
    $si = (int) ( ($mw - 40) * .50 );	/* site info = 60% of mainwidth-40*/
    $sg = (int) ( $mw - 50 - $si );	/* site generator - left over space */
    $caw = (int) $mw - 40;		/* mainwidth - 40 */
    $ocw = (int)($mw * .90);		/* one column width */
    $tbmult = 0.85;			// usually make top/bottom widget areas 85%
    if (weaver_getopt('ttw_wide_top_bottom')) $tbmult = 1;

    if (weaver_getopt_checked('ttw_header_first'))  weaver_f_write($sout, sprintf("#masthead {margin:0 auto;width:%dpx;}\n",$mw));

    if ($mw != WVR_WIDTH)	{			/* non-default width means override footer, etc. */
	weaver_f_write($sout, sprintf("#access .menu-header, #access2 .menu-header, #access3 .menu-header, div.menu, #colophon, #branding, #main, #wrapper { width: %dpx; }\n",$mw));
	weaver_f_write($sout, sprintf("#footer-widget-area .widget-area {width: %dpx !important; }\n",$fw));
	weaver_f_write($sout, sprintf("#site-info { width: %dpx;}\n",$si));
	weaver_f_write($sout, sprintf("#site-generator {text-align:right; width: %dpx; }\n",$sg));
	weaver_f_write($sout, sprintf("#site-title {width: 55%%;} "));
	weaver_f_write($sout, sprintf("#site-description {text-align:right; padding-right: 20px; width: 40%%;}\n"));
	weaver_f_write($sout, sprintf("#access, #access2, #access3 {width: %dpx; }\n",$mw));
	weaver_f_write($sout, sprintf("#access .menu-header, #access2 .menu-header, #access3 .menu-header, div.menu {width: %dpx;}\n",$mw-12));
	weaver_f_write($sout, sprintf("#content .attachment img {max-width: %dpx;}\n",$caw));
	weaver_f_write($sout, sprintf(".single-attachment #content {width: %dpx;}\n",$caw));
	weaver_f_write($sout, sprintf(".one-column #content {margin: 0 auto !important; width: %dpx;}\n",$ocw));
	weaver_f_write($sout, sprintf("#main {margin-bottom:4px;}\n"));
	weaver_f_write($sout, sprintf(".one-column #ttw-top-widget, .one-column #ttw-bot-widget, .one-column #ttw-site-top-widget,
 .one-column #ttw-site-bot-widget, .one-column #per-page-widget { margin-left:%dpx !important; margin-right:auto !important; width: %dpx !important;}\n",
	    (int)($mw*.045),$ocw));

	$altcontainer = $mw - 240;
	// alt templates
	weaver_f_write($sout, sprintf(".right-alt #container {width: %dpx;}
.right-alt #content {width: %dpx;}
.right-alt #content img {max-width: %dpx;}\n",$altcontainer, $altcontainer-20,$altcontainer-30));
	weaver_f_write($sout, sprintf( ".left-alt #content {width: %dpx;}
.left-alt #contentl img {max-width: %dpx;}",$altcontainer-42, $altcontainer-50));
    } elseif ($fw_use != 4) {
	weaver_f_write($sout, sprintf("#footer-widget-area .widget-area {width: %dpx !important; }\n",$fw));
    }

    if ($sidebars == weaver_SB_none) { 	/* no sidebars - simply hide them */
	if ($themewidth != WVR_WIDTH || $sidebarwidth || $tbmult == 1) {
	    $sidebarwidth = 0; /* use default if not set */
	    /* contentwidth + primary_secondary_width == (mainwidth-50) */
	    $contentw = (int)($mw - 50 - $sidebarwidth);	/* from formula */
	    $containerw = (int)($contentw + 38);		/* contentwidth + 38 */
	    if (weaver_getopt('ttw_wide_top_bottom')) $ttwwid = $contentw;	// same as content?
	    else $ttwwid = (int)($contentw - 70);		/* contentwidth - 70 */

	    weaver_f_write($sout, sprintf("#container { float: left; margin: 0 0px 4px 0; width: %dpx; }\n",$containerw));
	    weaver_f_write($sout, sprintf("#content {width: %dpx; overflow:hidden; margin:0 0px 10px 0px; padding: 5px 0px 0px 20px;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#content img { max-width: %dpx;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#primary, #secondary { visibility:hidden; width:0px; height: 0px;}\n"));
	    weaver_f_write($sout, sprintf(".one-column #ttw-top-widget, .one-column #ttw-bot-widget, .one-column #ttw-site-top-widget, .one-column #ttw-site-bot-widget { margin-left:80px !important; margin-right:auto !important; width: %dpx !important;}\n",(int)($contentw*.85)));
	    if (weaver_getopt('ttw_wide_top_bottom')) weaver_f_write($sout,
		sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: %dpx; margin-left: 20px;}\n",$ttwwid));
	    else weaver_f_write($sout, sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: %dpx;}\n",$ttwwid));

	} else {	/* using defaults, so make shorter */

	    weaver_f_write($sout, sprintf("#container { width:940px; margin: 0px 0px -30px 0px; }
#content { width: 860px; margin: 0 100px 30px 0px; overflow:hidden; padding-top: 10px;}
#content img { max-width: 860px;}
#primary { visibility:hidden; width:0px; height: 0px;}
#secondary { visibility:hidden; width:0px; height: 0px;}
#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: 800px;}\n"));
	}
    } elseif ($sidebars == weaver_SB_2c) {	/* 2 sidebars, main central column */
	if ($themewidth != WVR_WIDTH || $sidebarwidth || $tbmult == 1 || $sb_adjust != 0) {
	    if (! $sidebarwidth) $sidebarwidth = 220; /* use default if not set */
	    /* contentwidth = mainwidth - 40 - (2*sidebarwidth ) */
	    $contentw = (int)($mw - 40 - ($sidebarwidth*2));	/* from formula */
	    $containerw = (int)($mw);		/* same a mw */
	    $ttwwid = (int)($contentw * $tbmult);	/* 85%  or 100% */
	    if ($tbmult == 1) {$ttwmargin = $sidebarwidth+20; $ttwwid -= 10; }
	    else $ttwmargin = (int)($sidebarwidth + $contentw * .115);

	    if (weaver_getopt('ttw_useborders')) $second_left = (int)$sidebarwidth+6;
	    else $second_left = (int)$sidebarwidth+4;

	    weaver_f_write($sout, sprintf("\n#container { width:%dpx; float:left; margin:0 0 4px 0px;}\n",$containerw));
	    weaver_f_write($sout, sprintf("#content { width: %dpx; margin: 0px 0px 5px %dpx; overflow:hidden; padding: 5px 20px 4px 20px; }\n",
		$contentw,$sidebarwidth));
	    weaver_f_write($sout, sprintf("#content img { max-width: %dpx;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#primary { width:%dpx; float:left; margin: 0 0 4px -%dpx; }\n",$sidebarwidth-6-$sb_adjust,$mw));
	    weaver_f_write($sout, sprintf("#secondary { width:%dpx; float:left; margin: 0 0 4px -%dpx;}\n",$sidebarwidth-6-$sb_adjust,$second_left));
	    weaver_f_write($sout, sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: %dpx; margin-left: %dpx;}\n",$ttwwid, $ttwmargin));
	} else {	/* using defaults, so make shorter */
	    weaver_f_write($sout, sprintf("#container { width:940px; float:left; margin:0 0 4px 0px; }
#content { width: 460px; margin: 0px 0px 5px 220px; overflow:hidden; padding: 5px 20px 4px 20px; }
#content img { max-width: 460px;}
#primary { width:214px; float:left; margin: 0 0 4px -940px; }
#secondary { width:214px; float:left; margin: 0 0 4px -226px;}
#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: 400px; margin-left: 265px;}\n"));
	}
    } elseif ($sidebars == weaver_SB_2r) {
	if ($themewidth != WVR_WIDTH || $sidebarwidth || $tbmult == 1 || $sb_adjust != 0) {
	    if (! $sidebarwidth) $sidebarwidth = 220; /* use default if not set */
	    $sb2 = (int)($sidebarwidth*.75);
	    $contentw = (int)($mw - 60 - $sidebarwidth - $sb2);	/* from formula */
	    if (weaver_getopt('ttw_useborders')) $containerw = (int)($contentw + 36);
	    else $containerw = (int)($contentw + 40);
	    $ttwwid = (int)($contentw * $tbmult);
	    if ($tbmult == 1) { $ttwmargin = 0; $ttwwid += 5; }
	    else $ttwmargin = (int)($contentw*.115);

	    weaver_f_write($sout, sprintf("#container { width:%dpx; float:left; margin:0 0px 4px 0px;}\n",$containerw));
	    weaver_f_write($sout, sprintf("#content {width: %dpx; overflow:hidden; margin:0 0px 10px 0px; padding: 5px 0px 0px 20px;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#content img { max-width: %dpx;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#primary { width:%dpx; float:left; margin:0 0px 4px 0px;}\n",$sidebarwidth-$sb_adjust));
	    weaver_f_write($sout, sprintf("#secondary { width:%dpx; float:left; margin:0 0 4px 0px;}\n",$sb2));
	    weaver_f_write($sout, sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: %dpx;margin-left:%dpx;}\n",$ttwwid,$ttwmargin));
	} else {	/* using defaults, so make shorter */
	weaver_f_write($sout, sprintf("#container { width:525px; float:left; margin:0 0px 4px 0px;}
#content { width: 490px; overflow:hidden; margin:0 0px 10px 0px; padding: 5px 0px 0px 20px;}
#content img { max-width: 490px;}
#primary { width:220px; float:left; margin:0 0px 4px 0px;}
#secondary { width:170px; float:left; margin:0 0 4px 0px;}
#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: 420px; margin-left: 40px;}\n"));
	}
    } elseif ($sidebars == weaver_SB_2l) {
	if ($themewidth != WVR_WIDTH || $sidebarwidth || $tbmult == 1 || $sb_adjust != 0) {
	    if (! $sidebarwidth) $sidebarwidth = 220; /* use default if not set */
	    $sb2 = (int)($sidebarwidth*.75);
	    $contentw = (int)($mw - 60 - $sidebarwidth - $sb2);	/* from formula */
	    if (weaver_getopt('ttw_useborders')) $containerw = (int)($contentw + 36);
	    else $containerw = (int)($contentw + 40);
	    $ttwwid = (int)($contentw * $tbmult);
	    if ($tbmult == 1) $ttwmargin = 18;
	    else $ttwmargin = (int)($contentw*.115);

	    weaver_f_write($sout, sprintf("#container { width:%dpx; float:right; margin:0 0 4px 0px;}\n",$containerw));
	    weaver_f_write($sout, sprintf("#content { width: %dpx; overflow:hidden; float:right; padding: 5px 10px 5px 0px; margin:0 10px 4px 0px;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#content img { max-width: %dpx;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#primary { width:%dpx; float:left; margin:0 0px 4px 0px;}\n",$sidebarwidth-4-$sb_adjust));
	    weaver_f_write($sout, sprintf("#secondary { width:%dpx; float:left; margin:0 0 4px 0px; clear:none;}\n",$sb2));
	    weaver_f_write($sout, sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: %dpx;margin-left:%dpx;}\n",$ttwwid,$ttwmargin));
	    weaver_f_write($sout, sprintf(
		".one-column #content {margin-right: 20px !important; padding-left:20px; width: %dpx;}\n",$ocw+20));
	    } else {	/* using defaults, so make shorter */
	    weaver_f_write($sout, sprintf("#container { width:530px; float:right; margin:0 0 4px 0px;}
#content { width: 490px; overflow:hidden; float:right;  padding: 5px 10px 5px 0px; margin:0 10px 4px 0px;}
#content img { max-width: 490px;}
#primary { width:216px; float:left; margin:0 0px 4px 0px;}
#secondary { width:170px; float:left; margin:0 0 4px 0px; clear:none;}
#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: 420px;}
.one-column #content {margin-right: 20px !important; padding-left:20px; width: 850px;}\n"));

	}
    } elseif ($sidebars == weaver_SB_1l) {
	if ($themewidth != WVR_WIDTH || $sidebarwidth || $tbmult == 1 || $sb_adjust != 0) {
	    if (! $sidebarwidth) $sidebarwidth = 220; /* use default if not set */
	    $contentw = (int)($mw - 70 - $sidebarwidth);	/* from formula */
	    $ttwwid = (int)($contentw * $tbmult);
	    if ($tbmult == 1) $ttwmargin = 30;
	    else $ttwmargin = (int)($contentw*.115);

	    weaver_f_write($sout, sprintf("#container { float: right; margin: 0 -%dpx 4px 0; width: 100%%;}\n",$sidebarwidth+20));
	    weaver_f_write($sout, sprintf("#content { margin: 0px %dpx 4px 0px; width: %dpx; padding: 10px 25px 5px 25px;}\n",
		$sidebarwidth+20,$contentw));
	    weaver_f_write($sout, sprintf("#content img { max-width: %dpx;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#container.one-column-iframe #content {margin:0 0 0 -%dpx;padding:0px;width:100%%;}\n",$sidebarwidth+20));
	    weaver_f_write($sout, sprintf("#primary, #secondary { float: left;  width: %dpx; padding-left: 15px; margin-bottom:4px;}\n",$sidebarwidth+3-$sb_adjust));
	    weaver_f_write($sout, sprintf("#secondary { clear: left; }\n"));
	    weaver_f_write($sout, sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: %dpx; margin-left: %dpx;}\n",$ttwwid, $ttwmargin));
	    //weaver_f_write($sout, sprintf(".one-column #ttw-top-widget, .one-column #ttw-bot-widget, .one-column #ttw-site-top-widget, .one-column #ttw-site-bot-widget, .one-column #per-page-widget { margin-left:-%dpx !important; margin-right:auto !important; width: %dpx !important;}\n",
		//		  (int)($sidebarwidth-20), (int)($mw*.88-10)));
  	} else {	/* using defaults, so make shorter */
	    weaver_f_write($sout, sprintf( "#container { float: right; margin: 0 -240px 4px 0; width: 100%%;}
#content { margin: 0px 240px 4px 0px; width: 640px; padding: 10px 25px 5px 25px;}
#container.one-column-iframe #content {margin:0 0 0 -240px;padding:0;width:100%%;}
#content img { max-width: 640px;}
#primary, #secondary { float: left;  width: 223px; padding-left: 15px; margin-bottom:4px;}
#secondary { clear: left;}
#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: 580px;}\n"));
	}
    } elseif ($sidebars == weaver_SB_1rw) {
	if ($themewidth != WVR_WIDTH || $sidebarwidth  || $tbmult == 1 || $sb_adjust != 0) {
	    if (! $sidebarwidth) $sidebarwidth = 300; /* use default if not set */
	    /* contentwidth + primary_secondary_width == (mainwidth-50) */
	    $contentw = (int)($mw - 50 - $sidebarwidth);	/* from formula */
	    $containerw = (int)($contentw + 38);		/* contentwidth + 38 */
	    $ttwwid = (int)($contentw - 70);		/* contentwidth - 70 */
	    if ($tbmult == 1) $ttwwid = $contentw;

	    weaver_f_write($sout, sprintf("#container { float: left; margin: 0 0px 4px 0; width: %dpx; }\n",$containerw));
	    weaver_f_write($sout, sprintf("#content {width: %dpx; overflow:hidden; margin:0 0px 10px 0px; padding: 5px 0px 0px 20px;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#content img { max-width: %dpx;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#primary, #secondary { float: right; overflow: hidden; width: %dpx; margin: 0 0 4px 0;}\n",$sidebarwidth-$sb_adjust));
	    if ($tbmult == 1) weaver_f_write($sout, sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: %dpx; margin-left: 1px; margin-right: 1px;}\n",$ttwwid));
	    else weaver_f_write($sout, sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: %dpx;}\n",$ttwwid));
	} else {	/* using defaults, so make shorter */
	    weaver_f_write($sout, sprintf("#main {margin-bottom:4px;}
#container { float: left; margin: 0 0px 4px 0; width: 628px; }
#content {width: 590px; overflow:hidden; margin:0 0px 10px 0px; padding: 5px 0px 0px 20px;}
#content img { max-width: 590px;}
#primary, #secondary { float: right; overflow: hidden; width: 300px; margin: 0 0 4px 0;}
#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: 520px;}\n"));
	}
    } else {		/* default right sidebar */
	if ($themewidth != WVR_WIDTH || $sidebarwidth || $tbmult == 1 || $sb_adjust != 0) {
	    if (! $sidebarwidth) $sidebarwidth = 220; /* use default if not set */
	    /* contentwidth + primary_secondary_width == (mainwidth-50) */
	    $contentw = (int)($mw - 50 - $sidebarwidth);	/* from formula */
	    $containerw = (int)($contentw + 38);		/* contentwidth + 38 */
	    $ttwwid = (int)($contentw - 70);		/* contentwidth - 70 */
	    if ($tbmult == 1) $ttwwid = $contentw;

	    weaver_f_write($sout, sprintf("#container { float: left; margin: 0 0px 4px 0; width: %dpx; }\n",$containerw));
	    weaver_f_write($sout, sprintf("#content {width: %dpx; overflow:hidden; margin:0 0px 10px 0px; padding: 5px 0px 0px 20px;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#content img { max-width: %dpx;}\n",$contentw));
	    weaver_f_write($sout, sprintf("#primary, #secondary { float: right; overflow: hidden; width: %dpx; margin: 0 0 4px 0;}\n",$sidebarwidth-$sb_adjust));
	    weaver_f_write($sout, sprintf(".one-columnsb1r #content {margin-left: %dpx; padding: 0; width: %dpx;}\n",(int)($mw*.05),$ocw));
	    if ($tbmult == 1) weaver_f_write($sout, sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: %dpx; margin-left: 1px; margin-right: 1px;}\n",$ttwwid));
	    else weaver_f_write($sout, sprintf("#ttw-top-widget, #ttw-bot-widget, #ttw-site-top-widget, #ttw-site-bot-widget, #per-page-widget {width: %dpx;}\n",$ttwwid));
	}
    }
}

function weaver_css_fontfamily($sout, $name, $fontfamily) {
	/* fill in good set of alternate fonts */
	if (stripos($fontfamily,'(serif)')) {
		$altfont = "\"Times New Roman\", Times, serif";
	} elseif (stripos($fontfamily,'(sans-serif)')) {
		$altfont = 'Arial, Helvetica, sans-serif';
	} elseif (stripos($fontfamily,'(mono)')) {
		$altfont = 'Courier';
	} else { $altfont = 'serif';}

	$font = substr($fontfamily, 0 , strpos($fontfamily, ' (')); /* strip out font name */
	weaver_f_write($sout, sprintf( "$name {font-family: \"". $font ."\", $altfont;}\n"));
}

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

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

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