 +  ws=new WebSocket(rfidhuburl);
 +  window.onblur = function() {
 +    windowInFocus = false;
-+    ws.close();
++    clearTimeout(timer);
++    timer = setTimeout(function() {
++      if (isConnected && !windowInFocus) {
++        ws.close();
++      }
++    }, TIMEOUT);
 +  }
 +  branch = document.getElementById("logged-in-branch-code") ? document.getElementById("logged-in-branch-code").innerHTML : "ukjent";
 +  state = $("body").attr("id");

+  $("div.gradient").append('<div id="RFIDStatus"><a class="btn btn-small" onclick="location.reload();">RFID</a><span id="RFIDStatusMessage"></span><button id="RFIDPreg" onclick="activateWrite(ws);">Preg brikker</button></div>');
+  ws.onopen = function() {
+    console.log("connected");
+
+    $('#RFIDStatus .btn').css("backgroundColor", "green");
+

+ * creates <div> with <table>
+ * inserts table to #patronlists and adds highlighted items as they arrive from websocket
+ */
+
+var windowInFocus = true;
+var wasOnceConnected = false;
+var isConnected = false;
+var TIMEOUT = 10000; // 10s
+var timer;
+
+$(document).ready(function() {
+  connect();
+
+  window.onfocus = function() {
+    windowInFocus = true;
+    if (!isConnected && wasOnceConnected) {
+      connect();
+    }
+  }
