// 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 != 'www.tae.com.au' && sFullFolderName != 'www.taeaviation.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  = oLink.className + ' selected';			
		}
	}
	

	// 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');
		iApprovalsPos = sFullFolderName.indexOf('approvals');
		iCareersPos = sFullFolderName.indexOf('careers');
		iCompaniesPos = sFullFolderName.indexOf('companies');
		iContactPos = sFullFolderName.indexOf('contact');		
		iLegalsPos = sFullFolderName.indexOf('legals');		
		iNewsPos = sFullFolderName.indexOf('news');		
		iServicesPos = sFullFolderName.indexOf('services');		

		// 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 (iApprovalsPos < 0) {
			oSubNav = document.getElementById('subNavApprovals');
			hideIt(oSubNav);
		}
		
		// if we can't find the section then turn it off
		if (iCareersPos < 0) {
			oSubNav = document.getElementById('subNavCareers');
			hideIt(oSubNav);
		}

		// if we can't find the section then turn it off
		if (iCompaniesPos < 0) {
			oSubNav = document.getElementById('subNavCompanies');
			hideIt(oSubNav);
		}

		// if we can't find the section then turn it off
		if (iContactPos < 0) {
			oSubNav = document.getElementById('subNavContact');
			hideIt(oSubNav);
		}

		// if we can't find the section then turn it off
		if (iLegalsPos < 0) {
			oSubNav = document.getElementById('subNavLegals');
			hideIt(oSubNav);
		}

		// if we can't find the section then turn it off
		if (iNewsPos < 0) {
			oSubNav = document.getElementById('subNavNews');
			hideIt(oSubNav);
		}

		// if we can't find the section then turn it off
		if (iServicesPos < 0) {
			oSubNav = document.getElementById('subNavServices');
			hideIt(oSubNav);
		}

//	}
} else {
	oSubNav = document.getElementById('subNavAbout');
	hideIt(oSubNav);
	
	oSubNav = document.getElementById('subNavApprovals');
	hideIt(oSubNav);
	
	oSubNav = document.getElementById('subNavCareers');
	
	oSubNav = document.getElementById('subNavCompanies');
	hideIt(oSubNav);
	
	oSubNav = document.getElementById('subNavContact');
	hideIt(oSubNav);
	
	oSubNav = document.getElementById('subNavLegals');
	hideIt(oSubNav);
	
	oSubNav = document.getElementById('subNavNews');
	hideIt(oSubNav);
	
	oSubNav = document.getElementById('subNavServices');
	hideIt(oSubNav);
}

