/*
 * File is (c) Duncan Strand 2005
 *
 * You are free to use this code for non-commerical use
 * For commerical use please contact me at dstrand@zebs.org.uk
 * Please leave this message in the code though.
*/
 
function mouseover(me){
	me.style.background='#EEEEEE'
}

function mouseout(me) {
	me.style.background='#FFFFFF'
}

function showmenu(me, menu) {
	mouseover(me);
	document.getElementById(menu).style.visibility = "visible";
}

function hidemenu(me, menu) {
	mouseout(me);
	document.getElementById(menu).style.visibility = "hidden";
}

function noarrow() {
	return "<td class=\"menutext\">&nbsp;</td>\n"
}

function arrow(p2r) {
	return "<img src=\"" + p2r + "images/menu_arrow.png\" alt=\"...\" class=\"menuArrow\">\n";
}

function menu_html( p2r ) {

	var html = new String;
	html = "" +
		start_menu("menu", "") +

		// Text only
		menu_item( "textonly", "font-size: 7pt", "http://www.zebs.org.uk/cgi-bin/betsie/parser.pl", "Text Only", "Text<br>Only", false, false) +
		// Home
		menu_item( "home", "", p2r + "index.html", "Frontpage", "Home", false, false ) +
		// Search
		menu_item( "search", "", p2r + "search.htm", "Search this site", "Search", false, false) +
		// Site map
		menu_item( "sitemap", "", p2r + "site_map.htm", "Site map", "Site Map", false, false) +
		
		// About me
		menu_drop_head("aboutme", p2r, "aboutme/index.html", "About Me", "All about lil ol me", "aboutmeDropDown", false) +
			menu_item( "", "", p2r + "aboutme/aldebaran.htm", "Aldebaran", "Aldebaran", true, true ) +
			menu_item( "", "", p2r + "aboutme/background.htm", "Background", "Background", true, true ) +
			
			menu_drop_head("", p2r, "aboutme/computers.htm", "My Computers", "My Computers", "computerSub", true) +			
				menu_item( "", "", p2r + "aboutme/computers.htm", "", "Computers", true, true ) +
			menu_drop_head_end(true) +
			
			menu_item( "", "", p2r + "aboutme/car.htm", "My Car", "My Car", true, true ) +

			menu_drop_head("", p2r, "aboutme/far_side.html", "Far Side", "The Far Side", "farsidesub", true) +
				menu_item( "", "", p2r + "aboutme/far_side.htm", "", "Far Side 1", true, false ) +
				menu_item( "", "", p2r + "aboutme/far_side_2.htm", "", "Far Side 2", true, false ) +
				menu_item( "", "", p2r + "aboutme/far_side_3.htm", "", "Far Side 3", true, false ) +
				menu_item( "", "", p2r + "aboutme/far_side_4.htm", "", "Far Side 4", true, false ) +
			menu_drop_head_end(true) +

			menu_item( "", "", p2r + "aboutme/funny_stuff.htm", "Humour", "Humour", true, true ) +
			menu_item( "", "", p2r + "aboutme/pictures.htm", "Pictures", "Pictures", true, true ) +
	
			menu_drop_head("", p2r, "webcam/index.html", "Webcam", "Webcam", "webcamsub", true) +
				menu_item( "", "", p2r + "webcam/recent.html", "Recent", "Recent", true, false ) +
				menu_item( "", "", p2r + "webcam/larrycam/index.html", "Larry Cam", "Larry Cam", true, false ) +                     
			menu_drop_head_end(true) +
		menu_drop_head_end(false) +
		
		// About the site
		menu_drop_head("aboutsite", p2r, "code/index.html", "About Site", "About this sites code", "AboutsiteDropDown", false) +
			menu_item( "", "", p2r + "code/menu.html", "", "Menu Code", true, false ) +
		menu_drop_head_end(false) +
		
		// Software
		menu_drop_head("software", p2r, "software/index.html", "Software", "Software", "softwareDropDown", false) +
			menu_item( "", "", p2r + "software/mp3db.htm", "", "mp3db", true, false ) +
			menu_item( "", "", p2r + "software/crossedlines.htm", "", "Crossed Lines", true, false ) +
			menu_item( "", "", p2r + "software/binomial_coefficients.htm", "", "Binomial Coefficients", true, false ) +
			menu_item( "", "", p2r + "software/reversestring.htm", "", "ReverseString", true, false ) +
			menu_item( "", "", "", "", "<hr>", true, false ) +
			menu_item( "", "", p2r + "software/wip.htm", "", "Work in progress", true, false ) +
			menu_item( "", "", "", "", "<hr>", true, false ) +
			menu_item( "", "", p2r + "software/btec_nat_diploma.htm", "", "College programs", true, false ) +
		menu_drop_head_end(false) +

		// Uni stuff
		menu_drop_head("unistuff", p2r, "uni/index.html", "Uni Stuff", "My Uni work", "uniDropDown", false) +		
		// Uni Sub menus
		// Year 1
			menu_drop_head("", p2r, "", "Year 1", "Year 1", "uniYear1Sub", true) +
				menu_item( "", "", p2r + "uni/year1/csys1050/index.html", "", "CSYS1050 Computer Architecture", true, false ) +
				menu_item( "", "", p2r + "uni/year1/bsys1051/index.html", "", "BSYS1051 Business Communication Skills", true, false ) +
				menu_item( "", "", p2r + "uni/year1/soft1053/index.html", "", "SOFT1053 C++", true, false ) +
				menu_item( "", "", p2r + "uni/year1/soft1052/index.html", "", "SOFT1052 C++", true, false ) +
			menu_drop_head_end(true) +


		// Year 2
			menu_drop_head("", p2r, "", "Year 2", "Year 2", "uniYear2Sub", true) +
				menu_item( "", "", p2r + "uni/year2/soft2052/index.html", "", "SOFT2052 Java", true, false ) +
				menu_item( "", "", p2r + "uni/year2/csys2056/index.html", "", "SOFT2056 Operating Systems", true, false ) +
				menu_item( "", "", p2r + "uni/year2/bsys2050/index.html", "", "BSYS2050 Exhibition", true, false ) +
				menu_item( "", "", p2r + "uni/year2/csys2051/index.html", "", "CSYS2051 Networks and Communications", true, false ) +
				menu_item( "", "", p2r + "uni/year2/cprj2050/index.html", "", "CPRJ2050 Group Project (Java)", true, false ) +
				menu_item( "", "", p2r + "uni/year2/cprj2053/index.html", "", "CPRJ2053 Inividual Project", true, false ) +
			menu_drop_head_end(true) +


		// Year 3 Sem 5
			menu_drop_head("", p2r, "", "Year 3 Semester 5", "Year 3 Semester 5", "uniYear3Sem5Sub", true) +
				menu_item( "", "", p2r + "uni/year3sem5/soft2057/index.html", "", "SOFT2057 Computer Graphics", true, false ) +
				menu_item( "", "", p2r + "uni/year3sem5/cprj2052/index.html", "", "CPRJ2052 Research Project", true, false ) +
			menu_drop_head_end(true) +

		// Year 3 Sem 6
			menu_drop_head("", p2r, "", "Year 3 Semester 6", "Year 3 Semester 6", "uniYear3Sem6Sub", true) +
				menu_item( "", "", p2r + "uni/cprj3051/index.html", "", "CPRJ3051 Final Year Project", true, false ) +
				menu_item( "", "", p2r + "uni/year3sem6/soft3010/index.html", "", "SOFT3010 Object Orientated Development", true, false ) +
				menu_item( "", "", p2r + "uni/year3sem6/bsys3071/index.html", "", "BSYS3071 Innovative Trends in Information Systems", true, false ) +
				menu_item( "", "", p2r + "uni/year3sem6/isys3073/index.html", "", "ISYS3073 Advanced Database management", true, false ) +
			menu_drop_head_end(true) +

		// Year 3 Sem 7
			menu_drop_head("", p2r, "", "Year 3 Semester 7", "Year 3 Semester 7", "uniYear3Sem7Sub", true) +
				menu_item( "", "", p2r + "uni/cprj3051/index.html", "", "CPRJ3051 Final Year Project", true, false ) +
				menu_item( "", "", p2r + "uni/year4sem7/isys3072/index.html", "", "ISYS3072 Database Management Systems", true, false ) +
				menu_item( "", "", p2r + "uni/year4sem7/isys3074/index.html", "", "ISYS3074 Multimedia", true, false ) +
				menu_item( "", "", p2r + "uni/year4sem7/soft3057/index.html", "", "SOFT3057 Interactive Systems", true, false ) +
			menu_drop_head_end(true) +
		menu_drop_head_end(false) +

		// Files
		menu_item( "files", "", p2r + "files/files.htm", "Some interesting (or not) files", "Files") +
		// Contact me
		menu_item( "contact", "", "/contact.htm", "How to contact me", "Contact") +
		// Links
		menu_item( "links", "", p2r + "links.htm", "Links to lotsa sites", "Links") +

		// Guestbook
		"	<td id='guestbook' class=\"menutext\" onmouseover='mouseover(this)' onmouseout='mouseout(this)'>\n" +
		"	<a href=\"" + p2r + "guestbook.html\">View</a> / Sign Guestbook\n" +		
//		"	<a href=\"" + p2r + "guestbook.html\">View</a> / <a href=\"" + p2r + "gbAdd1.htm\">Sign</a> Guestbook\n" +
		end_menu();

	return html;
}

