// JavaScript Document

//Descriptions of the images at the top of the page
//how many different page header pictures there are, sequentially numbered, in /images/tops/topi.jpg, where i=1..n
var numTops = 7;

//array of descriptions of the pictures
var top_pics = new Array();
var curr_top_pic = 0;

top_pics[1] = ["Coastline at dusk, Wild Coast, Eastern Cape, South Africa"];
top_pics[2] = ["Two-person light airplane, with me in it, north of Johannesburg"];
top_pics[3] = ["NASA Saturn V rocket"];
top_pics[4] = ["Weddings the Las Vegas way -- a sign on the Strip"];
top_pics[5] = ["Mountains of Death Valley desert, California"];
top_pics[6] = ["Gene Pool and Beckman Institute, California Institute of Technology"];
top_pics[7] = ["From the garden of Khomkhulu, Hogsback, in the mountains of the Eastern Cape, South Africa"];

//Menu descriptions
//NOTE: Use single quotes within onclick events only, NO double quotes!

//the menu for along the page header picture
var menu_top = new Array();

menu_top[0] = ["Home",
			"My homepage, full of the latest news and changes to the site", 
			"document.location='/'"];
menu_top[1] = ["Blog",
			"My weblog, with everything I have to say about anything, from personal news to the future of the world", 
			"showMenu('blog')"];
menu_top[2] = ["Photo Album",
			"A collection of photos, taken by me and others", 
			"showMenu('photoalbum')"];
menu_top[3] = ["Media",
			"Straight from me to you: streaming internet radio from my apartment, music files, useful programs, movies and TV shows", 
			"showMenu('media')"];
menu_top[4] = ["Links",
			"Links to websites of a few friends, Internet must-see sites and some technical sites", 
			"document.location='/links.php'"];
			
menus = new Array();

menus['blog'] = new Array();
menus['blog']['title'] = "Blog";
menus['blog'][0] = ["All posts",
			"View all my posts, on all the topics mentioned below",
			"document.location = '/wordpress'"];
menus['blog'][1] = ["Personal",
			"Posts about my daily life, and news about my studies at Caltech",
			"document.location = '/wordpress/category/personal/'"];
menus['blog'][2] = ["Politics and philosophy",
			"Thoughts on the way the world works, or should work",
			"document.location = '/wordpress/category/politics-and-philosophy'"];
menus['blog'][3] = ["Technology and science",
			"Anything that amazes me, technological or scientific -- things that I think will change the future",
			"document.location = '/wordpress/category/technology-and-science/'"];
menus['blog'][4] = ["Stuff",
			"Cool stuff, interesting internet sites",
			"document.location = '/wordpress/category/stuff/'"];
			
menus['photoalbum'] = new Array();
menus['photoalbum']['title'] = "Photo album";
menus['photoalbum'][0] = ["All photos / search",
			"An index of all the categories and sub-categories of photos, as well a tool to search photo captions",
			"document.location = '/gallery/albums.php'"];
menus['photoalbum'][1] = ["NEW: Red Rocks 2005",
			"Rock climbing at Red Rocks, near Las Vegas",
			"document.location = '/gallery/redrocks05'"];
menus['photoalbum'][2] = ["2004",
			"Events in 2004, including Germany and our Hollywood teddybear calendar photoshoot",
			"document.location = '/gallery/2004events'"];
menus['photoalbum'][3] = ["2003",
			"Events in 2003, including trips to Kuala Lumpur, Cape Town and the Magaliesberg",
			"document.location = '/gallery/2003events'"];
menus['photoalbum'][4] = ["Places",
			'Photos of places I know well. The other categories obviously also have places, but these ones are more &quot;timeless&quot;. Or something.',
			"document.location = '/gallery/2003events'"];
menus['photoalbum'][5] = ["Friends",
			"Photos of my friends -- or, at least, the photos of the friends I have photos of",
			"document.location = '/gallery/friends'"];
menus['photoalbum'][6] = ["Funnies",
			"My small collection of silly signs and funny things",
			"document.location = '/gallery/funnies'"];
			
menus['media'] = new Array();
menus['media']['title'] = "Media";
menus['media'][0] = ["CaledorFM LIVE",
			"Listen to whatever I\\'m listening to at the moment, if I\\'m in my apartment. (WinAmp required)",
			"document.location = '/caledorfm/listen'"];
menus['media'][1] = ["CaledorFM info",
			"Look at the list of songs that have recently played in my apartment",
			"document.location = '/caledorfm'"];
