var pageCurrent = 1;
var objPage = null;

// Draw the page navigation bar on the screen using a loop.
function writePageControls() {
	document.writeln ('<div class="pageFlipBar">');
	if (pageCurrent!=1) document.writeln ('<a href="#" onclick="pageTurn(\'back\')" class="controlElem">&laquo;</a>');
	else document.writeln ('&laquo;');
	document.writeln ('Chapter ');
	for (i=1;i<=pageTotal;i++) {
		if (i==pageCurrent) document.write (i)
		else document.write ('<a href="#" onclick="pageJump('+i+')" class="controlElem">'+i+'</a>');
		if (i!=pageTotal) document.write('&nbsp;&nbsp;');
	}
	if (pageCurrent!=pageTotal) document.writeln ('<a href="#" onclick="pageTurn(\'next\')" class="controlElem"> &raquo;</a>');
	else document.writeln (' &raquo;');
	document.writeln ('</div>');
	document.writeln (' <br clear="all"/>');	
	if (pageCurrent==pageTotal) pageCurrent=1;
	else pageCurrent++;
}

// A link to the next page.
function writeMoveToNextPage() {
	document.writeln ('<div class="nextChapterLink">');
	document.writeln ('<a href="#" onclick="pageTurnAndScroll(\'next\')" class="controlElem"> Next Chapter &raquo;</a>');
	document.writeln ('</div>');
}

// A link to the previous page.
function writeMoveToPrevPage() {
	document.writeln ('<div class="prevChapterLink">');
	document.writeln ('<a href="#" onclick="pageTurnAndScroll(\'back\')" class="controlElem">&laquo; Previous Chapter</a>');
	document.writeln ('</div>');
}

// Shift to the next page element.
function pageTurn(direction) {
	if ((direction=='back') && (pageCurrent!=1)) pageCurrent--;
	if ((direction=='next') && (pageCurrent!=pageTotal)) pageCurrent++;
	if (objPage) objPage.style.display = 'none';
	pageName = 'page' + pageCurrent;
	objPage=document.getElementById(pageName);
	objPage.style.display = 'block';
	}

// Shift to the next page element and scroll up.
function pageTurnAndScroll(direction) {
	scrollTo(0,0);
	if ((direction=='back') && (pageCurrent!=1)) pageCurrent--;
	if ((direction=='next') && (pageCurrent!=pageTotal)) pageCurrent++;
	if (objPage) objPage.style.display = 'none';
	pageName = 'page' + pageCurrent;
	objPage=document.getElementById(pageName);
	objPage.style.display = 'block';
	}

// Shift to the clicked page element and hide old one.
function pageJump(pageName) {
	if(!pageName) pageName=1;
	if (objPage) objPage.style.display = 'none';
	pageCurrent = pageName;
	pageName = 'page' + pageCurrent;
	objPage=document.getElementById(pageName);
	objPage.style.display = 'block';
	}

// Spoiler controls.

var currentLink = 0;

// Write links.
function writeDynamicLinks(arr, arr2) {
	document.writeln ('<div class="pageFlipBar">');
	for (i=0; i<arr.length; i++) {
		if (i==currentLink) document.writeln(arr[i])
		else document.write ('<a href="#" onclick="linkJump(\''+arr2[i]+'\')" class="controlElem">'+arr[i]+'</a>');
		if (i!=arr.length-1) document.write('&nbsp;|&nbsp;');
	}
	document.writeln ('</div>');
	document.writeln (' <br clear="all"/>');	
	if (currentLink==arr.length) currentLink=0;
	else currentLink++;
}

// Shift to the clicked page element and hide old one.
function linkJump(pageName) {
	if(!pageName) pageName="englishtrans";
	if (objPage) objPage.style.display = 'none';
	objPage=document.getElementById(pageName);
	objPage.style.display = 'block';
	}
	
// Screen Resolution
function checkScreenRes() {
	var screenWidth = window.screen.width;
	var screenHeight = window.screen.height;
	document.cookie = "screenres="+screenWidth+" x "+screenHeight+"; expires=; path=/";
}
