/* HotKey Accessiblity Script

Author:     Murat Dilek 
Date:      January 2005

Note that some of the techniques here have been picked up from Chapter 9 of 
"JavaScript and DHTML Cookbook", by Danny Goodman, published by O'Reilly.
*/
// This array should be set up as required for YOUR web page.

var keyActions = new Array ();
keyActions [0] = {character:  "1", 
                  actionType: "link", 
                  param:      "/council_homepage.htm"};                  
keyActions [1] = {character:  "2", 
                  actionType: "link", 
                  param:      "/services_homepage.htm"};    
keyActions [2] = {character:  "3", 
                  actionType: "link", 
                  param:      "/business.htm"};                  
keyActions [3] = {character:  "4", 
                  actionType: "link", 
                  param:      "/leisure.htm"}; 
keyActions [4] = {character:  "5", 
                  actionType: "link", 
                  param:      "/stirling.htm"};                  
keyActions [5] = {character:  "6", 
                  actionType: "link", 
                  param:      "/community.htm"}; 
keyActions [6] = {character:  "7", 
                  actionType: "link", 
                  param:      "/your_life.htm"};                  
keyActions [7] = {character:  "8", 
                  actionType: "link", 
                  param:      "/access-info.htm"}; 
keyActions [8] = {character:  "9", 
                  actionType: "link", 
                  param:      "/council_structure.htm"};
keyActions [9] = {character:  "h", 
                  actionType: "link", 
                  param:      "/index.htm"};

		              
// End of user defined array
function hotKeys (event) {
  // Get details of the event dependent upon browser
  event = (event) ? event : ((window.event) ? event : null);  
  // We have found the event.
  if (event) {      
    // Hotkeys require that either the control key or the alt key is being held down
    if (event.ctrlKey || event.altKey || event.metaKey) {    
      // Pick up the Unicode value of the character of the depressed key.
      var charCode = (event.charCode) ? event.charCode : ((event.which) ? event.which : event.keyCode);      
      // Convert Unicode character to its lowercase ASCII equivalent
      var myChar = String.fromCharCode (charCode).toLowerCase();      
      // Convert it back into uppercase if the shift key is being held down
      if (event.shiftKey) {myChar = myChar.toUpperCase();}          
      // Now scan through the user-defined array to see if character has been defined.
      for (var i = 0; i < keyActions.length; i++) {         
        // See if the next array element contains the Hotkey character
		if (keyActions[i].character == myChar) {       
          // Yes - pick up the action from the table
		  var action;            
          // If the action is a hyperlink, create JavaScript instruction in an anonymous function
          if (keyActions[i].actionType.toLowerCase() == "link") {
            action = new Function ('location.href  ="' + keyActions[i].param + '"');
          }            
          // If the action is JavaScript, embed it in an anonymous function
          else if (keyActions[i].actionType.toLowerCase()  == "code") {
            action = new Function (keyActions[i].param);
          }            
          // Error - unrecognised action.
          else {
            alert ('Hotkey Function Error: Action should be "link" or "code"');
            break;
          }           
          // At last perform the required action from within an anonymous function.
          action ();         
          // Hotkey actioned - exit from the for loop.
          break;
        }
      }
    }
  }
}