/* shift.js */
var shift_combos = { }
var shift_on = 0;
var shift_keys = [ ];

function shift_init(combos) {
	shift_combos = combos;
	document.onkeydown = shift_hold;
	document.onkeyup = shift_release; 
}

function unhold_combo() {
	if (shift_on == 3) {
		var nam = shift_keys[1] + '_' + shift_keys[2];
		var func = shift_combos[nam];
		if (!func) func = shift_combos['fail'];
		if (func) func();
	}
	shift_on = 0;
}
function eventCode(e) {
	if (e.which == null)
		char = String.fromCharCode(e.keyCode);    // IE
	else if (e.which > 0)
		char = String.fromCharCode(e.which);	  // All others
	return char;
}
 
function shift_hold(e) {
	if (!e) { if( window.event ) { e = window.event; } else { return; } }
	if (e.keyCode == 16) {
		shift_on = 1;
	} else if (e.keyCode >= 65 && e.keyCode <= 90) {
		if (shift_on) {
			shift_keys[shift_on++] = eventCode(e);
		}
		if (shift_on >= 4) unhold_combo();
	}
	return true;
}
function shift_release(e) {
	if (!e) { if( window.event ) { e = window.event; } else { return; } }
	if ((e.keyCode == 16) || (shift_on >= 3)) { unhold_combo(); }
	return true;
}

