/*	Usage: <a href="javascript:book('http://www.google.com','Google'); return false;">Add Google to your bookmarks</a>  */
function book(bookmark_url,bookmark_title) {
	if (window.sidebar) { 
		window.sidebar.addPanel(bookmark_title, bookmark_url, "");
	} else if(window.opera && window.print) { 
		var elem = document.createElement('a');
		elem.setAttribute('href',bookmark_url);
		elem.setAttribute('title',bookmark_title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all) {
		window.external.AddFavorite(bookmark_url, bookmark_title);
	}
}





/*
 * Nice function from Dustin Diaz (www.dustindiaz.com)
Usage: var el = getElementsByClass('foo',document,'*');
 Required: class name as a string
 Optional: Supply a node. Defaults to document. This can be obtained by getElementById. Useful if you know your parent and you don’t want to loop through the entire D.O.M.
 Optional: Limit your results by adding a tagName. Very useful when you’re toggling checkboxes and etcetera. You could just supply “input“.   +IE5, you can use the “*” asterisk as a catch-all (meaning ‘any element).

*/

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


/*
This code is based on a code example from the article "Javascript navigation - cleaner, not meaner" by Christian Heilmann
URL: http://www.evolt.org/article/Javascript_navigation_cleaner_not_meaner/17/60273/index.html
*/

function initShowHide() {
	if (document.getElementById && document.getElementsByTagName && document.createTextNode) {
		hide();
		//var toggle = document.getElementById('toggle');
		//var as = toggle.getElementsByTagName('a');
		var as = getElementsByClass('toglink',document,'a');
		for (var i = 0; i < as.length; i++) {
			as[i].onclick = function() {
				show(this);
				return false;
			}
		}			
	}
}

function show(s) {
	hide();
	var id = s.href.match(/#(\w.+)/)[1];
	document.getElementById(id).style.display = 'block';
}

function hide() {
	var toggleable = getElementsByClass('toggleable',document,'div');
	for (var i = 0; i < toggleable.length; i++) {
		toggleable[i].style.display = 'none';
	}
}