/*
[##########*##########*##########*##########*##########]
####												####
####  Custom API developed by						####
####  												####
####  e]O™											####
####   ~  											####
####  												####
####  eYe Openers design							####
####  http://eYeOpenersdesign.com					####
####  contact *web.development* at the above domain	####
####  © Wm Leslie Howard MMX - all rights reserved	####
####  												####
[##########*##########*##########*##########*##########]
*/


/*

##########( PREVIOUS | NEXT TITLE POPULATION ]##########

Populate title attributes in Prev | Next navigation widget (book_series, media gallery, project_scholars, scripts, radio_productions) with a value parsed from the adjacent hyperlink.

-Wm | Wed, 15.Sep.2010 | 04:07:45PM START
-Wm | Mon, 20.Sep.2010 | 10:38:00AM END

*/

function makeTitle(tagID,hrefAttrib) {	

var _position=hrefAttrib.lastIndexOf("/"); 				// Position of last slash.
var startString=_position+1;							// Position of last slash + 1 to find the beginning of the string we want.
var rawString=hrefAttrib.slice(startString); 			// Return the string from the startString position on.
var makeTitle=rawString.replace(/_/gi, " "); 			// Replace all the underscores in the string with spaces.
var showTitle=makeTitle.slice(0,-5); 					// Remove ".html"
var init=showTitle.charAt(0).toUpperCase(); 			// Convert first character to initial cap. Script filenames are lower case.
var rest=showTitle.slice(1); 							// The rest of the string after the cap.
var Title=init+rest; 									// Put it together.
var secondInit=""; 										// Initialized here and used in script exceptions to get first letter after hyphen.
var cap=""; 											// Capitalize that first letter.
var preHyph="";											// String before and including a hyphenated name.
var postHyph=""; 										// Everything after.
var frontString="";										// Used to remove index.html from the string.
var secondWordStart="";									// Used in index.html files to capitalize.
var capWord="";


// If the filename being passed contains "index.html" get the previous group between /s instead of using the final group for the title attribute.

	if (hrefAttrib.slice(-11) == "/index.html"){				// If the last 11 characters of the attribute being passed are "/index.html"
		frontString=hrefAttrib.slice(0,-11); 					// Get the string minus "/index.html"
		endString=frontString.lastIndexOf("/")+1;				// Get position of last "/" and move forward one character.
		rawString=frontString.slice(endString);					// Get the new rawString from the position of the endString forward.
		makeTitle=rawString.replace(/_/gi, " "); 				// Replace all the underscores in the string with spaces.
		showTitle=makeTitle;									// Fill previously declared variable.
		init=showTitle.charAt(0).toUpperCase(); 				// Convert first character to initial cap.
		rest=showTitle.slice(1); 								// The rest of the string after the cap.
		if (rest.indexOf(" ") == -1){							// If there is only one word, finish up.
			if (hrefAttrib.slice(-11) == "/index.html"){
				Title=init+rest+" home";						// Put it together, append "home" to the end and stuff it into the variable.
			} 			
			else{
				Title=init+firstWordEnd+capWord+last;			// Put it together and stuff it into the variable.		
			}		
		}
		else{													// If url is not an index.html file.
			secondWordStart=rest.indexOf(" ")+1					// Get the character position after the space.
			firstWordEnd=rest.slice(0,secondWordStart);			// After the initial cap and including the space.
			capWord=rest.charAt(secondWordStart).toUpperCase();	// Find the charater after the space and capitalize it.
			last=rest.slice(secondWordStart+1);					// Second word after the initial cap.		
			if (hrefAttrib.slice(-11) == "/index.html"){
				Title=init+firstWordEnd+capWord+last+" home";	// Put it together, append "home" to the end and stuff it into the variable.
				writeTitle(tagID,Title);
			} 			
			else{
				Title=init+firstWordEnd+capWord+last;			// Put it together and stuff it into the variable.
			}
		}
	}
	
	
	
	// Punctuation Exceptions:
	
	// Book Series
	if (rawString == "920_O-Farrell_Street.html") {
		showTitle="920 O'Farrell Street";
	}
	if (rawString == "A_Yankee_in_Mexican_California_1834-1836.html") {
		showTitle="A Yankee in Mexican California, 1834-1836";
	}
	if (rawString == "Califauna_A_Literary_Field_Guide.html") {
		showTitle="Califauna: A Literary Field Guide";
	}
	if (rawString == "California_A_Study_of_American_Character.html") {
		showTitle="California: A Study of American Character";
	}
	if (rawString == "Dawsons_Avian_Kingdom.html") {
		showTitle="Dawson's Avian Kingdom";
	}
	if (rawString == "Death_Valley_in_49.html") {
		showTitle="Death Valley in '49";
	}
	if (rawString == "Fools_Paradise.html") {
		showTitle="Fool's Paradise";
	}
	if (rawString == "Mark_Twains_San_Francisco.html") {
		showTitle="Mark Twain's San Francisco";
	}
	if (rawString == "Wallace_Stegners_West.html") {
		showTitle="Wallace Stegner's West";
	}
	if (rawString == "Eldorado_Adventures_in_the_Path_of_Empire.html") {
		showTitle="Eldorado: Adventures in the Path of Empire";
	}
				
	
	//Scripts: Add hyphen where needed. Add comma and period when first initials used.
	if (Title.indexOf(" ") != -1 && location.pathname.indexOf("radio_anthology/scripts/") !=-1 && Title != "Radio Productions home") { // If script title has a space with exception.
		Title=Title.replace(" ", "-"); 							// Replace space with hyphen.
		secondInit=Title.indexOf("-")+1; 						// Find first letter after hyphen.
		cap=Title.charAt(secondInit).toUpperCase(); 			// Capitalize first letter after hyphen.
		preHyph=Title.substring(0,secondInit); 					// Get string up to and including hyphen.
		postHyph=Title.substring(secondInit+1); 				// Get string after hyphen.
		Title=preHyph + cap + postHyph;							// Put it all together.

		if(postHyph.length == 0) {								// Exceptions for first initials.
			preHyph=preHyph.replace("-", ", ");					// Last name, then comma.
			Title=preHyph + cap + ".";							// First initial with period.
		}	
	
		if (Title.indexOf("De-") != -1) {						// Exceptions for names beginning with "de ".
			preHyph="de ";
			Title=preHyph + cap + postHyph;
		}	
	
		if (Title.indexOf("Del-") != -1) {						// Exceptions for names beginning with "del ".
			preHyph="del ";
			Title=preHyph + cap + postHyph;
		}	
	
	}
	
	// Capitalize the second word in other than index.html attributes and single initials in scripts + exceptions for book titles.
	
	if (Title.indexOf(" ") != -1 && Title.slice(-4) != "home" && Title.indexOf(".") == -1 && preHyph != "de " && preHyph != "del "){		// If there's a space - with exceptions.
		init=showTitle.charAt(0).toUpperCase(); 					// Convert first character to initial cap.
		rest=showTitle.slice(1); 									// The rest of the string after the cap.
		secondWordStart=rest.indexOf(" ")+1;						// Get the character position after the space.
		firstWordEnd=rest.slice(0,secondWordStart);					// After the initial cap and including the space.
		capWord=rest.charAt(secondWordStart).toUpperCase();			// Find the charater after the space and capitalize it.
		last=rest.slice(secondWordStart+1);							// Second word after the initial cap.
		
		// Book title exceptions.
		if (last.charAt(0) == "f" && last.charAt(1) == " "){ 		// If second word is "Of," 
			capWord="o";											// Don't capitalize.
		}
		if (last.charAt(0) == "n" && last.charAt(2) == " "){ 		// If second word is "And," 
			capWord="a";											// Don't capitalize.
		}
		if (last.charAt(0) == "t" && last.charAt(1) == " "){ 		// If second word is "At," 
			capWord="a";											// Don't capitalize.
		}
		if (last.charAt(0) == "h" && last.charAt(2) == " "){ 		// If second word is "The," 
			capWord="t";											// Don't capitalize.
		}
		if (hrefAttrib.slice(-11) == "/index.html"){					// If this is an index file...
			Title=init+firstWordEnd+capWord+last+" home";			// Put the string together, append "home" to the end and stuff it into the variable.
		} 			
		else{
			Title=init+firstWordEnd+capWord+last;					// Put string together and stuff it into the variable.
		}
	}
	
	// Miscellaneous exceptions in scripts and media_gallery.
	if (Title == "Van Der veer") {
		Title="Van der Veer";
	}

	if (Title == "Kingston") {
		Title="Kingston: Recent California Literature";
	}

	if (Title == "A Conversation") {
		Title="California Legacy: A Conversation";
	}

	if (Title == "Peaceful Painter Hisako Hibi") {
		Title="Peaceful Painter: Hisako Hibi";
	}

	if (Title == "CLP Book sale") {
		Title="CLP Book Sale";
	}

	// Add phrase to single letter script indexes files.
	if (Title.charAt(1) == ""){
		Title="Author index for the letter " + Title + ".";
	}
	
	// Atlas exception.
	if (Title == "Atlas"){
		Title="CLP Atlas";
	}

	// Readers exception.
	if (Title == "Readers"){
		Title="CLP Anthology Readers";
	}
	
	// Scripts home exception.
	if (Title == "Scripts home"){
		Title="CLP Radio Anthology Scripts home";
	}
	
	// Podcast exception.
	if (Title == "Podcast"){
		Title="CLP Radio Anthology Podcast";
	}

	// Projects title addition and exception making sure this doesn't affect Project Scholars.
	if (hrefAttrib.charAt(28) == "p" && hrefAttrib.charAt(35) != "_"){ 		// If in "projects" directory
		Title="CLP " + Title;												// Prepend "CLP."
		if (Title == "CLP Project home"){									// Exception for "CLP Projects home"
			Title = "Project home"
		}
	}

	if (Title == "Dequille") {												// Exception for Dequille to DeQuille.
	Title="DeQuille";
	}	
		
	if (Title == "Van-Dyke") {												// Exception for "Van-Dyke" to "Van Dyke" Why is the hyphen there?
	Title="Van Dyke";
	}	

// Prepend Project Scholars title. -Wm | Wed, 22.Sep.2010 | 12:22:55AM [I don't belive that date/timestamp.]
if (hrefAttrib.indexOf("project_scholars") != -1){
	if (Title != "Project Scholars home"){
		Title="Project Scholar "+Title;
	}
	else{
		Title=Title;
	}
}

// If Title is a script prepend. -Wm | Wed, 22.Sep.2010 | 12:58:43PM
if(location.pathname.indexOf("radio_anthology/scripts/") !=-1 && location.pathname.indexOf("radio_anthology/scripts/index.html") == -1 && location.pathname.indexOf("radio_anthology/scripts/indexes") == -1){
	Title="Author: " +Title;
}

writeTitle(tagID,Title);
}

function writeTitle(toTag,FinalTitle){
	document.getElementById(toTag).title=FinalTitle;				// Print the title attribute to the id="prev" or id="next" anchor tag.}
}

/*
[##########*##########*##########*##########*##########]
####												####
####  Custom API developed by						####
####  												####
####  e]O™											####
####   ~  											####
####  												####
####  eYe Openers design							####
####  http://eYeOpenersdesign.com					####
####  contact *web.development* at the above domain	####
####  © Wm Leslie Howard MMX - all rights reserved	####
####  												####
[##########*##########*##########*##########*##########]
*/