function menu_drop_head( id, path2root, link, linkText, title, dropdownID, issubmenu ) {

		var str = new String;

		if( issubmenu == true ) {
			str += "<tr onmouseover='showmenu(this, \""+dropdownID+"\")' onmouseout='hidemenu(this, \"" + dropdownID +"\")'>\n";
			str += "<td class=\"menutext\" onmouseover='mouseover(this)' onmouseout='mouseout(this)'>\n";
			if(link.length > 2 )
				str += "<a href=\"" + path2root + link + "\">" + linkText + "</a>\n";
			else
				str += linkText;
			str += "</td>\n";
			str += "<td class=\"menutext\">\n";
			str += arrow(path2root);
			str += "<div id='" + dropdownID + "' class='DivMenuSub'>\n";
			str += "<table cellspacing=0>\n";
		}
		else {
			str += "<td id='" + id + "' class=\"menutext\" onmouseover='showmenu(this, \"" + dropdownID + "\")' onmouseout='hidemenu(this, \"" + dropdownID + "\")'>\n";
			str += "<a href=\"" + path2root + link + "\" title=\"" + title + "\">" + linkText + "</a><br>\n";
			str += "<div id='" + dropdownID + "' class='DivMenu'>\n";
			str += "<table cellspacing=0>\n";
		}
		
		return str;
}

