// this function allows us to set variables by passing them in as values in the query string
// by default it looks for the query string after the occurrence of '.html?' in URL of the current document
// but these values can be passed in as parameters
function parseQuery(loc,key) {
	if (loc == null) loc = document.location.href;
	if (key == null) key = '?';
	if (loc.indexOf(key) > -1) {
		query = loc.substring(loc.indexOf(key)+key.length,loc.length);
		args = query.split('\&');
		for (i=0; i<args.length; i++) {
			chunk = args[i];
			eval(chunk.split('=')[0] + " = '" + chunk.split('=')[1] + "'");
		}
	}
}


/*------------------------------------------------------------
*  Function:  openPopupWindow
*  
*  Description:
*  opens a popup window of a passed width and height
*  and loads the passed URL in it
*  
*  Parameters:
*  url			string		page to load
*  w			integer		width of popup window
*  h			integer		height of popup window
*  features		string		window features - see below for defaults
*  
*  Return:
*  none
*------------------------------------------------------------*/
function openPopupWindow(url,w,h,features) {
	if (w == null) w = 400;
	if (h == null) h = 400;
	if (features == null) features = ",menubar=0,status=0,location=0,directories=0,resizable=1,scrollbars=1";
	
	if (document.all) {
		w += 38;
		h += 30;
	}
	if (navigator.appVersion.match(/Safari/)) {
		h += 1;
	}
	if (navigator.userAgent.match(/Firefox/)) {
		w += 20;
		h += 20;
	}
	
	if (url) {
		var popupWindow = window.open(url,'popupWindow','width='+w+',height='+h+features);
		popupWindow.focus();
	}
}


function newImage(arg) {
	rslt = new Image();
	rslt.src = arg;
	return rslt;
}

function resizeWindow(w,h,force) {
	if (window.innerWidth && window.innerHeight) {
		var wdiff = window.outerWidth - window.innerWidth;
		var hdiff = window.outerHeight - window.innerHeight;
		
		var doit = false;
		if (window.innerWidth < w) {
			endw = w + wdiff;
			doit = true;
		} else {
			endw = window.outerWidth;
		}
		if (window.innerHeight < h) {
			endh = h + hdiff;
			doit = true;
		} else {
			endh = window.outerHeight;
		}
		if (force) {
			endw = w + wdiff;
			endh = h + hdiff;
		}
		
		if (doit || force) self.resizeTo(endw,endh);
	}
}

function dw(msg) {
	document.write(msg);
}

function randomNum(start,end) {
	var range = end - start + 1;
	var n = Math.floor(Math.random() * (range)) + start;
	return(n);
}

function imgOn(which) {
	if (which && onImgs) {
		if (onImgs[which]) {
			document.images[which].src = onImgs[which].src;
		}
	}
}

function imgOver(which) {
	if (which && overImgs) {
		if (overImgs[which] && which != navcurrent) {
			document.images[which].src = overImgs[which].src;
		}
	}
}

function imgOff(which) {
	if (which && offImgs) {
		if (offImgs[which] && which != navcurrent) {
			document.images[which].src = offImgs[which].src;
		}
	}
}

function setCurrent(which) {
	if (which) {
		var link = document.getElementById(which);
		if (link) {
			link.className = "navcurrent";
			navcurrent = which;
		}
	}
}

function gotoLink(url) {
	document.location = url;
}


function show(which) {
	document.getElementById(which).style.visibility = "visible";
}

function hide(which) {
	document.getElementById(which).style.visibility = "hidden";
}

function showdisplay(which) {
	document.getElementById(which).style.display = "inline";
}

function hidedisplay(which) {
	document.getElementById(which).style.display = "none";
}

function platformCSS() {
	var isMac = (navigator.userAgent.indexOf("Mac") > -1);
	var macCSS = "/lib/styles-mac.css";
	var pcCSS = "/lib/styles-pc.css";

	document.write('<link rel="stylesheet" type="text/css" href="'+ (isMac ? macCSS : pcCSS) +'">')
}

