/**
* @author Peter Rekdal Sunde <peters@vg.no>
*
* Determines what specialkeys that is available upon runtime
* for a specific browser for these events: Keypress, Keydown and Keyup.
* 
* @todo: Older versions of Safari reports keyCodes in a wierd range. This should
* be directly implemented into Event {} and re-organize the Specialkey properties accordingly.
*
* Based on http://www.quirksmode.org/js/key...
*/ 
var Specialkey = {
    Keypress: {
        IE: {
             Alt: this.Undefined,
             Backspace: this.Undefined,
             CapsLock: this.Undefined,
             Cmd: this.Undefined,
             Ctrl: this.Undefined,
             Delete: this.Undefined,
             Enter: 13,
             Help: this.Undefined,
             Home: this.Undefined,
             Insert: this.Undefined,
             NumLock: this.Undefined,
             PageUp:  this.Undefined,
             PageDown: this.Undefined,
             Shift: this.Undefined,
             Tab: this.Undefined,
             Escape: 27,
             WindowsStart: this.Undefined,
             End: this.Undefined,
             Space: 32,
             F1: this.Undefined,
             F2: this.Undefined,
             F3: this.Undefined,
             F4: this.Undefined,
             F5: this.Undefined,
             F6: this.Undefined,
             F7: this.Undefined,
             F8: this.Undefined,
             F9: this.Undefined,
             F10: this.Undefined,
             F11: this.Undefined,
             F12: this.Undefined,
             ArrowLeft: this.Undefined,
             ArrowRight: this.Undefined,
             ArrowDown: this.Undefined,
             ArrowUp: this.Undefined
        },
        WebKit: {
             Alt: this.Undefined,
             Backspace: 8,
             CapsLock: this.Undefined,
             Cmd: 91,
             Ctrl: this.Undefined,
             Delete: this.Undefined,
             Enter: 13,
             Help: this.Undefined,
             Home: this.Undefined,
             Insert: this.Undefined,
             NumLock: this.Undefined,
             PageUp:  this.Undefined,
             PageDown: this.Undefined,
             Shift: this.Undefined,
             Tab: this.Undefined,
             Escape: this.Undefined,
             WindowsStart: this.Undefined,
             End: this.Undefined,
             Space: 32,
             F1: this.Undefined,
             F2: this.Undefined,
             F3: this.Undefined,
             F4: this.Undefined,
             F5: this.Undefined,
             F6: this.Undefined,
             F7: this.Undefined,
             F8: this.Undefined,
             F9: this.Undefined,
             F10: this.Undefined,
             F11: this.Undefined,
             F12: this.Undefined,
             ArrowLeft: this.Undefined,
             ArrowRight: this.Undefined,
             ArrowDown: this.Undefined,
             ArrowUp: this.Undefined
        },
        Opera: {
             Alt: this.Undefined,
             Backspace: 8,
             CapsLock: this.Undefined,
             Cmd: this.Undefined,
             Ctrl: 17,
             Delete: 46,
             Enter: 13,
             Help: this.Undefined,
             Home: 36,
             Insert: 45,
             NumLock: 144,
             PageUp:  33,
             PageDown: 34,
             Shift: 16,
             Tab: 9,
             Escape: 27,
             WindowsStart: this.Undefined,
             Space: this.Undefined,
             F1: 112,
             F2: this.Undefined,
             F3: this.Undefined,
             F4: this.Undefined,
             F5: this.Undefined,
             F6: 116,
             F7: 11818,
             F8: 119,
             F9: 120,
             F10: 121,
             F11: 122,
             F12: 123,
             ArrowLeft: 37,
             ArrowRight: 39,
             ArrowDown: 40,
             ArrowUp: 38
        },
        Gecko: {
             Alt: this.Undefined,
             Backspace: 8,
             CapsLock: this.Undefined,
             Cmd: this.Undefined,
             Ctrl: this.Undefined,
             Delete: 46,
             Enter: 13,
             Help: this.Undefined,
             Home: 36,
             Insert: 45,
             NumLock: this.Undefined,
             PageUp: 33,
             PageDown: 34,
             Shift: this.Undefined,
             Tab: 9,
             Escape: 27,
             WindowsStart: 91,
             End: 35,
             F1: 112,
             F2: 113,
             F3: 114,
             F4: 115,
             F5: 116,
             F6: 117,
             F7: 118,
             F8: 119,
             F9: 120,
             F10: 121,
             F11: 122,
             F12: 123,
             ArrowLeft: 37,
             ArrowRight: 39,
             ArrowDown: 40,
             ArrowUp: 38
        }
    },
    Keydown: {
        IE: {
             Alt: 18,
             Backspace: 8,
             CapsLock: 20,
             Cmd: this.Undefined,
             Ctrl: 17,
             Delete: 46,
             Enter: 13,
             Help: this.Undefined,
             Home: 36,
             Insert: 45,
             NumLock: 144,
             PageUp: 33,
             PageDown: 34,
             Shift: 16,
             Tab: 9,
             Escape: 27,
             WindowsStart: 91,
             End: 35,
             Space: 32,
             F1: 112,
             F2: 113,
             F3: 114,
             F4: 115,
             F5: 116,
             F6: 117,
             F7: 118,
             F8: 119,
             F9: 120,
             F10: 121,
             F11: 122,
             F12: 123,
             ArrowLeft: 37,
             ArrowRight: 39,
             ArrowDown: 40,
             ArrowUp: 38
        },
        WebKit: {
             Alt: 18,
             Backspace: 8,
             CapsLock: 20,
             Cmd: 91,
             Ctrl: 17,
             Delete: 46,
             Enter: 13,
             Help: this.Undefined,
             Home: 36,
             Insert: 45,
             NumLock: 144,
             PageUp:  33,
             PageDown: 34,
             Shift: 16,
             Tab: 9,
             Escape: 27,
             WindowsStart: 91,
             End: 35,
             Space: 32, 
             F1: 112,
             F2: 113,
             F3: 114,
             F4: 115,
             F5: 116,
             F6: 117,
             F7: 118,
             F8: 119,
             F9: 120,
             F10: 121,
             F11: 122,
             F12: 123,
             ArrowLeft: 37,
             ArrowRight: 39,
             ArrowDown: 40,
             ArrowUp: 38
        },
        Opera: {
             Alt: this.Undefined,
             Backspace: 8,
             CapsLock: 20,
             Cmd: this.Undefined,
             Ctrl: 17,
             Delete: 46,
             Enter: 13,
             Help: this.Undefined,
             Home: 36,
             Insert: 45,
             NumLock: 144,
             PageUp:  33,
             PageDown: 34,
             Shift: 16,
             Tab: 9,
             Escape: 27,
             WindowsStart: 91,
             End: 35,
             F1: this.Undefined,
             F2: this.Undefined,
             F3: this.Undefined,
             F4: this.Undefined,
             F5: this.Undefined,
             F6: 117,
             F7: 118,
             F8: 119,
             F9: 120,
             F10: 121,
             F11: 122,
             F12: 123,
             ArrowLeft: 37,
             ArrowRight: 39,
             ArrowDown: 40,
             ArrowUp: 38
        },
        Gecko: {
             Alt: 18,
             Backspace: 8,
             CapsLock: 9,
             Cmd: this.Undefined,
             Ctrl: 17,
             Delete: 46,
             Enter: 13,
             Help: this.Undefined,
             Home: 36,
             Insert: 45,
             NumLock: 144,
             PageUp: 36,
             PageDown: 34,
             Shift: 16,
             Tab: 9,
             Escape: 27,
             WindowsStart: 91,
             End: 35,
             F1: 112,
             F2: 113,
             F3: 114,
             F4: 115,
             F5: 116,
             F6: 117,
             F7: 118,
             F8: 119,
             F9: 120,
             F10: 121,
             F11: 122,
             F12: 123,
             ArrowLeft: 37,
             ArrowRight: 39,
             ArrowDown: 40,
             ArrowUp: 38
        }
    },
    Keyup: {
        IE: {
             Alt: 18,
             Backspace: 8,
             CapsLock: 20,
             Cmd: this.Undefined,
             Ctrl: 16,
             Delete: 46,
             Enter: 13,
             Help: this.Undefined,
             Home: 36,
             Insert: 45,
             NumLock: 144,
             PageUp:  33,
             PageDown: 34,
             Shift: 16,
             Tab: 9,
             Escape: 27,
             WindowsStart: 91,
             End: 35,
             F1: 112,
             F2: 113,
             F3: this.Undefined,
             F4: this.Undefined,
             F5: this.Undefined,
             F6: this.Undefined,
             F7: 118,
             F8: 119,
             F9: 120,
             F10: 121,
             F11: 122,
             F12: 123,
             ArrowLeft: 37,
             ArrowRight: 39,
             ArrowDown: 40,
             ArrowUp: 38
        },
        WebKit: {
             Alt: 18,
             Backspace: 8,
             CapsLock: 20,
             Cmd: 91,
             Ctrl: 17,
             Delete: 46,
             Enter: 13,
             Help: this.Undefined,
             Home: 36,
             Insert: 45,
             NumLock: 45,
             PageUp:  33,
             PageDown: 34,
             Shift: 16,
             Tab: 9,
             Escape: 27,
             WindowsStart: 91,
             End: 35,
             F1: this.Undefined,
             F2: 113,
             F3: this.Undefined,
             F4: 115,
             F5: 116,
             F6: 117,
             F7: 118,
             F8: 119,
             F9: 120,
             F10: 121,
             F11: 122,
             F12: 123,
             ArrowLeft: 37,
             ArrowRight: 39,
             ArrowDown: 40,
             ArrowUp: 38
        },
        Opera: {
             Alt: this.Undefined,
             Backspace: 8,
             CapsLock: 20,
             Cmd: this.Undefined,
             Ctrl: 17,
             Delete: 46,
             Enter: 13,
             Help: this.Undefined,
             Home: 36,
             Insert: 45,
             NumLock: 144,
             PageUp: 33,
             PageDown: 34,
             Shift: 16,
             Tab: 9,
             Escape: 27,
             WindowsStart: 91,
             End: 35,
             F1: this.Undefined,
             F2: this.Undefined,
             F3: this.Undefined,
             F4: this.Undefined,
             F5: this.Undefined,
             F6: 117,
             F7: this.Undefined,
             F8: this.Undefined,
             F9: 120,
             F10: 121,
             F11: 122,
             F12: this.Undefined,
             ArrowLeft: 37,
             ArrowRight: 39,
             ArrowDown: 40,
             ArrowUp: 38
        },
        Gecko: {
             Alt: 18,
             Backspace: 8,
             CapsLock: 20,
             Cmd: this.Undefined,
             Ctrl: 17,
             Delete: 46,
             Enter: 13,
             Help: this.Undefined,
             Home: 36,
             Insert: 45,
             NumLock: 144, 
             PageUp:  33,
             PageDown: 34,
             Shift: 16,
             Tab: 9,
             Escape: 27,
             WindowsStart: 91,
             End: 35,
             F1: 112,
             F2: 113,
             F3: 114,
             F4: 115,
             F5: 116,
             F6: 117,
             F7: 118,
             F8: 119,
             F9: 120,
             F10: 121,
             F11: 122,
             F12: 123,
             ArrowLeft: 37,
             ArrowRight: 39,
             ArrowDown: 40,
             ArrowUp: 38
        }
    },
    Undefined: null
};

/**
* @author Peter Rekdal Sunde <peters@vg.no>
*  
* Extend Keypress, Keydown and Keyup to the Event object.
* 
*/
Object.extend(Event, {
    Keypress: Specialkey.Undefined,
    Keydown: Specialkey.Undefined,
    Keyup: Specialkey.Undefined
})

if(Prototype.Browser.Gecko) {
    Event.Keypress = Specialkey.Keypress.Gecko;
    Event.Keydown = Specialkey.Keydown.Gecko;
    Event.Keyup = Specialkey.Keyup.Gecko;
} else if(Prototype.Browser.IE) {
    Event.Keypress = Specialkey.Keypress.IE;
    Event.Keydown = Specialkey.Keydown.IE;
    Event.Keyup = Specialkey.Keyup.IE;
} else if(Prototype.Browser.Opera) {
    Event.Keypress = Specialkey.Keypress.Opera;
    Event.Keydown = Specialkey.Keydown.Opera;
    Event.Keyup = Specialkey.Keyup.Opera;
} else if(Prototype.Browser.WebKit) {
    Event.Keypress = Specialkey.Keypress.WebKit;
    Event.Keydown = Specialkey.Keydown.WebKit;
    Event.Keyup = Specialkey.Keyup.WebKit;
}
