/*************
 * LoadBook
 * c 1997-2000 integral
 *
 * v1.2
 *
 *************/

// Page object
function Page(fileName, chapterNum, headingNum, noteFileName) {
	this.fileName = fileName;
	this.chapterNum = chapterNum;
	this.headingNum = headingNum;
	this.noteFileName = noteFileName;
}

// Heading object
function Heading(title, firstPageNum) {
	this.title = title;
	this.firstPageNum = firstPageNum;
}

// Chapter object
function Chapter(title, firstPageNum) {
	this.title = title;
	this.firstPageNum = firstPageNum;
	this.arrHeading = new Array(); // Headings included in chapter
}

// should be the same with zintNavigation.js
ZINT_CHAPTER_SEPERATOR = "zintChapterSeparator";
ZINT_CHAPTER_END = "zintEndChapter";
ZINT_TEST_END = "zintEndTest";


arrPage = new Array();
arrChapter = new Array();

// variables will be used for filling arrays
pageLast = -1;
chapterLast = -1;
headingLast = -1;

// variables which will be changed by navigation functions
pageCurrent = 0;
chapterCurrent = 0;
headingCurrent = 0;

/*****
 * adds the name and the title of the pages, the name of the note page (if present) to the arrays
 * it adds htm extension to the name
 * N.B. If you are going to use note page, 
 *	1. Implement note frame in index.htm
 *	2. Add note page name (without extension) using the following syntax: addPage("mainPage|notePage","Example of note usage");
 */
function addPage(name,title){
	pageLast ++;

	if (title) {
		// page with title: add heading
		headingLast ++;
		arrChapter[chapterLast].arrHeading[headingLast] = new Heading(title, pageLast);
	}

	// See if there is a note page
	var arrTokens = name.split("|");
	if (arrTokens.length == 2) {
		arrPage[pageLast] = new Page(arrTokens[0] + ".htm", chapterLast, headingLast, arrTokens[1] + ".htm");
	} else {
		arrPage[pageLast] = new Page(arrTokens[0] + ".htm", chapterLast, headingLast, "");
	}	

}


/*****
 * Marks the begining of chapter
 * and remembers the index of page after chapter.htm (beginning of a new chapter)
 */
function newChapter(name){
	chapterLast ++;
	headingLast = -1;
	addPage(ZINT_CHAPTER_SEPERATOR);
	arrChapter[chapterLast] = new Chapter(name, pageLast + 1);
	//chapterFilling = chapterLast - 1;
}


/*****
 * Marks the end of chapter
 */
function endChapter(){
	addPage(ZINT_CHAPTER_END);
}


/*****
 * Marks the end of test
 */
function endTest(){
	addPage(ZINT_TEST_END);
}
