
function init() {

	try { if (body_background != "") { document.getElementById("body").style.backgroundColor = body_background; } } catch(e) {  /* on error */ }
	try { if (container_background != "") { document.getElementById("container").style.backgroundColor = container_background; } } catch(e) { /* on error */ }
	try { if (border_image_left != "") { document.getElementById("border_l").style.background = "transparent url("+border_image_left+")repeat"; } } catch(e) { /* on error */ }
	try { if (border_image_right != "") { document.getElementById("border_r").style.background = "transparent url("+border_image_right+")repeat"; } } catch(e) { /* on error */ }
	try { if (contents_header_font_color != "") { document.getElementById("menu_title").style.color = contents_header_font_color; } } catch(e) { /* on error */ }

	try { if (pages_width != "") { document.getElementById("fsiviewer").style.width = pages_width; } } catch(e) { /* on error */ }
	try { if (pages_height != "") { document.getElementById("fsiviewer").style.height = pages_height; } } catch(e) { /* on error */ }

	try { if (dotted_line_right != "") { document.getElementById("dotted_line").style.right = dotted_line_right; } } catch(e) { /* on error */ }
	try { if (dotted_line_width != "") { document.getElementById("dotted_line").style.width = dotted_line_width; } } catch(e) { /* on error */ }
	try { if (dotted_line_top != "") { document.getElementById("dotted_line").style.top = dotted_line_top; } } catch(e) { /* on error */ }
	try { if (dotted_line_height != "") { document.getElementById("dotted_line").style.height = dotted_line_height; } } catch(e) { /* on error */ }

	setup_menu();
}

function setup_menu(selected_page,from) {
	//alert(selected_page);

	if (from == "menu") {
	//	alert("menu changed page to "+selected_page);
		if (parseInt(selected_page)%2 == 0) {
	//		alert("even page ignore the next page");
			ignored_page_change = parseInt(selected_page) + 1;
			setup_menu_items(selected_page);
		} else {
	//		alert("odd page, ignore the previous page");
			ignored_page_change = parseInt(selected_page) - 1;
			setup_menu_items(selected_page);
		}
	} else {
		//alert("something else changed page");
		
		if (selected_page != ignored_page_change) {
			setup_menu_items(selected_page);
		} else {
			ignored_page_change = 0;
	//		alert("ignoring page change");
		}
	}
}

