/* Copyright 2005 - Pierre Saslawsky - pierre at photobiker.com */


//----------------------------------------------------
// Utilities
//----------------------------------------------------

function getDocumentParentFolder() {
	var aFolder = location.href.split("/");
	return aFolder[aFolder.length - 2];

}

function getDocumentGrandParentFolder() {
	var aFolder = location.href.split("/");
	return aFolder[aFolder.length - 3];

}

function isMerrittJournal() {
	return (location.href.indexOf('Merritt') != -1);
}

function isPierreJournal() {
	return (location.href.indexOf('Pierre') != -1);
}


//----------------------------------------------------
// UI Utilities
//----------------------------------------------------

function DisplayJournalLinks(which) {
	if (which == SELECT_DEFAULT) {
		if (isMerrittJournal()) which = SELECT_MERRITTJOURNAL;
		else
		if (isPierreJournal()) which = SELECT_PIERREJOURNAL;
	}
	DisplayMainLinks(which);
}

function DisplayArchivesLinks(isArchivePage) {
	if (isMerrittJournal()) which = (isArchivePage ? SELECT_MERRITTARCHIVES : SELECT_MERRITTENTRY);
	else
	if (isPierreJournal()) which = (isArchivePage ? SELECT_PIERREARCHIVES : SELECY_PIERREENTRY);
	DisplayMainLinks(which);
}


function GetWriterString(journal) {
	var pos = journal.indexOf('-Journal');
	if (pos != -1)
		journal = journal.substring(0, pos);
	return journal;
}

function GetWriterInContinentString(journal) {
	if (langFr)
		return GetWriterString(journal) + " en " + getContinentNameFR(gCurrentContinent);
	return GetWriterString(journal) + " in " + getContinentName(gCurrentContinent);
}

function DisplayPhotobikerJournalTitleBar(journal) {
	DisplayPhotobikerTitleBar(GetWriterInContinentString(journal));
}

function DisplayJournalWindowTitle(journal) {
	var saveLangFr = langFr;
	langFr = false;
	// The window title needs to be in English because I don't know how to convert
	// the accentuated characters html sequences (&xxx;) from the continent names.
	document.title = GetWriterInContinentString(journal);
	langFr = saveLangFr;
}


function DisplayPhotobikerJournalArchivesTitleBar(journal) {
	DisplayPhotobikerJournalTitleBar(journal);
}

function DisplayJournalArchivesWindowTitle(journal) {
	var saveLangFr = langFr;
	langFr = false;
	// The window title needs to be in English because I don't know how to convert
	// the accentuated characters html sequences (&xxx;) from the continent names.
	document.title = "Archives of " + GetWriterInContinentString(journal);
	langFr = saveLangFr;
}



//----------------------------------------------------
// UI Main Functions
//----------------------------------------------------

function DisplayMissingJournalUI() {
	DisplayJournalWindowTitle(getDocumentParentFolder());
	DisplayPhotobikerJournalTitleBar(getDocumentParentFolder());

	document.write('<div class="sidebarContainer">');
	showContinentSelector();

	document.write('<div class="sidebar navlinks">');
	DisplayJournalLinks(SELECT_DEFAULT);
	document.write('</div>');
	showPrintButton();
	showLangButtons();
	showFirefoxButton();
	document.write('</div>');
}

function DisplayRecentJournalEntriesTitle() {
	DisplayJournalWindowTitle(getDocumentParentFolder());
	DisplayPhotobikerJournalTitleBar(getDocumentParentFolder());
}

function DisplayRecentJournalEntriesSidebar() {
	showContinentSelector();


	document.write('<div class="sidebar navlinks">');
	DisplayJournalLinks(SELECT_DEFAULT);
	document.write('</div>');

	showPrintButton();
	showLangButtons();
	showFirefoxButton();
}

function DisplayJournalArchivesTitle() {
	DisplayJournalArchivesWindowTitle(getDocumentGrandParentFolder());
	DisplayPhotobikerJournalArchivesTitleBar(getDocumentGrandParentFolder());
	showGoogleTopRightSkyscraper();
}

function DisplayJournalArchivesSidebar() {
	showContinentSelector();

	document.write('<div class="sidebar navlinks">');
	DisplayArchivesLinks(true);
	document.write('</div>');

	showLangButtons();
	showFirefoxButton();
}

function DisplayJournalEntryTitle(journal) {
	if (langFr)
		DisplayPhotobikerTitleBar("Journal de " + GetWriterString(journal));
	else
		DisplayPhotobikerTitleBar(GetWriterString(journal) + "'s Journal");
}


function DisplayJournalEntrySidebar() {
	document.write('<div class="sidebar navlinks">');
	document.write('<a href="" id="Previous">Previous story</a>');
	document.write('<a href="" id="Next">Next story</a>');
	document.write('</div>');

	document.write('<div class="sidebar navlinks">');
	DisplayArchivesLinks(false);
	document.write('</div>');

	showPrintButton();
	showLangButtons();
	showFirefoxButton();
}

/*==============================================*/

document.write('<script src=\"' + getSiteBaseUrl() + 'lang/' + 'firefox.js' + '\"></script>');

/*==============================================*/
