﻿var KEY_ARROW_LEFT = 37;
var KEY_ARROW_UP = 38;
var KEY_ARROW_RIGHT = 39;
var KEY_ARROW_DOWN = 40;
var LastKeyPressed = 0;
function processKey(pKeyCode) {
    try {
        if (pKeyCode == KEY_ARROW_LEFT) {
            var Position = Number(_cuPlayerGetCurrentPosition());
            Position = parseInt(Position) - 30;
            if (Position < 0) Position = 0;
            _cuPlayerSetCurrentPosition(Position);
            LastKeyPressed = KEY_ARROW_LEFT;
        }

        if (pKeyCode == KEY_ARROW_UP) {
            var Volume = _cuVolVar;
            Volume = parseInt(Volume) + 1;
            if (Volume < 0) Volume = 0;
            if (Volume > 100) Volume = 100;

            _cuPlayerSetVolume(Volume)
            LastKeyPressed = KEY_ARROW_UP;
        }

        if (pKeyCode == KEY_ARROW_RIGHT) {
            var Position = Number(_cuPlayerGetCurrentPosition());
            Position = parseInt(Position) + 30;
            if (Position > _cuPlayerGetCurrentDuration()) Position = _cuPlayerGetCurrentDuration();
            _cuPlayerSetCurrentPosition(Position);
            LastKeyPressed = KEY_ARROW_RIGHT;
        }

        if (pKeyCode == KEY_ARROW_DOWN) {
            var Volume = _cuVolVar;
            Volume = parseInt(Volume) - 1;
            if (Volume < 0) Volume = 0;
            if (Volume > 100) Volume = 100;

            _cuPlayerSetVolume(Volume);
            LastKeyPressed = KEY_ARROW_DOWN;
        }
    } catch (e) { }
}
function unProcessKey() {
    if (LastKeyPressed == KEY_ARROW_LEFT) {
        _cuPlayerPlay()
        LastKeyPressed = 0;
    }
    if (LastKeyPressed == KEY_ARROW_RIGHT) {
        _cuPlayerPlay()
        LastKeyPressed = 0;
    }
    if (LastKeyPressed == KEY_ARROW_UP || LastKeyPressed == KEY_ARROW_DOWN) {
        LastKeyPressed = 0;
    }
}
function checkkeys(e) {
    try { processKey(e.keyCode); } catch (ex) { }
    try { processKey(event.keyCode); } catch (ex) { }
}
document.onkeydown = checkkeys;
function setFocus() {
    self.focus();
}
function addOnloadEvent(newOnloadEvent) {
    if (typeof window.addEventListener != "undefined") {
        window.addEventListener("load", newOnloadEvent, false)
    } else {
        if (typeof document.addEventListener != "undefined") {
            document.addEventListener("load", newOnloadEvent, false)
        } else {
            if (typeof window.attachEvent != "undefined") {
                window.attachEvent("onload", newOnloadEvent)
            } else {
                if (typeof window.onload == "function") {
                    var prevOnload = onload; window.onload = function() { prevOnload(); newOnloadEvent() }
                }
                else {
                    window.onload = newOnloadEvent
                }
            }
        }
    }
};
addOnloadEvent(setFocus);
