// work out the file name
sLocation = window.location.href;
aLocationParts = sLocation.split("/");
sFileName = aLocationParts[aLocationParts.length-1]; // Last element
sFullFolderName = aLocationParts[aLocationParts.length-2]; // Second Last element

function hideIt(oElement) {
	if (oElement != null) {
		oElement.style.display = 'none';	
	}
}

if (sFullFolderName != '' && sFullFolderName != 'NEW' && sFullFolderName != 'jaws' && sFullFolderName != '~jawsbuckets123' && sFullFolderName != 'www.jaws.com.au') {

	// get to the main navigation div
	oMainNav = document.getElementById('cellNavigation');
	
	// loop through all the links in the main navigation div
	aNavigationObjs = oMainNav.getElementsByTagName('a');
	
	
	for(i=0;i<aNavigationObjs.length;i++){
		oLink = aNavigationObjs[i];
		// work out the href
		sLinkURL = oLink.toString();
		// check if it matches our current file name
		iInstancePos = sLinkURL.indexOf(sFullFolderName);
		
		if (iInstancePos > 0) {
			// change its class if it is.
			oLink.className  = 'navSelected';			
		}
	}
	

	// get to the sub navigation div
	oSubNav = document.getElementById('cellSubNavigation');
	
	if (oSubNav) {
		
		// loop through all the links in the sub navigation div
		aSubNavigationObjs = oSubNav.getElementsByTagName('a');
		
		for(i=0;i<aSubNavigationObjs.length;i++){
			oLink = aSubNavigationObjs[i];
			// work out the href
			sLinkURL = oLink.toString();
			// check if it matches our current file name
			sCheckLink = sFullFolderName + '/' + sFileName;
			iInstancePos = sLinkURL.indexOf(sCheckLink);
			
			if (iInstancePos > 0) {
				// change its class if it is.
				oLink.className  = 'navSelected';			
			}
		}
		
		
		// work out if it is any of the sections with sub nav
		iAboutPos = sFullFolderName.indexOf('about_us');
		iMiningPos = sFullFolderName.indexOf('mining');
		iConstructionPos = sFullFolderName.indexOf('construction');
		iSparePartsPos = sFullFolderName.indexOf('spare_parts_and_support');
		iQualityPos = sFullFolderName.indexOf('quality');
		iContactPos = sFullFolderName.indexOf('contact');
		
		// reverse thinking here for best case default
		// if we can't find the section then turn it off
		if (iAboutPos < 0) {
			oSubNav = document.getElementById('subNavAbout');
			hideIt(oSubNav);
		}
		
		// if we can't find the section then turn it off
		if (iMiningPos < 0) {
			oSubNav = document.getElementById('subNavMining');
			hideIt(oSubNav);
		}
		
		// if we can't find the section then turn it off
		if (iConstructionPos < 0) {
			oSubNav = document.getElementById('subNavConstruction');
			hideIt(oSubNav);
		}
		
		// if we can't find the section then turn it off
		if (iSparePartsPos < 0) {
			oSubNav = document.getElementById('subNavSpareParts');
			hideIt(oSubNav);
		}
		
		// if we can't find the section then turn it off
		if (iQualityPos < 0) {
			oSubNav = document.getElementById('subNavQuality');
			hideIt(oSubNav);
		}
		
		// if we can't find the section then turn it off
		if (iContactPos < 0) {
			oSubNav = document.getElementById('subNavContact');
			hideIt(oSubNav);
		}
	}
}

