// JavaScript Document

/**
*	nav - method of redirecting to pages ;)
*
*	targ can be one of three variations:
*	1. nav('pagename') - will attempt to load index of
*	2. nav('?pagename') - load subsection of current section
*	3. nav('pagename?pagename') - load section, and subsection
*/
function nav( targ )
{
	// if "?" is present, we're targeting a 'sub section'
	// or a main section
	// of the desired section, which will be the name
	// of the (sub)section we wish to load...
	if( targ.indexOf( "?" ) > -1 )
	{
		var dest = targ.split("?");


		// if nothing prepended before "?", targeting
		// subsection of current page
		if( dest[0].length < 1 )
		{
			var tmp = location.toString().split("?");
			location.href = tmp[0] + "?" + dest[1];
		}
		// if nothing appened after "?", load
		// index page...		
		else if( dest.length < 2 || dest[1].length < 1 )
		{
			location.href = dest[0] + ".php";
		}		
		// else load sub destination
		else
		{
			location.href = dest[0] + ".php?" + dest[1];
		}		
	}
	// else we're loading the main page
	else
	{
		//var dest = location.toString();
		//dest = dest.split("?");
		//alert("loading main section page");
		location.href = targ + ".php";//dest[ 0 ] + "?" + targ;		
	}
}

// apply currently selected link style
function hilightCurrentSection()
{
	sect = location.search;
	sect = sect.substring( 1, sect.length );
	try
	{		
		document.getElementById( sect ).className = "interiorLeftColumnSelected";
	}
	catch( e )
	{
		//an error may occur if the section doesn't exist; or the id is incorrect
	}
}

// mailto function from footer (hiding email from krawlers)
function mail()
{
	var ml = "lars" + "@c2e" + ".ca";
	location.href = "mailto:"+ml;
}

// try to preload the nav images (mout/mover), so things
// don't look nasty on load..
navImgs = 
[
	"mout_about.png",
	"mout_approach.png",
	"mout_clients.png",
	"mout_services.png",
	"mout_track_record.png",
	"mover_about.png",
	"mover_approach.png",
	"mover_clients.png",
	"mover_services.png",
	"mover_track_record.png",
	//interior buttons
	"mout_clients_interior.png",
	"mout_track_record_interior.png",
	"mover_clients_interior.png",
	"mover_track_record_interior.png"
]

for( var i in navImgs )
{
	img = new Image();
	img.src = "media/" + navImgs[i];
}

onload=hilightCurrentSection;