=== modified file 'src/Buffer.cpp' (properties changed: -x to +x)
--- src/Buffer.cpp	2011-12-04 03:05:08 +0000
+++ src/Buffer.cpp	2011-12-04 23:24:48 +0000
 
@@ -1777,28 +1777,83 @@
 		   << "\n<!-- Preamble Snippets -->\n"
 		   << from_utf8(features.getPreambleSnippets());
 
-		os << "\n<!-- Layout-provided Styles -->\n";
-		docstring const styleinfo = features.getTClassHTMLStyles();
-		if (!styleinfo.empty()) {
-			os << "<style type='text/css'>\n"
-				<< styleinfo
-				<< "</style>\n";
-		}
+		// Structure for Writing CSS Components
+		struct writeCSS {
+			static void writeClassHTMLStyles(XHTMLStream xs, docstring const styleinfo) {
+				// Write Styles
+				if (!styleinfo.empty()) {
+					xs << styleinfo
+						<< "\n";
+				}
+			}
+
+			static void writeFgBg(XHTMLStream xs, bool needfg, bool needbg,
+								  lyx::RGBColor fontcolor, lyx::RGBColor backgroundcolor) {
+				if (needfg || needbg) {
+					xs << "\nbody {\n";
+					if (needfg)
+					   xs << "  color: "
+							<< from_ascii(X11hexname(fontcolor))
+							<< ";\n";
+					if (needbg)
+					   xs << "  background-color: "
+							<< from_ascii(X11hexname(backgroundcolor))
+							<< ";\n";
+					xs << "}\n";
+				}
+			}
+		};
+
+		// Check to see if HTML Stylesheet should be written as part of XHTML or as separate CSS
 
 		bool const needfg = params().fontcolor != RGBColor(0, 0, 0);
 		bool const needbg = params().backgroundcolor != RGBColor(0xFF, 0xFF, 0xFF);
-		if (needfg || needbg) {
-				os << "<style type='text/css'>\nbody {\n";
-				if (needfg)
-				   os << "  color: "
-					    << from_ascii(X11hexname(params().fontcolor))
-					    << ";\n";
-				if (needbg)
-				   os << "  background-color: "
-					    << from_ascii(X11hexname(params().backgroundcolor))
-					    << ";\n";
-				os << "}\n</style>\n";
-		}
+
+		XHTMLStream xsm(os);
+
+		if (params().html_css_as_file) {
+
+			lyxerr << "\nExport Separate CSS: True";
+
+			// Create a Link to the Stylesheet
+			os << "<link rel='stylesheet' href='docstyle.css' type='text/css' />\n";
+
+			// Create a New Stream for CSS
+			ofdocstream ocss;
+			string const fcssname = addName(temppath(), "docstyle.css");
+			XHTMLStream xcss(ocss);
+
+			// Check to see if it is open
+			if (!openFileWrite(ocss, FileName(fcssname)))
+				return;
+
+			writeCSS::writeClassHTMLStyles(xcss, features.getTClassHTMLStyles());
+			writeCSS::writeFgBg(xcss, needfg, needbg, params().fontcolor, params().backgroundcolor);
+
+			// Close Data File and Export to Destination Folder
+			ocss.close();
+			runparams.exportdata->addExternalFile("xhtml", FileName(fcssname));
+
+			if (ocss.fail()) {
+				lyxerr << "File '" << fcssname << "' was not closed properly." << endl;
+				// Failed to Write to CSS, Export to HTML
+				os << "\n<!-- Layout-provided Styles -->\n";
+				os << "\n<style type='text/css'>\n";
+				writeCSS::writeClassHTMLStyles(xsm, features.getTClassHTMLStyles());
+				writeCSS::writeFgBg(xsm, needfg, needbg, params().fontcolor, params().backgroundcolor);
+				os << "\n</style>\n";
+			}
+		}
+
+		else  {
+			lyxerr << "\nExport Separate CSS: False";
+			os << "\n<!-- Layout-provided Styles -->\n";
+			os << "\n<style type='text/css'>\n";
+			writeCSS::writeClassHTMLStyles(xsm, features.getTClassHTMLStyles());
+			writeCSS::writeFgBg(xsm, needfg, needbg, params().fontcolor, params().backgroundcolor);
+			os << "</style>\n";
+		}
+
 		os << "</head>\n";
 	}
 

