
    // default bgcolor for the nav
    var default_bgcolor = "#F03C3C";
    
    // edit the array of bgcolors, element 0 should be left blank, or set to the default bgcolor of all documents
    var bgcolorArray = new Array( '', default_bgcolor, '#4F4532', '#79694D', '#ffffff');
    
    // edit the default indent width
    var indentDefault = 0;
    
    // edit the incremental amount for each level's indentation
    var indentIncrement = 10;
    
    // a development server - for resolving hard-coded external links,
    // do not use any producti69on server's hostname here
    var host = location.hostname;    
    var developmentServer = 'redesign.my.sivananda.org'; // default
    if ( host == "my.sivananda.org" || host == "dev.my.sivananda.org"  ) {
        developmentServer = host;
    }
    
	var base_section_home;
	
	
function init() {
	base_section_home = new NavItem ( "base_section_home", "", "#" );  	
}

/**
 * EDITABLE HTML DISPLAY FUNCTIONS
 *
 * Edit only the HTML for display-formatting purposes
 *
 */ 
var displayNavString = ''; //'<table width="160" cellpadding="0" cellspacing="0" border="0">';


// wrapper for displayThisArea() function
function displayNavigation ( area, header ) {
    
    // yup, we do strings too...
    if ( typeof(area) == "string" ) {
        area = eval(area);
    }
    
    area.is_top_level = (area.parent.id == "base_section_home");
    
    
    displayThisArea( area );
    
    //displayNavString = displayNavHeader( header ) + displayNavString;
    return displayNavString;
}





function getTopLevelNav ( area, state ) {

    // code for running on local server
    if (location.hostname == developmentServer) {
        fixurl( area );
    }
    
    var indicator_image = 'blank.gif';
    if ( state == "opened" ) {
        indicator_image = 'arrow_white.gif';
    }
    
    var css = "nav-text";
    if (area.is_top_level) {
    	css = "nav-text-selected";	
    }
    
    var display = (
    	'<p><a href="' + area.url + '"><span class="' + css + '">' + area.text + '</span></a></p>'
    );
    
    return display;
}




function getSubLevelNav ( area, state ) {

    // code for running on a local server
    if (location.hostname == developmentServer) {
        fixurl( area );
    }
    
    // need a 2nd bgcolor when we're down to the white level
    var bgcolor = bgcolorArray[colourCounter];
    var bgcolor2 = bgcolorArray[colourCounter + 1];
        
    // default bullet for subnav's
    //var bullet = '<img src="/images/bullet_green.gif" width="2" height="2" vspace="6" alt="" border="0">';
    var bullet = '&middot;&nbsp;';
    
    // default td cell for subnav's
    //var navText = '\'<td class="footer"><a href="\' + area.url + \'" target="_parent">\' + area.text + \'</a></td>\'';
    var navText = '\'<a href="\' + area.url + \'"><span class="subnav-text" style="color:\' + bgcolor + \'">\' + area.text + \'</span></a>\'';
    
    // if this is the selected subnav, show the indicators
    if ( area.id == SELECTED_SUBNAV ) {
        //bullet = '<img src="/images/arrow_red.gif" width="5" height="7" vspace="4" alt="" border="0">';
        bullet = '&#149;&nbsp;';
        //navText = '\'<td><a href="\' + area.url + \'" target="_parent"><span class="left-nav-selected">\' + area.text + \'</span></a></td>\'';
        //navText = '\'<a href="\' + area.url + \'"><span class="subnav-selected-text" style="color:\' + bgcolor2 + \'">\' + area.text + \'</span></a>\'';
        navText = '\'<a href="\' + area.url + \'"><span class="subnav-selected-text" style="color:\' + default_bgcolor + \'">\' + area.text + \'</span></a>\'';
    
    }
    
    var display = (
    	'<p style="margin:0px 0px 0px ' + indent + 'px">' + bullet + eval(navText) + '</p>'
    );

    
    return display;
}

 

 

 
 
 
 
/**
 * CORE FUNCTIONS - DO NOT EDIT THESE FUNCTIONS OR VARIABLES
 */ 
 
// Global variables - since the function displayThisArea() makes recursive calls...

// the display string
var display = '';
var colourCounter = 0;
var indent = indentDefault;

// due to recursive calls, these must also be global
var childIDArray = new Array();
var levelsCounter = 0;

// constant: the subnav item that was clicked - this is always going to be childIDArray[1]
var SELECTED_SUBNAV = '';

var breadcrumbs = '<span class="breadcrumb"><a href="/index.html" target="_parent">Home</a></span>';

/**
 * This function is intimately linked to the structure of the 'NavItem()' function
 *  - edit with extreme care...
 */  