//platformCSS();
var offImgs = new Array();
var overImgs = new Array();
var onImgs = new Array();

var navcurrent = null;

offImgs['aboutthekids'] = newImage('/lib/nav/images/aboutthekids.gif');
overImgs['aboutthekids'] = newImage('/lib/nav/images/aboutthekids-over.gif');
onImgs['aboutthekids'] = newImage('/lib/nav/images/aboutthekids-down.gif');
offImgs['aboutus'] = newImage('/lib/nav/images/aboutus.gif');
overImgs['aboutus'] = newImage('/lib/nav/images/aboutus-over.gif');
onImgs['aboutus'] = newImage('/lib/nav/images/aboutus-down.gif');
offImgs['contact'] = newImage('/lib/nav/images/contact.gif');
overImgs['contact'] = newImage('/lib/nav/images/contact-over.gif');
onImgs['contact'] = newImage('/lib/nav/images/contact-down.gif');
offImgs['contribute'] = newImage('/lib/nav/images/contribute.gif');
overImgs['contribute'] = newImage('/lib/nav/images/contribute-over.gif');
onImgs['contribute'] = newImage('/lib/nav/images/contribute-down.gif');
offImgs['emailthekids'] = newImage('/lib/nav/images/emailthekids.gif');
overImgs['emailthekids'] = newImage('/lib/nav/images/emailthekids-over.gif');
onImgs['emailthekids'] = newImage('/lib/nav/images/emailthekids-down.gif');
offImgs['faq'] = newImage('/lib/nav/images/faq.gif');
overImgs['faq'] = newImage('/lib/nav/images/faq-over.gif');
onImgs['faq'] = newImage('/lib/nav/images/faq-down.gif');
offImgs['history'] = newImage('/lib/nav/images/history.gif');
overImgs['history'] = newImage('/lib/nav/images/history-over.gif');
onImgs['history'] = newImage('/lib/nav/images/history-down.gif');
offImgs['joinouremaillist'] = newImage('/lib/nav/images/joinouremaillist.gif');
overImgs['joinouremaillist'] = newImage('/lib/nav/images/joinouremaillist-over.gif');
onImgs['joinouremaillist'] = newImage('/lib/nav/images/joinouremaillist-down.gif');
offImgs['kidsbook'] = newImage('/lib/nav/images/kidsbook.gif');
overImgs['kidsbook'] = newImage('/lib/nav/images/kidsbook-over.gif');
onImgs['kidsbook'] = newImage('/lib/nav/images/kidsbook-down.gif');
offImgs['kidsgallery'] = newImage('/lib/nav/images/kidsgallery.gif');
overImgs['kidsgallery'] = newImage('/lib/nav/images/kidsgallery-over.gif');
onImgs['kidsgallery'] = newImage('/lib/nav/images/kidsgallery-down.gif');
offImgs['events'] = newImage('/lib/nav/images/events.gif');
overImgs['events'] = newImage('/lib/nav/images/events-over.gif');
onImgs['events'] = newImage('/lib/nav/images/events-over.gif');
offImgs['mission'] = newImage('/lib/nav/images/mission.gif');
overImgs['mission'] = newImage('/lib/nav/images/mission-over.gif');
onImgs['mission'] = newImage('/lib/nav/images/mission-down.gif');
offImgs['news'] = newImage('/lib/nav/images/news.gif');
overImgs['news'] = newImage('/lib/nav/images/news-over.gif');
onImgs['news'] = newImage('/lib/nav/images/news-down.gif');
offImgs['workshops'] = newImage('/lib/nav/images/workshops.gif');
overImgs['workshops'] = newImage('/lib/nav/images/workshops-over.gif');
onImgs['workshops'] = newImage('/lib/nav/images/workshops-down.gif');

