// Define variables
var textCommand = "";
var textCommandKey = "";

// Track keypresses
$(document).keydown(function(e) {
    textCommandKey = e.which;
    switch (e.which) {
        case 13:
	    if (textCommand) {
	        runTextCommand(textCommand);
	    	textCommand = "";
	    }
	    break;
        case 37:
	    $('#next-view:not(.toggled)').click();
	    break;
        case 39:
	    $('.toggled').click();
	    break;
	default:
	    textCommand += String.fromCharCode(textCommandKey);
	    break;
    }
});

// Run commands
function runTextCommand(cmd) {
    switch (cmd) {
        case "hi":
	    $.jGrowl("<p>Hello world!</p>");
	    break;
        case "login":
	    $.jGrowl("<p>Want to login, huh? There's nothing here to login to!</p>");
	    break;
	case "aldone":
	    window.location.href = "http://www.aldone.fi/";
	    break;
	case "twitter":
	    window.location.href = "http://www.twitter.com/#!/teppokoivula";
	    break;
	case "blog":
	    window.location.href = "http://www.aldone.fi/blogit/teppo/";
	    break;
	case "linkedin":
	    window.location.href = "http://fi.linkedin.com/in/teppokoivula";
	    break;
	case "facebook":
	    window.location.href = "http://www.facebook.com/teppo.koivula";
	    break;
	default:
	    $.jGrowl("<p>Unknown command <strong>" + cmd + "</strong>. Sorry!</p>");
	    break;
    }
}
