

// Copyright 2003-7 The Cyber Hymnal

var midiFile;
var nextPage;
var playCalled = false;
var prevPage;
var root;

//------------------------------------------------
function arrows()
{
// PURPOSE	Draw navigational arrows to home, previous & next pages
// ENTRY		Init() has been called

	document.write('<p class="navigation"><a href="' + prevPage + '" onMouseOver="return stat(\'Go to previous page\')" onMouseOut="return erase()"><img src="' + root + '/img/a/ar-left.gif" title=" Back " width="30" height="30"></a> ')
	document.write('<a href="' + root + 'index.htm#lk" onMouseOver="return stat(\'Go to Cyber Hymnal home page\')" onMouseOut="return erase()"><img src="' + root + 'img/a/ar-toc.gif" title=" Home " width="30" height="30" /></a> ')
	document.write('<a href="' + nextPage + '" onMouseOver="return stat(\'Go to next page\')" onMouseOut="return erase()"><img src="' + root + '/img/a/ar-right.gif" title=" Next " width="30" height="30"></a></p>')
}
//------------------------------------------------
function begin
(
	quote, 	// Scripture quotation
	verse		// Chapter & verse
)
// PURPOSE  Draw the top of the page
// ENTRY	 Init() has been called
{
	if (playCalled == false)
	{
		alert("No call to play(). Please click the \"Report Errors\" link on the home page and send us an e-mail about this problem.")
		location.href = root + "index.htm"
	}
	if (argsOk(arguments.callee, true, false))
	{
		arrows();
		document.write('<marquee>&ldquo;' + quote + '&rdquo; ' + verse + '</marquee><hr />')
	}
}
//------------------------------------------------ 
function bio(text, file) 
{ 
// PURPOSE		Draw link to a biography page 
// ENTRY			Init() has been called 
// ARGUMENTS	text  Link text to display 
//					file  Biography file page (without extension, which must be .htm) 

	if (argsOk(arguments.callee, true, false))
	{
		document.write('<a href="' + root + 'bio/' + file + '.htm" target="_blank" ')
		document.write('onMouseOver="return stat(\'See biography (opens new window/tab)\')" ')
		document.write('onMouseOut="return erase()">' + text + '</a>')
	}
} 
//------------------------------------------------
function end()
{
// PURPOSE Draw end of the page
// ENTRY	Init() has been called
	arrows()
	document.write('<center><iframe src="http://nethymnal.org/js/ads2.htm" width=800 height=150 frameborder=0></iframe></center>')
	document.write('<p class="footer" title="When this page last changed">' + document.lastModified + '</p>');
}
//------------------------------------------------
function init(level, midi, prev, next)
{
// PURPOSE		Page initialization
// ARGUMENTS	level = Number of levels below site root
//				midi = MIDI file name (without extension, which must be .mid)
//				prev = Previous page's URL (without extension, which must be .htm)
//				next = Next page's URL (without extension, which must be .htm)

	if (argsOk(arguments.callee, true, false))
	{
		if (window != top)
			top.location.href = location.href
	  root = ""
	  for (i = 0; i < level; ++i)
	  	root += "../"
		midiFile = root + "mid/" + midi + ".mid"
		prevPage = prev + ".htm"
		nextPage = next + ".htm"
		document.write('<link href="' + root + 'sty/tch-hymn.css" rel="stylesheet" type="text/css" />')
		document.write('<bgsound src="' + midiFile + '" loop="infinite">')
		delay = location.search.toString()
		if (delay != "")
		{
			delay = delay.substring(1, delay.length)
			document.write('<meta http-equiv="refresh" content="' + delay + ';url=' + nextPage + '?' + delay + '">')
		}
	}
}
//------------------------------------------------
function insertMusicLinks(

	midi					,	// Full MIDI file name, including extension
	scoreBase			,	// Score file name, down from score directory (no extension)
	scoreExtension	,	// Extension of score file name (must be same as score directory name)
	scoreType				// Decscription of score file type
)
// PURPOSE	Insert insert links for a MIDI & a score file.
// ENTRY	Init() has been called
{
	if (argsOk(arguments.callee, true, false))
	{
		score = root + scoreExtension + '/' + scoreBase + '.' + scoreExtension
		output = '<span class="musicLinks"> (<a href="' + midi + '" onMouseOver="return stat(\'Open MIDI file\')" onMouseOut="return erase()">MI&shy;DI</a>, '
		output += '<a href="' + score + '"'
		if (scoreExtension == 'pdf')
			output += ' target="_blank"'
		output += ' onMouseOver="return stat(\'See sheet music (' + scoreType + ' format)\')" onMouseOut="return erase()">score</a>)</span>'
		document.write(output)
	}
}
//------------------------------------------------
function lmn(

	score	// Base name of score file, with path down from nwc directory (no extension, which must be "nwc")
)
// PURPOSE	Insert links for a page's main MIDI file & NoteWorthy Composer score file
// ENTRY	Init() has been called
{
	if (argsOk(arguments.callee, true, false))
		lmn2(midiFile, score)
}
//------------------------------------------------
function lmn2
(
	midi,	// Full path to MIDI file, or path down from MIDI directory. If not full path, should not have extension, which must be "mid".
	score	// Score file name, down from the "nwc" directory (no extension, which must be "nwc")
)
// PURPOSE	Insert links for a MIDI file & NoteWorthy Composer score file. This function is called from lmn(),
//			and is also used for "alternate tune" links on hymn pages.
{
	if (argsOk(arguments.callee, true, false))
	{
		if (midi.indexOf(root) == -1)								// If MIDI lacks full path
			midi = root + 'mid/' + midi + ".mid"					// Add it
		insertMusicLinks(midi,score,"nwc","NoteWorthy Composer")
	}
}
//------------------------------------------------
function lmp
(
	score	// Base name of score file, with path down from pdf directory (no extension, which must be "pdf")
)
// PURPOSE	Insert links for a page's main MIDI file & PDF score file
// ENTRY	Init() has been called
{
	if (argsOk(arguments.callee, true, false))
		lmp2(midiFile, score)
}
//------------------------------------------------
function lmp2
(
	midi,	// Full path to MIDI file, or path down from MIDI directory. If not full path, should not have extension, which must be "mid".
	score	// Score file name, down from the "pdf" directory (no extension, which must be "pdf")
)
// PURPOSE	Insert links for a MIDI file & an Adobe PDF score file. This function is called from lmp(),
//			and is also used for "alternate tune" links on hymn pages.
{
	if (argsOk(arguments.callee, true, false))
	{
		if (midi.indexOf(root) == -1)						// If MIDI lacks full path
			midi = root + 'mid/' + midi + ".mid"			// Add it
		insertMusicLinks(midi, score, "pdf", "Adobe PDF")
	}
}
//------------------------------------------------
function play()
{
// PURPOSE	Insert embedded MIDI object for browsers that need it, & insert autoplay HTML when appropriate.
// ENTRY	Init() has been called

	if (playCalled == true)
		alert(error + "Play() called multiple times");
	else
	{
		playCalled = true;
		if (navigator.appName == "Netscape")
 		{
 			document.write('<embed src="' + midiFile + '" autostart="true" height="60" width="144" loop="true" repeat="true">')
 		}
 		if (location.search.toString() != "")
 		{
 			document.write('<p class="autoplay">AUTOPLAY</p>')
 		}
	}
}
//------------------------------------------------
function start
(
	title, 		// Page title
	quote, 		// Scripture quotation
	verse,		// Chapter & verse
	alternate	// Alternate title (optional)
)
{
	play()
	document.write("<h1>" + title + "</h1>")
	if (alternate != null)
		document.write("<h2>" + alternate + "</h2>")
	begin(quote, verse)
	document.write('<center><iframe src="http://nethymnal.org/js/ads1.htm" width=800 height=150 frameborder=0></iframe></center>')

}
//------------------------------------------------