function menu_drop_head_end(issubmenu) {
	
	var str = new String();
	
	if( issubmenu == false ) {
		str = "</table></div>\n</td>\n";
	}
	else {
		str = "</table></div>\n</td>\n</tr>\n";
	}

	return str;
}

function menu_item( id, style, path, title, text, tr, hidearrow) {
	var string = new String();

	if( tr == true )
		string = "<tr>\n";

	string += "<td ";
	string += (id.length > 1)?"id='" + id + "' ": "" // only include ID if needed
	string += "class=\"menutext\" ";
	
	string += (style.length > 1)? "style='" + style + "' " : "";
	string += "onmouseover='mouseover(this)' onmouseout='mouseout(this)'>\n";

	string += (path.length >1)?"<a href=\"" + path + "\" title=\"" + title + "\">" + text + "</a>\n" : text;
	string += "</td>\n";

	if( hidearrow == true )
		string += noarrow();

	if( tr == true )
		string += "</tr>\n";

	return string;
}

function start_menu(clss, style) {
	var html = new String();
	html = "<table class=\"" + clss + "\" id=\"menubar\"";
	html += (style.length > 1) ? "style=\"" + style + "\">" : ">";
	html += "<tr>";
	return html;
}

function end_menu() {
	return "</tr></table>\n";
}