function displayThisArea ( area, childID, recurseflag ) {

    // we need to track the various levels, note that the index [0] will always be undefined
    childIDArray[levelsCounter] = childID;

    // if childIDArray has been set, then set the SELECTED_SUBNAV constant
    if ( childIDArray[1] ) {
        SELECTED_SUBNAV = childIDArray[1];
    }
    
    
    // keep climbing up until we're at the topmost parent (i.e. base_section_home)
    if ( area.parent != '' && recurseflag != false ) {
        
            // this area has a parent, so add this area as a new childID to the array
            levelsCounter++;
            childIDArray[levelsCounter] = area.id;   
            displayThisArea ( area.parent, childIDArray[levelsCounter] ); 
    
    // else we are at the topmost parent level (i.e. base_section_home)
    } else {
        
            // nothing to display for Sivananda Home
            if ( area.id != "base_section_home" ) {
            
                // Level 1 selected nav - opened
                if (area.parent.id == "base_section_home" ) {            
                    display += getTopLevelNav ( area, 'opened' );  
                    breadcrumbs +=   formatBreadCrumbs(area);                
                // Sublevel nav - opened
                } else {
                    display += getSubLevelNav ( area, 'opened' );
                    breadcrumbs +=   formatBreadCrumbs(area);  
                }
            }
            
            
            // we're looping through the children, so increment the colour-counter to get the subnav colours
            colourCounter++;
            
            // increase the indent
            indent += indentIncrement;
            
            for ( subnav in area.child ) {
                
                // if this child is on the path to the target, then
                // we have to open it up and display its subnav items
                if ( area.child[subnav].id == childID ) {
                 
                    levelsCounter--;
                    displayThisArea ( area.child[subnav], childIDArray[levelsCounter], false );                  
                
                // else just display this parent's children    
                } else {
                
                    // track the number of children remaining - for display purposes
                    area.remainingChildren --;
                    
                    // display top-level children of base_section_home
                    if (area.id == "base_section_home") {                    
                        display += getTopLevelNav ( area.child[subnav] );
                    
                    // else display sub-level children
                    } else {
                        display += getSubLevelNav ( area.child[subnav] );
                    }                
                }                
            }
            
            // back to previous level colour
            colourCounter--;
            
            // decrease the indent
            indent -= indentIncrement;
    }
    
    displayNavString += display;
    display = '';
}




  
/**
 * This function is intimately linked to the structure of the 'displayThisArea()' function
 *  - edit with extreme care...
 */ 

function NavItem ( navID, navText, navURL ) {

    this.id = navID;
    this.text = navText;
    this.url = navURL;
    this.child = new Object();
    this.addChild = addChildNode;
    this.remainingChildren = 0;
    this.hasNextChild = hasNextChild;
    this.parent = '';
    
}

// a method of NavItem
function addChildNode ( childObj ) {       
    this.child[childObj.id] = childObj;
    this.child[childObj.id].parent = this; 
    this.remainingChildren ++;
}


function hasNextChild() {
    return this.remainingChildren != 0;
}

 
/**
 * This function is for detecting the referring zone when redundant url's are
 * used in more than one section - it permits the nav to display the proper
 * section that the common target page was referred from
 */
function detectNavZone () {

    var myQueryString = location.search;
    var name = '';
    var value = '';
    
    
    if ( myQueryString != "" && myQueryString != "?" ) {
        
        myQueryString = myQueryString.substring(1); // remove the ? mark
        var queryArray = myQueryString.split("&");
        
        for ( pairs in queryArray ) {
            var param = queryArray[pairs].split("=");
            
            name = param[0];
            
            if ( name == "navzone" ) {
                value = param[1];
                value += "_";
                break;
            }
        }        
    }
    
    return value;
}    



 
/**
 * fixurl()
 * alters the hostname and port for selected URL's so that any
 * hard-coded hyperlinks to external servers will run on a 
 * local development server
 */ 
function fixurl ( area ) {

    var area_url = area.url;
    var thisDevServer = location.hostname + ":" + location.port;
    var externalServersArray = new Array (
        "www.sivananda.org"
    );
    
    for ( server in externalServersArray ) {
        var host = new RegExp( externalServersArray[ server ], "i" );
        area_url = area_url.replace ( host, thisDevServer );
    }
    
    area.url = area_url;
}
 
 
 
 
function formatBreadCrumbs ( area ) {

    var href = '';
    var text = area.text;
    
    if ( text.indexOf("img") != -1 ) {
        var arr = new Array();
        arr = text.match(/alt=\".*\"/);
        arr[0] = arr[0].substring(5, arr[0].length-1);
        text = arr[0];
    }
        
    if ( levelsCounter > 0 ) {
         href += '<span class="breadcrumb"> &gt; <a href="' + area.url + '" target="_parent">' + text + '</a></span>';
    } else {
        href += '<span class="breadcrumb"> &gt; </span><span class="breadcrumb-highlight">' + text + '</span>';
    }
    
    return href;
} 
 
 
function getBreadCrumbs () {

    return breadcrumbs;
}
 


function displayNavHeader( header ) {
	
	// split off the first letter of each word
	var word_array = header.split(" ");
	var new_header = '';
	
	for (i=0; i<word_array.length; i++) {
		var word = word_array[i];
		var first = word.substring(0,1);
		var remainder = word.substring(1);
		var space = '';
		
		if ( i > 0 ) { space = ' '; }
		new_header += space + '<span class="large-cap">' + first + '</span>' + remainder;
	}
	
	return (
			'<div id="leftNavHeader">'
		+	new_header
		+	'</div>'
	);
}




init();


