function KeyCommandProcessor(keys, onSuccess, onError) {
	this.keys = keys;
	this.onSuccess = onSuccess;
	this.onError = onError;
	this.position = 0;
	
	this.process = function(key) {
		if (this.position < this.keys.length) {
			if (this.keys[this.position] == key) {
				this.position += 1;
				if (this.position == this.keys.length) {
					this.onSuccess();
					this.position = 0;
				}
			}
			else {
				this.position = 0;
				this.onError();
			}
		}
	}
}

// 上、上、下、下、左、右、左、右、b、a
var keys = [38,38,40,40,37,39,37,39,66,65];

function onSuccess() {
	alert('コマンド入力成功！');
	document.getElementById("index").style.background = "#000000";
	document.getElementById("shadow_left").style.background = "#ffff99";
	document.getElementById("shadow_right").style.background = "#ffff99";
}

function onError() {
}

var processor = new KeyCommandProcessor(keys, onSuccess, onError);
// イベントハンドラの作成
function onKeyDown(evt) {
	// IE, Firefox 対応
	var event = evt || window.event;
		
	// Key 処理
	processor.process(event.keyCode);
}
