/////////////////////////////////////////////////////////////////////CONSTRUCTOR
function Keyboard(n)
//
////////////////////////////////////////////////////////////////////////////////
{
	var count;
	
	this.name=n;
	this.frame;
	this.keys = new Array();

	this.AddKey = kAddKey;
	this.RemoveKey = kRemoveKey;
	this.Assign = kAssign;
	this.KeyboardEvent=kKeyboardEvent;
}
	//////////////////////////////////////////////////////////////////////method
	function kAddKey(key)
	//
	////////////////////////////////////////////////////////////////////////////
	{
		this.keys[this.keys.length]=key;
	}
	//////////////////////////////////////////////////////////////////////method	
	function kRemoveKey(key)
	//
	////////////////////////////////////////////////////////////////////////////
	{
		var ar2=new Array();
		
		for(count=0;count<this.keys.length;count++)
		{
			if( (this.keys[count].casesensitive && this.keys[count].letter == letter) 
				|| (this.keys[count].letter.toLowerCase() == letter.toLowerCase()) )
			{}
			else
			{
				ar2[length]=ar2;
			}
		}
		this.keys=ar2;
	}
	//////////////////////////////////////////////////////////////////////method	
	function kAssign(w,obj,doc)
	//
	////////////////////////////////////////////////////////////////////////////
	{
		this.frame = w;
		if(navigator.appName.indexOf("Expl") > -1)
		{
			obj.onkeydown=Function('e', '{' + w + '.kKeyboardEvent(e, "' + w + '", "' + this.name + '" );}');
		}
		else
		{
			doc.captureEvents(Event.KEYDOWN);
			obj.onkeydown=Function('e', '{' + w + '.kKeyboardEvent(e, "' + w + '", "' + this.name + '" );}');
		}
	}
	//////////////////////////////////////////////////////////////////////method	
	function kKeyboardEvent(e, w, n)
	//
	////////////////////////////////////////////////////////////////////////////
	{
		var letter;

		if(navigator.appName.indexOf("Expl") > -1)
		{
			if(top.event && !top.event.ctrlKey)
      {
				letter=String.fromCharCode(top.event.keyCode);
      }
			else if(event  && !event.ctrlKey)
      {
				letter=String.fromCharCode(event.keyCode);
      }
		}
		else
		{
			if(e.modifiers==0)
      {
				letter=String.fromCharCode(e.which);
      }
		}
    
		if(letter)
		{
			s=w + "."  + n + ".keys";
			keys = eval(s);

			for(count=0;count<this.keys.length;count++)
			{
				if( (keys[count].casesensitive && keys[count].letter == letter) 
					|| (keys[count].letter.toLowerCase() == letter.toLowerCase()) )
				{
					keys[count].Press();
				}
			}
		}
		return false;

	}
    
////////////////////////////////////////////////////////////////////////////////
function SetupStartKB()
// Sets up the keyboard shortcut for the start page of an exported presentation.
////////////////////////////////////////////////////////////////////////////////
{
	kb = new Keyboard("kb");
  
  usingIE = navigator.appName && navigator.appName.indexOf("Expl") > -1;
	
	if(usingIE)
	{
		kb.Assign("top", top.document, self.document);
		kb.Assign("top", self.document, self.document);
    
    // IE Key codes:
    //   39 = right arrow
    //  190 = >

    kb.AddKey( new Key("s", "window.location = top.linkstart.href;") );
    kb.AddKey( new Key(" ", "window.location = top.linkstart.href;") );
    kb.AddKey( new Key(String.fromCharCode(39), "window.location = top.linkstart.href;") );
    kb.AddKey( new Key(String.fromCharCode(190), "window.location = top.linkstart.href;") );
	}
	else
	{
		kb.Assign("top", self.document, self.document);
    
    kb.AddKey( new Key("s", "window.location = document.links[0].href;") );
    kb.AddKey( new Key(" ", "window.location = document.links[0].href;") );
    kb.AddKey( new Key(".", "window.location = document.links[0].href;") );
	}
}

////////////////////////////////////////////////////////////////////////////////
function SetupKB()
// Sets up the keyboard shortcuts for a slide page of an exported presentation.
////////////////////////////////////////////////////////////////////////////////
{
	kb = new Keyboard("kb");
  
  usingIE = navigator.appName && navigator.appName.indexOf("Expl") > -1;
	
	if(usingIE)
	{
		kb.Assign("top", top.document, self.document);
		kb.Assign("top", self.document, self.document);
    
    // IE Key codes:
    //   37 = left arrow
    //   38 = up arrow
    //   39 = right arrow
    //   40 = down arrow
    //  188 = <
    //  190 = >
    
    // Start/Stop presentation
    kb.AddKey( new Key("s", "window.location = top.linkstop.href;") );
    
    // First slide
    kb.AddKey( new Key("a", "window.location = top.linkfirst.href;") );
    kb.AddKey( new Key(String.fromCharCode(38), "window.location = top.linkfirst.href;") );
    
    // Previous slide
    kb.AddKey( new Key(String.fromCharCode(37), "window.location = top.linkback.href;") );
    kb.AddKey( new Key(String.fromCharCode(188), "window.location = top.linkback.href;") );
    
    // Next slide
    kb.AddKey( new Key(" ", "window.location = top.linkforward.href;") );
    kb.AddKey( new Key(String.fromCharCode(39), "window.location = top.linkforward.href;") );
    kb.AddKey( new Key(String.fromCharCode(190), "window.location = top.linkforward.href;") );
    
    // Last slide
    kb.AddKey( new Key("z", "window.location = top.linklast.href;") );
    kb.AddKey( new Key(String.fromCharCode(40), "window.location = top.linklast.href;") );
	}
	else
	{
		kb.Assign("top", self.document, self.document);
    
    // Start/Stop presentation
    kb.AddKey( new Key("s", "window.location = document.toolbar.document.links[0].href;") );

    // First slide
    kb.AddKey( new Key("a", "window.location = document.toolbar.document.links[1].href;") );

    // Previous slide
    kb.AddKey( new Key(",", "window.location = document.toolbar.document.links[2].href;") );

    // Next slide
    kb.AddKey( new Key(".", "window.location = document.toolbar.document.links[3].href;") );
    kb.AddKey( new Key(" ", "window.location = document.toolbar.document.links[3].href;") );

    // Last slide
    kb.AddKey( new Key("z", "window.location = document.toolbar.document.links[4].href;") );
	}
}
