// Start with no Document
var n = 0;
var LastElement = Places.length-1;
var PageFrame   = null;
var TitleFrame  = null;
var InfoFrame   = null;
var TitleTimer  = null;
var TitleFlag   = 0; 

var detect = navigator.userAgent.toLowerCase();
var browserName = "An unknown browser"
var browserVer  = 0;
var place,thestring;

if (checkIt('konqueror'))    browserName = "Konqueror";
else if (checkIt('omniweb')) browserName = "OmniWeb"
else if (checkIt('opera'))   browserName = "Opera"
else if (checkIt('webtv'))   browserName = "WebTV";
else if (checkIt('icab'))    browserName = "iCab"
else if (checkIt('msie'))    browserName = "Internet Explorer"
else if (!checkIt('compatible'))
{
browserName = "Netscape"
browserVer = detect.charAt(8);
}

function checkIt(string) {
  place = detect.indexOf(string) + 1;
  thestring = string;
  return place;
}

if (browserVer==0) browserVer = detect.charAt(place + thestring.length);

// Go to the first page of the tour
function GoFirst() {
   n=1;
   GoPage(Places[n].uri);
}
//------------------------------

// Jump to the last page of the tour
function GoLast() {
   n=LastElement;
   GoPage(Places[n].uri);
}
//------------------------------

// Go back one page
function GoBack() {
if (n>1)  n--;  
 else
 {  n=1;  
	alert("\nThis is already the first page of the tour! \n\n");  }
 GoPage(Places[n].uri);
}
//------------------------------

// Go to the next page
function GoNext() {
if (n<LastElement)  n++;
 else
 { alert("\nThis is already the last page of the tour!\nPress the exit button to leave the guided tour mode.\n\n");  }
 GoPage(Places[n].uri);
}
//------------------------------

// Go to Page no x
function GoPos(x) {
   n=x;
   GoPage(Places[n].uri);
}
//------------------------------

// Create an index of all pages of the guided tour
function CreateIndex() {
 if (TitleFlag!=0) { clearTimeout(TitleTimer); TitleFlag=0; }
 InfoFrame = parent.display;  // Opera needs this...
 
 InfoFrame.document.open('text/html');
 InfoFrame.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />\n<link href="main.css" rel="stylesheet" />\n</head>\n<body class="single" bgcolor="#FFFFFF" linkcolor="#0040C0">\n');
 InfoFrame.document.write('<div class="content">\n<div class="heading_small">Guided tour index</div>');
 if (n>0) 
 {
   InfoFrame.document.write("You are at page "+n+" of  "+LastElement+".");
 }
 // Create an ordered list: <ol>
 InfoFrame.document.write('<ol>');
 for(var i = 1;  i <= (LastElement); i++)  {

	// Link...
	InfoFrame.document.write('<li><p><a href="'+Places[i].uri+'" onClick="parent.GoPos('+i+'); return false">'); 
    
	// Title
	if (i==n)   // Last visited page
		InfoFrame.document.write('<font size="5" color="#b02000">'+Places[i].Title +'</font>\n');   
   	else
    	InfoFrame.document.write('<strong>'+Places[i].Title +'</strong>\n');  

	InfoFrame.document.write('</a><br />');
	// Description
    InfoFrame.document.write('<font size="-1" face="Arial,Helvetica">'+Places[i].Description+'</font></p></li>\n');
    //InfoFrame.document.write('<font size="0">'+Places[i].uri+"</font>");
    }
 InfoFrame.document.write('</ol><br /></div></body></html>\n');
 InfoFrame.document.close();
}
//------------------------------

// Reload page.
function Reload() {
 if (n==0) n=1;
 GoPage(Places[n].uri);
 // if (version == "n>2") parent.display.location.reload();
}
//------------------------------

// Open in extra Window
function ExtraWindow() {
   if (n==0) n=1;
   if (TitleFlag!=0) { clearTimeout(TitleTimer); TitleFlag=0; }
   // TitleTimer = window.setTimeout("PrintTitle();TitleFlag=0;",600); TitleFlag=1;
   var WinURL = Places[n].uri;
   win=window.open(WinURL,"browse");
   if (browserVer > 3) win.focus();  
}
//-----------------------------------

