//	styswt.js	Style-switcher JS routines
//
//	(c) Andy Belcher 2006
//
//	ONLOAD - write alternate stylesheets into page head.
//	Load current stylesheet as default as avoids sceen-blink on sitchover
//
var ckOk = 0;
//
if(styleSwitch)
	{var curCkSty = readCookie(styCk);
	for(var i=0;i<styCtr;i++) {if(styCss[i] == curCkSty) {ckOk = 1;}}
	if(!ckOk) {curCkSty = "";}
	var alter = "";
	if(curCkSty)
		{dw("<link rel=\"stylesheet\" type=\"text/css\" "
			+ "href=\"/css/"+curCkSty+".css\" title=\""+curCkSty+"\" />");
		alter = "alternate ";
		}
	for(var i=0;i<styCtr;i++)
		{if((curCkSty) && (curCkSty == styCss[i])) {continue;}
		dw("<link rel=\""+alter+"stylesheet\" type=\"text/css\" "
			+ "href=\"/css/"+styCss[i]+".css\" title=\""+styCss[i]+"\" />");
		if(!alter) {curCkSty = styCss[i];}
		alter = "alternate ";
		}
	writeCookie(styCk,curCkSty);
	}
//
//	Includes INITIALISATION FOR SLIDING NAV_BAR
window.onload = function(e) {
	if(styleSwitch) {setActiveStyleSheet();}
	initMvBar();
	}
//
function drawStyleSelect() {
	if(!styleSwitch) {return;}
	dw("Choose a style: <select name=\"selsty\" id=\"selsty\">");
	var curSty = readCookie(styCk);
	for(var i=0;i<styCtr;i++)
		{var sel = "";if(curSty == styCss[i]) {sel = "selected=\"selected\"";}
		dw("<option value=\""+styCss[i]+"\" "+sel+">"+styTit[i]+"</option>");
		}
	dw("</select> <input type=\"submit\" class=\"button\" "
		+ "value=\"Change Style...\" onclick=\"changeStyle();\" /> "
		+ "<br /><a href=\"#\" onclick=\"switchClass('stynote','show');return false;\" "
		+ "title=\"Jump to the foot of the page to "
		+ "find out more about this particular style and style switching in "
		+ "general...\">More information on this style...</a>"
		+ "&#8212; <a href=\"#\" onclick=\"switchClass('styswt','hide');return false;\" "
		+ "title=\"Hide this style-switcher, to reveal it REFRESH "
		+ "[F5] the page or go to another page...\">Hide this form...</a>"
		+ "&#8212; <a href=\"#\" onclick=\"hideform();return false;\" "
		+ "title=\"Disable this style-switcher completely, to reveal it click "
		+ "the link at the foot of the page...\">Disable form</a>"
		+ "<div id=\"stynote\" class=\"hide\">"
		+ "<a style=\"font-size:12pt;font-weight:bold;\" href=\"#\" onclick=\"switchClass('stynote','hide');return false;\" title=\"Hide this information...\">Hide this section</a>"
		+ "<h3>About this style...</h3>\n"
		+ "<p id=\"stytxt\">?</p><h3>About these pages...</h3>"
		+ "<p>Here we have a set of website pages containing the required content marked up in HTML. All of the formatting is handled by CSS, the instructions are contained within a separate style sheet, thus we have a complete separation of content from style.</p>\n"
		+ "<p>The style-switcher allows alternative CSS instructions to be used instead, which allows us to use more than one style, theme or 'skin' to display all of the pages for this website; choose from Spring, Summer, Autumn or Winter.</p>\n"
		+ "<p>Select the required style from the selection above and without any change of content the whole website undergoes a complete transformation. This gives a clear <strong>demonstration of the 'separation' principle</strong> and a way to show different styles.</p>\n"
		+ "<h3>Using the Style-Switcher...</h3>\n"
		+ "<p>Your preferred style will be stored in a session cookie, on your later return to this website the style will be 'remembered.</p>\n"
		+ "<p>Hiding the style form will remove it from display until you refresh the page when it will reappear. Disabling the form will turn it off completely, this too is 'remembered' via a cookie for later sessions. The form can be restored by clicking the link at the foot of the page.</p>\n"
		+ "</div><!--stynote-->");
	}
//
function changeStyle() {
	if(!styleSwitch) {return;}
	setActiveStyleSheet(getObjectByAnyMeans("selsty").value);
	}
//
function hideform() {
	if(!styleSwitch) {return;}
	writeCookie('showform',0,1);
	switchClass('styswt','hide');
	switchClass('styfoot','show');
	}
//
function unhideform() {
	if(!styleSwitch) {return;}
	writeCookie('showform',1,1);
	switchClass('styswt','show');
	switchClass('styfoot','hide');
	}
//
function setActiveStyleSheet(reqSty) {
	if(!styleSwitch) {return;}
	if(!reqSty) {reqSty = readCookie(styCk);}
	if(!reqSty) {reqSty = styCss[0];}
	if(readCookie('showform'))
		{switchClass('styswt','show');
		switchClass('styfoot','hide');
		}
	else
		{switchClass('styswt','hide');
		switchClass('styfoot','show');
		}
	writeCookie(styCk,reqSty,365);
	var i,a,main;
	for(i=0;(a=document.getElementsByTagName("link")[i]);i++)
  		{if((a.getAttribute("rel").indexOf("style") != -1) && (a.getAttribute("title")))
			{a.disabled = true;
			if(a.getAttribute("title") == reqSty) {a.disabled = false;}
			}
		}
	for(var z=0;z<=styCtr;z++)
		{if(styCss[z] == reqSty) {switchText("stytxt",styTxt[z]);}}
	}
//
//	EOF
//
