// AP2 Javascript
// v simp stylesh switcher and cookie subs (rest in chimney)

// set common vars if undef
if (!legit_styles)
{
var w, t, r, stylesheet, AP2_urchin, legit_styles;
w = window; t = document; r = true;
stylesheet = "AP2"; AP2_urchin = "AP2";
legit_styles = new Array("a", "b", "c", "d", "e", "f", "g", "x", "y", "z");
}

// find stylesheet
function fs(depth)
{
var brain, style;
if (depth == 0) { brain = ""; }
else if (depth == 2) { brain = "../../brain/"; }
else { brain = "../brain/"; }
style = which_style();
document.writeln("<link rel='stylesheet' type='text/css' href='" + brain + style + ".css'>");
}

// determine style
function which_style()
{ return stylesheet + check_style(rifle_urchin(AP2_urchin)); }

// check it's legit
function check_style(style_to_check)
{
for (var f = 0; f < legit_styles.length; f ++)
{ if (style_to_check == legit_styles[f]) { return style_to_check; } }
return legit_styles[0];
}

// read
function rifle_urchin(urchin)
{
var urchin_height, urchin_parade, f, suspicious_urchin, pockets;
urchin += "=";
urchin_height = urchin.length;
urchin_parade = t.cookie.length;
f = 0; while (f < urchin_parade)
{
suspicious_urchin = urchin_height + f;
if (t.cookie.substring(f, suspicious_urchin) == urchin)
{
pockets = t.cookie.indexOf("; ", suspicious_urchin);
if (pockets == -1) { pockets = t.cookie.length; }
urchin = t.cookie.substring(suspicious_urchin, pockets);
return(urchin.substring(urchin.length - 2, urchin.length - 1));
}
f = t.cookie.indexOf(" ", f) + 1; if (f == 0) { break; }
}
return false;
}

// reading a page directly? Add link to correct start point
// (always index.html, which may in turn point to start, for local portability)
function AP2()
{
if (!window.name) { document.writeln("<div class='line'><hr></div>\r\r<p class='red_centre_big'>ALERT! You've leapt into the middle of things. <a class='la' href='index.html' target='_top'>Start AP2 properly</a>.</p>\r\r<p class='red_centre_small'>AP2 and contents are (c) The A-Nows and A-Now Software. Every right reserved. You are free to examine AP2 for your own personal use but cannot, for example, put it on a CD and sell it or something. Commercial reproduction strictly prohibited. See the Credits page for more info.</p>\r\r<div class='line'><hr></div>"); }
}