var d, dnlWidth, dnlHeight, dnlMaj, dnlMin, dnlBld, l, p, pr, path, sp, ns, dnlInstalled, viewStr, instStr, prog, speed, progTim, dispWS, controlsAbove, pid, scriptable, tbType, pvImageName, pvMode, imPath;
var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);

function GetObj(id) {
if (isDOM) return document.getElementById(id);
if (isIE4) return document.all[id];
}

function GetStyle(id) {
return GetObj(id).style;
}

function Ready(){
	var o;
	HideProgress();
	o = GetObj("dnlplyr");
	if (o){
		o.LoadBook(path + d);
	}
}

function NoReader(){
	var o;
	HideProgress();
	o = GetObj("bookspace");
	o.innerHTML = instStr;
}

function HideProgress(){
	var st;
	st = GetStyle("ProgressLayer");
	st.visibility = "hidden";
	st = GetStyle("ProgressBarLayer");
	st.visibility = "hidden";
	st = GetStyle("BookLayer");
	st.visibility = "hidden";
	speed = 5;
	prog = 1;
	if (progTim > 0) clearInterval(progTim);
}

function DisplayBook(){
	var o;
	if (!ns) DisplayProgress();
	o = GetObj("bookspace");
	o.innerHTML = viewStr;
	o = GetObj("dnlplyr");
	if (o){
		o.LoadBook(path + d);
	}
}

function Install(){
	var o;
	if (!ns) DisplayProgress();
	o = GetObj("bookspace");
	o.innerHTML = viewStr;
	if (ns){
		xpi={'Install DNL Viewer':'xpinst.xpi'};
		if (InstallTrigger.compareVersion("DNL_Viewer",dnlMaj + "." + dnlMin + ".0." + dnlBld) < 0)
			InstallTrigger.install(xpi);
	}
}

function UpdateProgress(){
var img, s;
prog += speed;
if (prog > 194) prog = 194;
else {
	s = Math.round(prog/40);
	switch(s){
	case 0: speed = 5; break;
	case 1: speed = 4; break;
	case 2: speed = 3; break;
	case 3: speed = 2; break;
	case 4: speed = 1; break;
	}
}
img = GetObj("ProgressBar");
img.width = prog;
}

function DisplayProgress(){
	var st, l, t, w, h, img;
	w = document.body.offsetWidth-20;
	h = dnlHeight + 20;
	l = (w - 250) / 2;
	t = 400;
	st = GetStyle("BookLayer");
	st.left = 50;
	st.top = 235;	
	img = GetObj("BookLyrImg");
	img.width = w - 100;
	img.height = dnlHeight + 50;
	st.visibility = "visible";
	st = GetStyle("ProgressLayer");
	st.left = l;
	st.top = t;	
	img = GetObj("ProgressBar");
	img.width = prog;
	st.visibility = "visible";
	st = GetStyle("ProgressBarLayer");
	st.left = l + 46;
	st.top = t + 21;
	st.visibility = "visible";
	progTim = setInterval("UpdateProgress()",300);
}

function InitData(tb){
progTim = 0;
tbType = tb;
instStr = "<table width=" + dnlWidth + " height=" + dnlHeight + " align='center' border=0><tr>";
instStr += "<td align='center' class='instText'>This page contains a Digital Web Book.<br>";
instStr += "To view this digital web book, you must install the DNL Reader.<br><br>";
instStr += "Click <a href='javascript:Install();'>here</a> to install the DNL Reader<br><br><br>"
instStr += "For more information on Digital Web Books, visit <a href='http://digitalwebbooks.com' target='_blank'>digitalwebbooks.com</a></td>";
instStr += "</tr></table>";

speed = 5;
prog = 1;
l = new String(window.location);
path = "";

ns = (((document.layers) || (document.getElementById && !document.all)) ? true: false);
dnlInstalled = false;
scriptable = false;
if (ns){
	var agt=navigator.userAgent.toLowerCase();
	var majorVer = parseInt(navigator.appVersion);
	if ((majorVer >= 5) && (agt.indexOf("netscape6") < 0)) scriptable = true;
} else {
 	scriptable = true;
}
}

function InsertBook(){
if (ns){
	dnlInstalled = navigator.mimeTypes && navigator.mimeTypes["application/x-dnl"] && navigator.mimeTypes["application/x-dnl"].enabledPlugin;
	viewStr = "<table align='center'><tr><td>";
	viewStr += "<embed id=\"dnlplyr\" type=\"application/x-dnl\"";
	viewStr += "SRC=\"" + path + d + "\" width=" + dnlWidth + " height=" + dnlHeight + "	codebase=\"http://www.digitalwebbooks.com/reader/xpinst.xpi\">";
	viewStr += "</embed></td></tr></table>";
} else {
	viewStr = "<table id='dnltab' align='center'><tr><td>";
	viewStr += "<object classid=\"clsid:164B406B-0FD6-4E7F-BA7E-64D227D4CA37\" ";
	viewStr += "codebase=\"http://www.digitalwebbooks.com/reader/dbplugin.cab#version=" + dnlMaj + "," + dnlMin + ",0," + dnlBld + "\" ";
	viewStr += "name=\"dnlplyr\" id=\"dnlplyr\" data=\"DATA:application/x-oleobject;BASE64,a0BLFtYPf066fmTSJ9TKNwADAADIMAAAUhwAAA==\" ";
	viewStr += "width=" + dnlWidth + " height=" + dnlHeight + " onreadystatechange=\"Ready();\" onerror='NoReader();'>";
	viewStr += "</object></td></tr></table>";
}
if (scriptable) InsertControlBar();
if (dnlInstalled){
	DisplayBook();
} else {
	Install();
}
}

function GoForward(){
 var d = GetObj("dnlplyr");
 if (d) d.GoForward();
}

function GoBack(){
 var d = GetObj("dnlplyr");
 if (d) d.GoBack();
}

function Standalone(){
 var d = GetObj("dnlplyr");
 if (d) d.GoStandAlone();
}

function Save(){
 var d = GetObj("dnlplyr");
 if (d) d.Save();
}

function Mail(){
 var d = GetObj("dnlplyr");
 if (d) d.Mail();
}

function Website(){
 window.open("http://desktopauthor.com/?pid=" + pid, target="_blank");
}

function InsertControlBar(){
var s;
s = "<table id=\"buttons\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
s += "<tr><td><img src=\"" + imPath + "design2_arrow_left.gif\" onClick=\"GoBack()\" title=\"Go Back One Page\"></td>";
s += "<td><img src=\"" + imPath + "design2_blue_logo.gif\" onClick=\"Website()\" title=\"Visit the Software Creator's Website\"></td>";
s += "<td><img src=\"" + imPath + "design2_envelope.gif\" onClick=\"Mail()\" title=\"Email this Book\"></td>";
s += "<td><img src=\"" + imPath + "design2_pop_out.gif\" onClick=\"Standalone()\" title=\"Detach book from Browser\"></td>";
s += "<td><img src=\"" + imPath + "design2_save.gif\" onClick=\"Save()\" title=\"Save this Book\"></td>";
s += "<td><img src=\"" + imPath + "design2_arrow_right.gif\" onClick=\"GoForward()\" title=\"Go Forward One Page\"></td></tr>";
s += "</table><br>";
viewStr = s + viewStr;
}


