var basePath = window.location.pathname.toString().split("/");
// Check Location
var currentArea = basePath[1];
var currentSub = null;
if (basePath.length > 3) {	
	var currentSub = basePath[basePath.length-2];
}
var currentPage = basePath[basePath.length-1].toString().split(".htm")[0];

// Testing
//document.write('<style>#error_check {background: black; width:180px; font-size: 10px; color: white;}</style>');
//document.write('<div id="error_check"><p>TEST AREA</p><p>Area: '+currentArea+'</p><p>Sub: '+currentSub+'</p><p>Page: '+currentPage+'</p></div>');


//document.write('<p>Base: '+basePath+'</p>');

// Set Active
$(function(){
	// Special Case
	if (currentArea == "_blog") {
		currentArea ="business_taxation_services";
		currentSub = null;
		currentPage = "blog";
		$("#nav a[href*='/_blog/Blog/']").addClass('current_page');
	}
	
	// Make current page active
	$('#nav a[href='+window.location.pathname+']').addClass('current_page');
		   	

	// Show Submenu if in Root
	if ( $('#sub_'+currentPage).length ) {			  
	   showSub(currentPage);
	}
	
	// Show Submenu if in Subfolder
	if (currentSub != null) {
	   $('#nav a[href=/'+currentArea+'/'+currentSub+'.htm]').addClass('current_page');
	   showSub(currentSub);
	}
});

// Show Submenu
function showSub(currentSent){
	var grabSub = "#sub_"+currentSent;
	$(grabSub).appendTo('#sub_content').css({'display' : 'block'});
}

// Set Area
$(function(){
		   if(currentArea=="bookkeeping_services"){
			   $('#header_location h1').html('Bookkeeping Services');
		   } 
		   if(currentArea=="business_taxation_services"){
			   $('#header_location h1').html('Business &amp; Taxation Services');
		   }
		   if(currentArea=="gfs_accounting_software"){
			   $('#header_location h1').html('mydaEs Accounting Software');
		   }
		   if(currentArea=="production_accounting_payroll"){
			   $('#header_location h1').html('Production Accounting &amp; Payroll');
		   }
		   if(currentArea=="rebates_offset_facilitation"){
			   $('#header_location h1').html('Rebates &amp; Offset Facilitation');
		   }
		   if(currentArea=="wealth_management"){
			   $('#header_location h1').html('Wealth Management');
		   }
});
