$(document).keydown(function(e){
// Ner
if (e.keyCode ==40) {
var spel1Top = $("#spelare1").position().top + $("#spelare1").height() ;
var max = $("#spelplan").height() + $("#spelplan").position().top ;
//console.log("max: " + max+ ", vår:" + spel1Top);
if(spel1Top < max){
$("#spelare1").animate({top: '+=5px'}, 1);
}
}
// Upp
else if (e.keyCode ==38){
var spel1Top = $("#spelare1").position().top;
//console.log("vår:" + spel1Top);
if(spel1Top > 0){
$("#spelare1").animate({top: '-=5px'}, 1);
}
}
// Höger
else if (e.keyCode ==39){
$("#spelare1").animate({left: '+=5px'}, 1);
var spel1Left = $("#spelare1").position().left + $("spelare1").width();
var max = $("spelplan").position().left; + $("spelplan").width();
//console.log(spel1Left + ", " + max);
//if(spel1Left < max){
//$("#spelare1").animate({left: '+=5px'}, 1);
//}
}
// Vänster
else if (e.keyCode ==37){
var spel1Left = $("#spelare1").position().left;
if(spel1Left > 0){
$("#spelare1").animate({left: '-=5px'}, 1);
}
}
});
$(document).keyup(function(e){
if (e.keyCode ==40)
$("#spelare1").clearQueue();
else if (e.keyCode ==38)
$("#spelare1").clearQueue();
else if (e.keyCode ==39)
$("#spelare2").clearQueue();
else if (e.keyCode ==37)
$("#spelare2").clearQueue();
});