window.Away = { "UnseenMsgCounter": 0, "OrigTitle": "", "HasFocus": true, "UpdateFrequency": 3000, "onFocus": function() { Away.HasFocus = true; Away.UnseenMsgCounter = 0; // Courtesy http://stackoverflow.com/questions/2952384/changing-the-window-title-when-focussing-the-window-doesnt-work-in-chrome window.setTimeout(function () { $('title').text(Away.OrigTitle); }, 100); }, "onBlur": function() { Away.HasFocus = false; }, "updateTitle": function () { if (Away.UnseenMsgCounter > 0) { var plural = Away.UnseenMsgCounter > 1 ? 's' : ''; $('title').text(Away.UnseenMsgCounter + ' new dump' + plural + '! | ' + Away.OrigTitle); } setTimeout(Away.updateTitle, Away.UpdateFrequency); }, "startTitleUpdater": function() { Away.OrigTitle = $('title').text(); $(window).blur(Away.onBlur); $(window).focus(Away.onFocus); setTimeout(Away.updateTitle, Away.UpdateFrequency); } };