// requires jquery.ba-dotimeout.min.js
$(document).ready(function() {
   $('body').keydown( function( event ) {
      if( event.target.nodeName == 'TEXTAREA' || event.target.nodeName == 'INPUT' )
         return; // we simply want to type in textarea, nothing else!
      var code = ( event.keyCode ? event.keyCode : ( event.charCode ? event.charCode : -1 ) ); // Work around bug in event.which
      if( code == 39 ) { // key right
         $.doTimeout( 'content_loading', 750, function() { $('#Content').html( '<div class="content_loading">&nbsp;</div>' ); } );
      } else if( code == 37 ) { // key left
         $.doTimeout( 'content_loading', 750, function() { $('#Content').html( '<div class="content_loading">&nbsp;</div>' ); } );
      } else if( code == 13 ) { // enter
         // alert( 'show answer please! (or mark as correct please)' )
      } else if( code == 32 ) { // space
         //alert( 'mark as incorrect please!' )
      //} else if( code == 27 ) { // escape not used anymore, closes popups!
         //alert( 'return to reading mode please!' )
      } else {
         return true
      }

      if(code == 37) {
   	   jQuery.ajax({
   		   url: '/previousLektion',
   		   success: function(data){
   			   window.location = data;
   		   }
   		 });
      }else if(code == 39){
   	   jQuery.ajax({
   		   url: '/nextLektion',
   		   success: function(data){
   			   window.location = data;
   		   }
   		 });
      }        	   
      /*jQuery.ajax({
         type:'POST',
         timeout: 5000,
         data:'key='+code,
         url:'/modul/handleKey'
      });*/
      /*
      if( event.preventDefault ) {
          event.preventDefault();
      }
      */
      //alert( code );
   });
});

