// ------------------------------------------------------------------
// (c) 2008-2010 Thunor <thunorsif@hotmail.com>
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Functions
// ------------------------------------------------------------------

// ------------------------------------------------------------------
// logowrite.
// ------------------------------------------------------------------
// On entry:
//	level = the number of "../"s that should prefix "images/"

function logowrite(level) {
	var logo = 0;
	var logostring = "";
	
	logo = Math.round(Math.random() * 4);
	switch (logo) {
		/* case 0:
			logostring = "teleport";
			break;
		case 1:
			logostring = "bear";
			break;
		case 2:
			logostring = "robbo";
			break;
		case 3:
			logostring = "gun";
			break;
		case 4:
			logostring = "bird";
			break;
		case 5:
			logostring = "bear_b";
			break;
		case 6:
			logostring = "butterfly";
			break;
		case 7:
			logostring = "capsule";
			break;
		case 8:
			logostring = "radioactive";
			break; */
		case 0:
			logostring = "barrier";
			break;
		case 1:
			logostring = "scoreline-moon";
			break;
		case 2:
			logostring = "scoreline-raygun";
			break;
		case 3:
			logostring = "teleporting";
			break;
		default:
			logostring = "logo";
	}

	logostring = "images/" + logostring + ".gif' alt='" + logostring + "' width='48px' height='48px'>";
	for (count = 0; count < level; count++) logostring = "../" + logostring;
	logostring = "<img src='" + logostring;
	document.write (logostring);
}

// ------------------------------------------------------------------
// mainmenuwrite.
// ------------------------------------------------------------------
// On entry:
//	current = 'eng' or 'jsataxx' etc.
//	root = 1 for root, 0 for ../

function mainmenuwrite(current, root) {

	document.write("<ul class='mainmenu'>");

	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("index.html'");
	if (current == 'blog') {
		document.write(" class='current'");
	}
	document.write("><span>Blog</span></a></li>");

	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("vintagemags/index.html'");
	if (current == 'vintagemags') {
		document.write(" class='current'");
	}
	document.write("><span>Vintage Magazine Scans</span></a></li>");
	
	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("angliasoft/index.html'><span>Angliasoft</span></a></li>");

	document.write("<li class='mainmenuitem'><a href='http://code.google.com/p/gtkdialog/'><span>Gtkdialog</span></a></li>");

	document.write("<li class='mainmenuitem'><a href='http://sz81.sourceforge.net/'><span>sz81</span></a></li>");

	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("mmcoyzx81/index.html'><span>Mastering Machine Code on Your ZX81 or ZX80</span></a></li>");
													
	document.write("<li class='mainmenuitem'><a href='http://eng.sourceforge.net/'><span>ENG</span></a></li>");
	
	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("extinct/index.html'");
	if (current == 'extinct') {
		document.write(" class='current'");
	}
	document.write("><span>Extinct</span></a></li>");
	
	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("friq/index.html'");
	if (current == 'friq') {
		document.write(" class='current'");
	}
	document.write("><span>Friq</span></a></li>");
	
	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("pipepanic/index.html'");
	if (current == 'pipepanic') {
		document.write(" class='current'");
	}
	document.write("><span>Pipepanic</span></a></li>");
	
	document.write("<li class='mainmenuitem'><a href='http://gnurobbo.sourceforge.net/'><span>GNU Robbo</span></a></li>");

	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("gnurobbo/index.html'");
	if (current == 'gnurobbo') {
		document.write(" class='current'");
	}
	document.write("><span>GNU Robbo (Embedded)</span></a></li>");
	
	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("rbvba/index.html'");
	if (current == 'rbvba') {
		document.write(" class='current'");
	}
	document.write("><span>REALbasic RbVBA</span></a></li>");
	
	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("fltetravex/index.html'");
	if (current == 'fltetravex') {
		document.write(" class='current'");
	}
	document.write("><span>Flash Tetravex</span></a></li>");
	
	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("jspp/index.html'");
	if (current == 'jspp') {
		document.write(" class='current'");
	}
	document.write("><span>JavaScript Pipepanic</span></a></li>");

	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("jscb/index.html'");
	if (current == 'jscb') {
		document.write(" class='current'");
	}
	document.write("><span>JavaScript Codebreaker</span></a></li>");

	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("jsataxx/index.html'");
	if (current == 'jsataxx') {
		document.write(" class='current'");
	}
	document.write("><span>JavaScript Ataxx</span></a></li>");
													
/*	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("packages/index.html'");
	if (current == 'packages') {
		document.write(" class='current'");
	}
	document.write("><span>Packages</span></a></li>"); */

	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("code/index.html'");
	if (current == 'code') {
		document.write(" class='current'");
	}
	document.write("><span>/code</span></a></li>");

	document.write("<li class='mainmenuitem'><a href='");
	if (!root) document.write("../");
	document.write("tmp/index.html'");
	if (current == 'tmp') {
		document.write(" class='current'");
	}
	document.write("><span>/tmp</span></a></li>");

	document.write("</ul>");
}

// ------------------------------------------------------------------
// cookiemanager.
// ------------------------------------------------------------------
// On entry:
//	action = "write" or "read".
//	name = cookie name.
//	value = cookie value.
//	days = expiry in days.
// On exit:
//	cookiemanager returns a value on read, "" if the cookie doesn't exist.
//	NOTE: if you are expecting to read a number then call it like this :-
//		mynum = Number(cookiemanager("read", bla, bla, bla))

function cookiemanager(action, name, value, days) {
	var cookiestring = document.cookie;
	var cookie = cookiestring.split(';');
	var cookiesize = cookie.length;
	var cookieloop = 0;
	var cookienamesvaluesarray = "";
	var cookievalue = "";
	var expires = new Date();
	var expirydays = expires.getTime() + (days * 24 * 60 * 60 * 1000);
	expires.setTime(expirydays);
	
	if (action == 'write') {
		document.cookie = name + "=" + value + "; expires=" + expires.toGMTString();
	} else {
		if (action == 'read') {
			for (cookieloop = 0; cookieloop < cookiesize; cookieloop++) {
				cookienamesvaluesarray = cookie[cookieloop].split("=");
				cookievalue = cookienamesvaluesarray[0];
				if (cookievalue.substr(0,1) == " ") cookievalue = cookievalue.substr(1);
				if (cookievalue == name) return cookienamesvaluesarray[1];
			}
			return "";
		}	
	}
}




