function prepNav() {
	
	if(!document.getElementById) return false;
	if(!document.getElementById("top-nav")) return false;
	if(!document.getElementsByTagName) return false;

	var topNav = document.getElementById("top-nav");
	var topNavLi = topNav.getElementsByTagName("LI");

	for ( var i = 0; i < topNavLi.length; i++)
	{
		topNavLi[i].onmouseover = topNavLi[i].onfocus = function() {
			if(!this.className.match("hover"))
			{
				if(this.className)
				{
					this.className += " hover";
				}
				else {
					this.className = "hover";
				}
			}
			return 0;
		}
		
		topNavLi[i].onmouseout = topNavLi[i].onblur = function() {
			if(this.className.match("hover"))
			{
				this.className = this.className.replace(/ ?hover ?/g, "");
			}
			return 0;
		}
	}
	return 0;
}

addLoadEvent(prepNav);

/* = ACCORDION BLOCK
-------------------------------------------------*/

function prepCollapsableContent(collapsableBlockId) {
	if(!document.getElementById || !document.getElementById(collapsableBlockId)) return false;
	
	var block = document.getElementById(collapsableBlockId);

	var blocks = block.getElementsByTagName("DIV");
	
	var collapsable_blocks = new Array;

	for (var i = 0; i < blocks.length; i++) {

		if(!blocks[i].className.match("collapsable")) {
			continue;
		}
		else {
			collapsable_blocks.push(blocks[i]);
		}
	
		var toggle_links = blocks[i].getElementsByTagName("A");
		for(var j = 0; j < toggle_links.length; j++) {
		
			if(!toggle_links[j].className.match("toggle-link")) continue;
			
			toggle_links[j].block_to_collapse = blocks[i];
			
			toggle_links[j].onclick = function() {

				if(this.block_to_collapse.className.match("open")) return false;
	
				collapse_all(collapsable_blocks);
	
				if(this.block_to_collapse.className) {
					this.block_to_collapse.className += " open";
				}
				else {
					this.block_to_collapse.className = "open"
				}
				
				return false;
			}
		}
	
	}
	
	return 0;
}

/* = COLLAPSE ALL ACCORDION CONTENT BLOCKS
-------------------------------------------------*/

function collapse_all(blocks) {
	if(!blocks) return false;
	
	var collapsable_blocks = blocks;
	
	for(var i = 0; i < collapsable_blocks.length; i++) {
		if(collapsable_blocks[i].className.match("collapsable")) {
			if(collapsable_blocks[i].className.match("open")) {
				collapsable_blocks[i].className = collapsable_blocks[i].className.replace(/ ?open ?/g, "");
			}
		}
	}
	
	return 0;
}

function prepProfilesNav() {
	if(!document.getElementById || !document.getElementById("profiles-nav")) return false;
	
	var nav = document.getElementById("profiles-nav");
	var nav_items = nav.getElementsByTagName("LI");
	
	for( var i = 0; i < nav_items.length; i++) {
		nav_items[i].onclick = function() {
			if(this.className.match("sel")) return false;
			if(hide_all(nav_items)) return false;
			if(this.className) {
				this.className += " sel";
			}
			else {
				this.className = "sel";
			}
			return false;
		}
	}
	return 0;
}

function hide_all(collection_to_hide) {
	if(!collection_to_hide) return 1;
	
	for(var i = 0; i < collection_to_hide.length; i++) {
		if(collection_to_hide[i].className.match("sel")) {
			collection_to_hide[i].className = collection_to_hide[i].className.replace(/ ?sel ?/g, "");
		}
	}
	return 0;
}

/* = ON LOAD
---------------------------------------------------------------
	add the on load events
---------------------------------------------------------------*/
function addLoadEvent(func) {
	var oldOnLoad = window.onload
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldOnLoad();
			func();
		}
	}
}