/*
 * Mocean Records' website JavaScipt - for Dividing Line Creations.
 *
 * Author: Ryan Allen (visit badfont.com!)
 * Date:   27th August '04
 *
 * Comments: 
 * I like JavaScript'ing DOM! It's fun. It's faster than downloading images
 * for navigations(and much more classy, I think).
 * 
 */

/* initalises the top navigation for mouseovers, selected, onpress.. etc */
function initaliseNavigation()
{
	// get all the table cells in the nav element
	var cells = document.getElementById('nav').getElementsByTagName('td');
	
	// loop through each cell...
	for (var i = 0; i < cells.length; i++)
	{
		// set the table alignment; because it's so clunky in html :D
		// (saves a few bytes of bandwidth)
		cells[i].align  = 'center';
		cells[i].valign = 'middle';

		// funky eh? (the zero index thing, i like it)
		var link = cells[i].getElementsByTagName('a')[0];
		
		// funky here too! (discarded new object to cast location attribute
		// to a string so we can use String's indexOf() method)...
		// it's checking to see if the link's href is somewhere in the url
		if (new String(window.location).indexOf(link.href) != -1)
		{
			// the links href IS somewhere in the URL!
			// this is the selected nav cell..., so make it look selected
			// (and remove the link but preserve the text!)
			cells[i].className    = 'over';
			cells[i].style.cursor = 'default';  // override cursor in .over css
			cells[i].innerHTML    = link.innerHTML;
		}
		else
		{
			// it's just a plain old boring nav cell, so just give it
			// some event handlers
			cells[i].onmouseover = function()
			{
				this.className = 'over'; // class turns on
			}
			
			cells[i].onmouseout = function()
			{
				this.className = ''; // class turns off
			}
			
			cells[i].onclick = function ()
			{
				// this rocks, i love this; usable and seach engine friendly!
				// (means i can put a real link (<a> tag) in the table cell, 
				//  and still use it's href when they don't physically click 
				//  on it).
				var link        = this.getElementsByTagName('a')[0];
				window.location = link.href;		
			}	
		}
	}
}