function bottom_html( pathToRoot, validHTML, validCSS ) {

	var theHTML = "" +
	"<br clear=all>\n" +
	"<hr>\n" +
	"<table style=\"width: 100%;  border-collapse: collapse\">\n" +
	"<tr>\n" +
	"	<td align=left width=20%><a href=\'http://portal.plus.net/my/mydiscount_info/landing_page.html?WRKUh%2Fz%2FuZ5dXmEjImm%2BIMDUSCqWiITK7fOasYNi1BU%3D\'><img src=\'http://portal.plus.net/images/banners/banner_10.gif\' border=\'0\' alt=\"Sign up with Plus.net!\"></a></td>\n";

	if( validHTML == true ) {
			theHTML += "" +
			"	<td align=center width=20%><a href=\"http://validator.w3.org/check?uri=referer\"><img border=\"0\" src=\"http://www.w3.org/Icons/valid-html401\" alt=\"Valid HTML 4.01!\" height=\"31\" width=\"88\"></a>\n";
	}
	else {
			theHTML += "<td width=20%></td>\n";
	}

	theHTML += "<td align=center width=20%><a href=\"http://www.spreadfirefox.com/?q=affiliates&amp;id=0&amp;t=61\"><img border=\"0\" alt=\"Get Firefox!\" title=\"Get Firefox!\" src=\"http://sfx-images.mozilla.org/affiliates/Buttons/110x32/trust.gif\"/></a></td>\n";
	if( validCSS == true ) {
			theHTML += "" +
			"	<td align=center width=20%><a href=\"http://jigsaw.w3.org/css-validator/\"><img src=\"http://jigsaw.w3.org/css-validator/images/vcss\" alt=\"Valid CSS!\"></a>\n";
	}
	else {
			theHTML += "<td width=20%></td>\n";
	}

	// if an empty "pathtoroot" is set then ignore it (otherwise amazon logo isn't displayed
	if( pathToRoot.length == 0 ) {
			theHTML += "	<td align=right width=20%><a href=\"http://www.amazon.co.uk/exec/obidos/redirect-home?tag=zebs&amp;site=amazon\"><img alt=\"Amazon.co.uk Logo on White Background\" border=0 src=\"images/amazon_logo.png\" align=\"middle\" width=\"125\" height=\"27\"></a></td>\n";
	}
	else {
			theHTML += "	<td align=right width=20%><a href=\"http://www.amazon.co.uk/exec/obidos/redirect-home?tag=zebs&amp;site=amazon\"><img alt=\"Amazon.co.uk Logo on White Background\" border=0 src=\"" + pathToRoot + "/images/amazon_logo.png\" align=\"middle\" width=\"125\" height=\"27\"></a></td>\n";
	}
	theHTML += 
	"</tr>\n" +
	"</table>\n" +
	"<div align=right style=\"text-align: right; font-size: x-small\">(c)2007 Duncan Strand</div>\n";

	return theHTML;
}

function display_html( pathToRoot, item, write ) {
	var theHTML = new String;
	//var re = new RegExp

	if( item == "menu" )    
			theHTML = menu_html(pathToRoot);
	else
			theHTML = bottom_html( pathToRoot, true, true );

	/*theHTML = theHTML.replace(/</gi, "&lt;");	// Replace < with &lt;
	theHTML = theHTML.replace(/>/gi, "&gt;") 	// Replace > with &gt;
	theHTML = theHTML.replace(/\n/gi, "<br>");	// Replace \n with <br>*/

	if( write == true )
		document.write( theHTML );
	
	return theHTML
}

function print_bottom_bar( pathToRoot, validHTML, validCSS ) {
	document.write( bottom_html( pathToRoot, validHTML, validCSS ) );
}

function print_top_toolbar( pathToRoot ) {
	document.write( menu_html(pathToRoot) );
}