function setup_menu_items(selected_page) {
	document.getElementById("menu_title").innerHTML = contents_header_text;
	menu_string = "";
	selected_identifier = "";
	for (i in chapter_names) {
		try { if (chapter_font_color != "") { chapter_color = "color:"+chapter_font_color; } else { chapter_color = ""; } } catch(e) { /* on error */ }
		menu_string += "<a href=\"#\" class=\"chapter\" style=\""+chapter_color+"\" onMouseDown=\"FSIgotoPage("+chapter_pages[i]+");setup_menu("+chapter_pages[i]+",'menu');\" onMouseUp=\"FSInoCommand()\">"+chapter_names[i]+"</a><br />";
			temp = parseInt(i)+1;
		if (selected_page != undefined && parseInt(selected_page) >= parseInt(chapter_pages[i]) && (parseInt(selected_page) < parseInt(chapter_pages[temp]) || i == chapter_pages.length-1)) {
			selected_page = parseInt(selected_page);
			menu_string +="<table>";
			for (j in sub_chapter_names) {
				if (sub_chapter_parents[j] == i) {
					this_sub_chapter_page = parseInt(sub_chapter_pages[j]);
					if (selected_page >= this_sub_chapter_page) {
						selected_identifier = "sub_chapter_"+j;
					} 
					
					
					try { if (sub_chapter_font_color != "") { sub_chapter_color = "color:"+sub_chapter_font_color; } else { sub_chapter_color = ""; } } catch(e) { /* on error */ }
					try { if (sub_chapter_number_font_color != "") { number_color = "color:"+sub_chapter_number_font_color; } else { number_color = ""; } } catch(e) { /* on error */ }

					menu_string += "<tr><td valign=\"top\"><a href=\"#\" id=\"sub_chapter_"+j+"\" class=\"number\" style=\""+number_color+"\" onMouseDown=\"FSIgotoPage("+sub_chapter_pages[j]+");setup_menu("+sub_chapter_pages[j]+",'menu');\" onMouseUp=\"FSInoCommand()\">"+sub_chapter_read_pages[j]+"&nbsp;</a></td>";
					menu_string += "<td valign=\"top\"><a href=\"#\" id=\"sub_chapter_"+j+"\" class=\"visible\" style=\""+sub_chapter_color+"\" onMouseDown=\"FSIgotoPage("+sub_chapter_pages[j]+");setup_menu("+sub_chapter_pages[j]+",'menu')\" onMouseUp=\"FSInoCommand()\">"+sub_chapter_names[j]+"</a></td></tr>";
				}
			}
			menu_string +="</table>";
		}
		menu_string += "<table><tr><td style=\"height:3px;\"></td></tr></table>";
	}
	document.getElementById("menu_content").innerHTML = menu_string;

	// now set class of selected_identifier to selected
	//selected_identifier = selected_identifier - 1;
	if (selected_page != undefined) {
		if (InternetExplorer == true) {
			//alert("selected_identifier = "+selected_identifier);
			try {
				document.getElementById(selected_identifier).setAttribute("className", "selected");
			} catch (e) {
				// some error
			}
			try {
				document.getElementById(selected_identifier).innerHTML = "&nbsp;&nbsp;&nbsp;";
			} catch (e) {
				// some error
			}
			
			//document.getElementById(selected_identifier).setAttribute("padding-left", "-32px");

		} else {
			//alert("non-ie");
			try {
				document.getElementById(selected_identifier).setAttribute("class", "selected"); 
			} catch (e) {
				// some error
			}
		}
	}	
}

function change_page(the_page) {
	if (the_page == "1") { setup_menu(); } else {setup_menu(the_page); }
//	alert("ss");
}

var ignored_page_change = 0;

var chapter_names = new Array();
var chapter_pages = new Array();
var sub_chapter_names = new Array();
var sub_chapter_pages = new Array();
var sub_chapter_parents = new Array();
var sub_chapter_read_pages = new Array();

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
function FSIgotoPage(nPage){
	doFSICommand("newImageIndex", nPage);
	doFSICommand("FSICMD", "GotoPage");
}
function FSInextPage(){
	doFSICommand("FSICMD", "NextPage");
}
function FSIpreviousPage(){
	doFSICommand("FSICMD", "PreviousPage");
}
function FSInoCommand(){
	doFSICommand("FSICMD", "");
}
function doFSICommand(cmd, arg){
	var fsiviewerObj = InternetExplorer ? fsiviewer : document.fsiviewer;

	try{
	//alert(fsiviewerObj);
		fsiviewerObj.SetVariable(cmd, arg);
	}
	catch(e){
	//alert(e);
	}
	
}


function resize_window(x,y)
{
	//window.resizeTo(x,y)
	window.innerheight = y;
	window.innerwidth = x;

}
function alertSize(x,y) {

	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
	//window.alert( 'Width = ' + myWidth );
	//window.alert( 'Height = ' + myHeight );
}
			
var where = ""; // which link
function checkwhere(e) {
		if (document.layers){
		xCoord = e.x;
		yCoord = e.y;
}
		else if (document.all){
		xCoord = event.clientX;
		yCoord = event.clientY;
}
		else if (document.getElementById){
		xCoord = e.clientX;
		yCoord = e.clientY;
}
		//self.status = "X= "+ xCoord + "  Y= " + yCoord; 
		}


document.onmousemove = checkwhere;
if(document.captureEvents) {document.captureEvents(Event.MOUSEMOVE); }

