

// Main BreadCrumb function ==============================================================================


function breadCrumbs($home_directory, $divider,$cStyle, $tStyle, $dStyle, $new_line) {
    // gets current URL and converts to text string
	// e.g. http://www.itrainweb.com/tests/javascript/test_elements.html
	$location = window.location.toString();
	//gets the substring of the URL after the home directory (http://itrainweb.com/)and splits it at the / 
	//e.g. tests,javascript,test_elements.html 
	
    $subString = $location.substr($location.indexOf($home_directory) + $home_directory.length + 1).split("/");
	// prints the path to the home directory + the $divider e.g.'<a href="../../index">Home</a><span>>></span>'
	// uses the getLoc() function defined below with the sunString.length to determine how many levels up from the current file the home directory is.

// prints out the path to the home directory, the home directory name ($home_file) and the $divider (and style classes if defined). Remove +$home_file to return to default directory listing
document.write("<a href=\"" + getLoc($subString.length - 1)+ "\" class=\"" + $cStyle + "\">iCampus Home</a>  " + "<span class=\"" + $dStyle + "\">" + $divider + "</span> ");

// prints remainder of path converting file names first letters to uppercase using getCaps()=====

    $a = ($location.indexOf() == -1) ? 1 : 2;
	
//loops thro no of sub-directories, adds uppercase letter from makeCaps() and prints as link
//Remove +$home_file to return to default directory listing
    for (i = 0; i < $subString.length - $a; i++) {
	
        $subString[i] = makeCaps(unescape($subString[i]));
		
        document.write("<a href=\"" + getLoc($subString.length - i - 2) + "\" class=\"" + $cStyle + "\">" + $subString[i] + "</a>  " + "<span class=\"" + $dStyle + "\">" + $divider + "</span> ");
    }
//breaks current file title on to second line by inserting a <BR> if $new_line set to 1====================
    if ($new_line == 1) {
        document.write("<br>");
    }
//========================================================================================================
	//writes out CSS + document title of current page
    document.write("<span class=\"" + $tStyle + "\">" + document.title + "</span>");
}//EoFn breadCrumbs()

//picks up directory names and changes first letter to uppercase ====================================
function makeCaps($a) { 
//$a takes on the value of $subString[i] which is a directory title from the breadCrumbs() function above
	$sub_dir_name = $a.split(" ");
	
	//loops thro directory names and changes 'name' to 'Name'
    for (l = 0; l <  $sub_dir_name.length; l++) {
         $sub_dir_name[l] =  $sub_dir_name[l].toUpperCase().slice(0, 1) +  $sub_dir_name[l].slice(1);
		
    }
    return  $sub_dir_name.join(" ");
}//EoFn makeCaps()
//===========================================================================================================
// determins number of levels up required to reach root directory and prints the appropriate number of '../'
	function getLoc($num) {
    var $path = "";
    if ($num > 0) {
        for ($count = 0; $count < $num; $count++) {
			// for each level specified by $num add a '../'
            $path = $path + "../";
			        }
    }
	
    return $path; //returns the $path value to the calling code i.e.line 32
	
}//EoFn getLoc()