menus['media'][2] = ["MP3s",
			"My music collection. (Password required)",
			"document.location = '/mp3'"];
menus['media'][3] = ["Movies",
			"The apartment\\'s collection of movies and DVDs. (Password required)",
			"document.location = '/movies'"];
menus['media'][4] = ["TV episodes",
			"Episodes for some TV shows, mostly animated (Simpsons, Family Guy...) and a little sci-fi. (Password required)",
			"document.location = '/episodes'"];
menus['media'][5] = ["Programs",
			"Installation files for useful programs I\\'ve collected. (Password required)",
			"document.location = '/install'"];

//Public methods, called by the menus

function showMenu(menuName) {
	hideCurrentMenu();
	document.getElementById(menuName).style.display = "block";
}

function hideCurrentMenu() { /* Hides any menu that is currently visible */
	for ( menu in menus ) {
		document.getElementById(menu).style.display = "none";
	}
}

function showButtonTip(tip,changeVisible) {
	document.getElementById("buttontip").innerHTML = tip;
	if (changeVisible > 0) {
		document.getElementById("buttontip").style.display = "block";
	}
}

function hideButtonTip(changeVisible) {
	if (changeVisible > 0) {
		document.getElementById("buttontip").style.display = "none";
	}
	document.getElementById("buttontip").innerHTML = "";
}

function showTopImageName() {
	showButtonTip('<em>This image:</em> ' + top_pics[curr_top_pic][0] + ' | <strong>Click to change</strong>', 1);
}

function hideTopImageName() {
	hideButtonTip(1);
}

//Technical functions

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function buttonbar_show() { //shows the green background of the button bar over the top image
	document.getElementById("buttonbar_border3").style.display = "block";
	document.getElementById("buttonbar_border2").style.display = "block";
	document.getElementById("buttonbar_border").style.display = "block";
	document.getElementById("buttontip").style.display = "block";
}

function buttonbar_hide() { //hides the button bar background
	document.getElementById("buttonbar_border3").style.display = "none";
	document.getElementById("buttonbar_border2").style.display = "none";
	document.getElementById("buttonbar_border").style.display = "none";
	document.getElementById("buttontip").style.display = "none";
}

//Page construction functions

function choosePageTopImage () {
	old_curr = curr_top_pic;
	do {
		curr_top_pic = (Math.round((Math.random() * (numTops - 1))+1));
	} while (curr_top_pic == old_curr);
	document.getElementById("pagetopimage").src = "/images/tops/top" + curr_top_pic + "_merged.jpg";
}

function constructMenuTop() {
	document.write('<div id="buttontip"></div><div id="buttonbar_border"></div><div id="buttonbar_border2"><div id="buttonbar_border3"></div></div>');
	//write the dark green shadow colour first
	document.write('<div id="buttonbar_shadow">');
	for (i = 0; i < menu_top.length; i++) {
		document.write('<div class="buttonbar_shadow_item">' + menu_top[i][0] + '</div>');
	}
	document.write('</div>');
	document.write('<div id="buttonbar">');
	for (i = 0; i < menu_top.length; i++) {
		document.write('<a class="buttonbarlink" onClick="' + menu_top[i][2] + ';" onMouseOver="buttonbar_show(); showButtonTip(' + "'" + menu_top[i][1] + "'" + ', 0);" onMouseOut="buttonbar_hide(); hideButtonTip(0);">' + menu_top[i][0] + '</a>');
	}
	document.write('</div>');
}

function constructMenus() { //creates invisible menus for all necessary
	out = '';
	for ( menu in menus ) {
		out = out + '<div id="' + menu + '" class="menubox"><div class="menubox2"><div class="menubox3">';
		out = out + '<div class="menuboxcloser"><a onClick="hideCurrentMenu();">X</a></div><div class="menuboxhead">' + menus[menu]['title'] + '</div><div class="menuboxcontent">';
		for ( i = 0; i < menus[menu].length; i++ ) {
			out = out + '<a onMouseOver="showButtonTip(' + "'" + menus[menu][i][1] + "'" + ', 1);" onMouseOut="hideButtonTip(1);" onClick="' + menus[menu][i][2] + ';">' + menus[menu][i][0] + '</a>';
		}
		out = out + '</div></div></div></div>';
	}
	document.write(out);
}

function setbkgnd(obj, colour) { //sets the background CSS to colour, for object obj
	obj.style.background = colour;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//-->