// Show help screen
function ShowHelp() {
  if (TitleFlag!=0) { clearTimeout(TitleTimer); TitleFlag=0; }
  if ((browserName == "Internet Explorer" || browserName == "Opera") && browserVer >= 4)
  {  // MSIE 4 has new bugs.
    parent.display.document.open('text/html');
    parent.display.document.write('<html><frameset rows="*" border=0>\n');
    parent.display.document.write('<frame src="'+HelpURL+'" name="help">\n');
    parent.display.document.write('</frameset>\n<noframes>\n');
    parent.display.document.write('<H1>Error!</H1>Please notify me by  <a href="mailto:harald@weinreichs.de">EMail</a>. Harald Weinreich<br />\n</noframes></html>\n');
    parent.display.document.close();
  }
  else 
  {
   	parent.display.location.href=HelpURL;
  	// InfoFrame.location.replace(HelpURL);  // Für neuere Browser!
  }
}
//------------------------------

// Exit Guided Tour
function Exit() 
{ 
	if (TitleFlag!=0) { clearTimeout(TitleTimer); TitleFlag=0; }
    win=window.open(ReferringPage,"_top"); 
}
//-----------------------------------

//
function GoPage(uri) {
  if (TitleFlag!=0) { clearTimeout(TitleTimer); TitleFlag=0; }
  if (browserName=="Netscape" || browserVer>3)
  {
    InfoFrame = parent.display;  // Opera needs this...
    InfoFrame.document.open('text/html');
    InfoFrame.document.write('<html>\n<frameset rows="*,30" border=0>\n');
    InfoFrame.document.write('<frame src="'+uri+'" name="page" marginwidth="6" marginheight="6">\n');
    if (browserName=="Opera")
        InfoFrame.document.write('<frame name="title" marginwidth="6" marginheight="3">\n');
    else
        InfoFrame.document.write('<frame src="'+BlankURL+'" name="title" marginwidth="6" marginheight="3">\n');
    InfoFrame.document.write('</frameset>\n<noframes>\n');
    InfoFrame.document.write('<H1>Error!</H1>Please notify me by  <a href="mailto:harald@weinreichs.de">EMail</a>. Harald Weinreich<br />\n</noframes></html>\n');
    InfoFrame.document.close();
  }
  else
  {
    PageFrame=parent.display.page;
    PageFrame.location.href=uri;
  }
  TitleTimer = window.setTimeout("TitleFlag=0;PrintTitle();",600); TitleFlag=1;
}

// Print title
function PrintTitle() {
   TitleFlag=0;
   TitleFrame = parent.display.title
   TitleFrame.document.open('text/html');
   TitleFrame.document.write("<html><head>"+'<link href="main.css" rel="stylesheet" />'+"</head><body>");
   TitleFrame.document.write('<table width="98%" style="margin-left:.5em;margin-right:.5em"><tr><td align="left" style="font-size:18;color:#CCCCFF;text-transform:uppercase">'+Places[n].Title+"&nbsp;&nbsp;");
   TitleFrame.document.write('<span style="font-size:9" color="#DDDDFF">'+Places[n].Description+'</span></td><td align="right">');
   // Only recent Versions of Netscape may execute this. Bugs...
   if ((browserName!="Netscape" || browserVer > 3) && browserName!="Opera")
   {
       for(var i = 1;  i <= (LastElement); i++)  {
          if (i == n)
         { TitleFrame.document.write('<font size="0" color="#FFFFFF"><strong>'+i+'</strong></font> \n'); } 
         else 
         { TitleFrame.document.write('<font size="-1" color="#FFFFCC"><a href="'+Places[i].uri+'" onClick="parent.parent.GoPos('+i+'); return false">'+i+'</a></font> \n'); }
       }
   }
   else
   {
      TitleFrame.document.write('<font size="-1">You are at page '+n+' of '+LastElement+'.</font>\n');
   }
   TitleFrame.document.write("</td></tr></table>\n</body></html>");
   TitleFrame.document.close();
}

