//////////////////////////////////////////////////////////////////////////////
//                         Nifty Breadcrumbs Script                         //
//////////////////////////////////////////////////////////////////////////////
// 
// This is a neat little script that takes your site's file/folder structure
// and converts it into breadcrumbs. As an added bonus, it forces you to
// create a structure that is optimal for search engines to index and rank!
//
// CONTRIBUTORS:
//
// Original Creator:
//     Paul Hirsch
//     www.paulhirsch.com
//
// Tested by:
//     International Web Developers Network (IWDN)
//     www.iwdn.net - home page
//     www.iwdn.net/index.php - forums/community where testing took place
//
// Other Contributors:
//     [INSERT YOUR NAME AND BRIEF DESCRIPTION OF YOUR CONTRIBUTION HERE]
//
// INSTRUCTIONS:
//
// 1.  Create your site structure using folders and files with useful names.
//     Use underscores to signify spaces when naming everything.
//
//     Example: http://www.squid.com/My_Pet_Squid/Meet_Rocky.html shows good
//     name choices to describe an area of content and the contents of a page.
//    
//     Alternatively, you can setup mod_rewrite to create friendly URLs such
//     as the one above.
//
//     Every folder *must* have a default document in it (such as index.html
//     or default.asp or whatever your host specifies).  You can also use
//     301/302 redirection to push the folder root to one of the pages within
//     that folder.  This will replace an index page, if you don't wish to
//     have one.
//
// 1a. If you want to use something other than underscores for spaces (such
//     as hyphens), you can make edits to the actual script to recognize
//     your preference.  A set of prewritten code lines have been inserted
//     below and commented out.  Feel free to use them, or to create your
//     own based on them.
//
// 2.  Fill in the settings for the variables in the next section of this
//     script.  They should be pretty self-explanatory.
//
// 3.  Add the following to your site wherever you want your breadcrumbs
//     to appear (change the path to point to wherever you put this script):
//
//     <div id="breadcrumbs"></div>
//     <script type="text/javascript" src="path/to/breadcrumbs.js"></script>
//
// LICENSE:
//
// This script is protected under General Public License (GPL).  Feel free to
// redistribute this script, so long as you do not alter any of the contents
// specifying authorship.  If you add to or modify this script, you may add
// your name to the "Other Contributors" list at the top of this script.  As
// a courtesy, please email me and let me know how you've improved my script!
// You may not profit from the direct sale of this script.  You may use this
// script in commercial endeavors however (i.e. as part of a commercial site).
//
// Email me here: http://www.paulhirsch.com/contact_me.php
//
// Copyright 2006, Paul Hirsch. All rights specified herein and within GPL
// documentation: http://www.gnu.org/licenses/gpl.txt
//
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
// Change the following variables as instructed                             //
//////////////////////////////////////////////////////////////////////////////

// Enter your domain name here, 
var url = "www.nitrosaggio.net";

// Enter the word you want to use to describe the home page of your site
var home = "Home";

// Enter the character(s) you want to use to separate your breadcrumbs
var divide = "  ::  ";

// Enter text you'd like to see.  You can make this blank as well - "";
var pre = "";

// Enter the extension you use for your pages
var ext = ".htm";

// Enter the default file name you use for the root file of your folders
var root = "index";

//////////////////////////////////////////////////////////////////////////////
// DO NOT TOUCH ANYTHING BELOW THIS LINE                                    //
// unless done in accordance with the instructions at the top of the page.  //
//////////////////////////////////////////////////////////////////////////////

divide = " " + divide + " "; // Adds some space around the breadcrumb divider.
var a = "" + window.location; // Creates a string out of the page URL.
var b = ""; // Declaring this for later.
var bar = divide + root; // Creates a variable to allow us to easily remove some unwanted breadcrumb stuff later.
var code = ""; // Declaring this for later.
var foo = root + ext; // Creates a variable we can use to call the root file of a given folder at a later time.
var left = ""; // Declaring this for later.

a = a.replace(ext,""); // [A] Strips off the file extension from the name of the page.
left = a.lastIndexOf("/"); // Identifies the last forward slash in the page URL.

// If the last character within the URL is a forward slash, this bit of code adds the root folder word to the end of it, so other parts of this script will be able to process things properly.
if (a.substring(a.lastIndexOf("/")) == "/") {
	a = a + root;
}

b = a.substring(left+1); // Makes the variable "b" equal to everything on the right side of the last forward slash in the URL: the page name, minus the file extension (removed in line [A])
b = b.replace(/_/g," "); // Replaces all underscores with spaces.
b = b.replace(/#/g,divide); // Replaces the octothorpe commonly used for jump links with the user-specified divider

// Alternative spacer: hyphen. Remove comment tags in the next line to activate
// b = b.replace(/-/g," ");

code = divide + b; // [B] Makes the variable "code" equal to the name of the page, as stored in variable "b", plus a breadcrumb divider is added in front.
b = "/" + b // The slash is added back to the beginning of variable "b".  It was discarded in line [B].
b = b.replace(divide,"#"); // The octothorpe is put back into the file name.
b = b.replace(/ /g,"_"); // The underscores are put back into the file name.

// Alternative spacer: hyphen. Remove comment tags in the next line to activate
// b = b.replace(/ /g,"-");

a = a.replace(b,""); // Removes the segment that was just used from the variable holding the URL.

// This loop will continue the breadcrumb creation process, so long as the last forward slash is not preceded by another forward slash (which signifies the beginning of the URL)
if (a.substring(left-1) != "/") {
	do  {
		left = a.lastIndexOf("/"); // Identifies the last forward slash in the remaining URL.
		b = a.substring(left+1); // Makes the variable "b" equal to everything on the right side of the last forward slash in the URL: a folder in which a page or deeper folder is being stored.
		b = b.replace(/_/g," "); // Replaces all underscores with spaces.
		
		// Alternative spacer: hyphen. Remove comment tags in the next line to activate
		// b = b.replace(/-/g," ");

		code = divide + "<a href=\"" + foo + "\">" + b + "</a>" + code; // Updates the variable code to include the name of the folder and the URL necessary to reach the folder root.
		foo = "../" + foo; // Adds an additional level to the variable that determines the path to the folder that will be assigned in the breadcrumb loop.
		b = "/" + b; // The slash is added back to the beginning of variable "b".
		b = b.replace(/ /g,"_"); // The underscores are put back into the file name.
		
		// Alternative spacer: hyphen. Remove comment tags in the next line to activate
		// b = b.replace(/ /g,"-");

		a = a.replace(b,""); // Removes the segment that was just used from the variable holding the URL.
	} while (a.substring(left-1) != "/"); // Checks to make sure there's still more string to parse.
}

code = code.replace(url,home); // The remaining URL is replaced with whatever word was specified for the home page of the site.
code = code.replace(bar,""); // If the URL is pointing to a folder root file, the root file name is stripped out, along with the bullet between it and the folder name.
code = (code.substring(code.indexOf("<"))); // The "code" string contains an unwanted bullet at the beginning.  This snippet causes it to be removed/ignored.
code = pre + code; // Any verbiage specified by the author to precede the breadcrumbs is inserted here.
document.getElementById('breadcrumbs').innerHTML = code; // The final code string is inserted into the Web page at the point where it sees an object with the ID "breadcrumbs".