//
// Konami_Mootools Class 1.0
//
// http://www.schlaeps.com/libraries/konomi_mootools/
//
// Written by Jonathan Schlaepfer
//
// new Konami(codeCalledFunction [, codeStepFunction [, codeMessedUpFunction]])
//
/*




<script type="text/javascript" src="konami_mootools.js"></script>
<script type="text/javascript">
        konami = new Konami(function(){
                // Do your Konomi code JS here.
                alert('KONOMI!');
        });
</script>


codeCalledFunction()
Required
A required function that will be called when the Konami code has been successfully completed.

codeStepFunction(step)
Optional
An optional function that will be called when a step of the Konami code is successfully completed.

codeMessedUpFunction
Optional
An optional function that will be called when the user messes up the code. 

*/

var Konami = new Class({

	code: ["up","up","down","down","left","right","left","right","b","a","enter"],
	step: 0,

	initialize: function(func1,func2,func3){
		if($defined(func2))
			this.func2 = func2;
		if($defined(func3))
			this.func3 = func3;
		this.func = func1;
		window.addEvent('keyup',this.keystroke.bind(this));
	},
    
	keystroke: function(e){
		ev = new Event(e);
    	
		if(ev.key == this.code[this.step]){
			if($defined(this.func2))
				this.func2.attempt(this.step);
			this.step++;
			if(this.step == this.code.length){
				this.step = 0;
				this.func.attempt();
			}
		} else {
			this.step = 0;
			if($defined(this.func3))
				this.func3.attempt();
		}
	}
    
});
