//	the following functions are commented out because they are defined in nav-header.js:
//	function isObject(a){ return typeof a == 'object'; }
//	function isArray(a){ return isObject(a) && a.constructor == Array; }

// Define file paths
//	the following paths are commented out because they are defined in nav-header.js:
//	var PB	= "/personal-banking/";
//	var BB	= "/business-banking/";
//	var AS	= "accounts-services/";
//	var MISC= "/misc/";
//	var LOC	= "/locations/";

var AU  = "/about-us/";
var SO	= "/special-offers/";
var BAC = "business-accounts/";
var BBC = "business-borrowing/";
var BC = "borrowing-credit/";
var GN = "good-neighbour/";
var INV = "investments/";

var sBuf = "";
//  This function is used to determin the element index of the Section subheader.
//  This determines whether to display the section subheader
var currentI = 999;
var currentJ = 999;
function findCurrentSubSectionHeaderIndex( currentSection, currentPage, aLabel ){
	for (var i=0; i < aLabel.length; i++) {
		if( aLabel[i][0] == currentSection){
			for (var j=0; j < aLabel[i].length; j++) {
				if( isArray(aLabel[i][j]) ){  // array
					for (var k=0; k < aLabel[i][j].length; k++) {
						if( aLabel[i][j][k] == currentPage ){ currentI=i; currentJ=j; return; }
					}
				} else {  // node
					if( aLabel[i][j] == currentPage ){ currentI=i; currentJ=j; return; }
				}
			}
		}
	}
	return;  // did not find current page
}
var isFirst = true;
var thisSection = "";
var iPadIncrement = 11;  // this is the number of Pixels to pad the labels.  eg. iPadIncrement=11 would set "padding-left:11px"
function SectionNavBar( currentSection, currentPage, oThisLabel, oThisURL ) {
	var iPadding = 0;  // iPadding is the number of Pixels to pad the labels
	var sLabel = "";  var sURL = "";  var sClass = ""; var sImg = "";
	//  The following call sets currentI and currentJ
	findCurrentSubSectionHeaderIndex( currentSection, currentPage, oThisLabel ); 
	for (var i=0; i < oThisLabel.length; i++) {
		var isSectionHeader = false;
		if( !isArray(oThisLabel[i]) ){  // node
			if( i == 0 )isSectionHeader = true;
			else isSectionHeader = false;
			writeNode( currentSection, currentPage, oThisLabel[i], oThisURL[i], isSectionHeader );
		} else {  // array - loop to level 3
			for (var j=0; j < oThisLabel[i].length; j++) {
				if( !isArray(oThisLabel[i][j]) ){  // node
					if( j == 0 )isSectionHeader = true;
					else isSectionHeader = false;
					if( (currentSection == "") || (j == 0) || (i == currentI) ) 
						writeNode( currentSection, currentPage, oThisLabel[i][j], oThisURL[i][j], isSectionHeader );
				} else {
					if( (i == currentI) || (currentSection == "") ){  // array - loop to level 3
						var maxElementsLevel3 = oThisLabel[i][j].length;
						for (var k=0; k < maxElementsLevel3; k++) {
							sLabel = oThisLabel[i][j][k];
							sURL = oThisURL[i][j][k];
							sImg = "";
							if (k == 0) iPadding = 2 * iPadIncrement;  
							else iPadding = 3 * iPadIncrement;  
							if( sLabel == currentPage ) {
								sClass = ' class="cCurrentPage"';
								sImg='<img src="/images/Avroarrow.gif" width="10" height="6" alt="current page indicator" />';
								iPadding = iPadding - 10;  // adjust for width of image
							}
							else sClass = "";
							document.write( '<div' + sClass + ' style="padding-left:' + iPadding + 'px">' + sImg);
							if( (sURL == "") || (sLabel == currentPage) ){
								document.write( sLabel + '</div>');
							} else {
								document.write( '<a href="' + sURL + '">' + sLabel + '</a></div>');
							}
							if( (j != currentJ) || (currentSection == "") ) maxElementsLevel3 = 0;  // force an end loop
						}
					}
				}
			}
		}
	}
}

function writeNode(currentSection, currentPage, sLabel, sURL, isSectionHeader){
	var iPadding = 0;
	var sClass = "";
	var sImg = "";
	if( isSectionHeader ) {  // Section header
		iPadding = iPadIncrement;  
		if( isFirst ) isFirst = false;
		else document.write( '<div class="leftnavHorizontalDivider"></div>' );
		thisSection = sLabel;
		if( sLabel == currentSection ){  // the current page is the current section header
			sClass = "cCurrentSectionHeader";
			if( sLabel == currentPage ){
				sClass += " cCurrentPage";
				sImg='<img src="/images/Avroarrow.gif" width="10" height="6" alt="current page indicator" />';
				iPadding = iPadding - 10;  // adjust for width of image
			}
		} else {
			sClass = "cNonCurrentSectionHeader";
		}
	} else {  // not a section header - must be a sub-page
		if( (currentSection != "") && (thisSection != currentSection) && (currentPage != currentSection) )
			iPadding = 0;
		else {
			iPadding = 2 * iPadIncrement;
			if( thisSection == currentSection ){  // the current page is within the current section
				sClass = "cCurrentSection";
				if( sLabel == currentPage ){
					sClass += " cCurrentPage";
					sImg='<img src="/images/Avroarrow.gif" width="10" height="6" alt="current page indicator" />';
					iPadding = iPadding - 10;  // adjust for width of image
					}
			} else {  // the current page is outside the current section
				sClass = "cNonCurrentSection";
			}
		}
	}
	if( iPadding != 0){
		document.write( '<div class="' + sClass + '" style="padding-left:' + iPadding + 'px">' + sImg );
		if( (sURL == "") || (sLabel == currentPage) ){
			document.write( sLabel + '</div>');
		} else {
			document.write( '<a href="' + sURL + '">' + sLabel + '</a></div>');
		}
	}
}