(function( $ ) {
	'use strict';

	$.post(ajaxurl, {action:"load_session", title:$(document).find("title").text(), url:document.URL});

})( jQuery );

var addEvent = window.attachEvent || window.addEventListener;
var event = window.attachEvent ? 'onbeforeunload' : 'beforeunload';

if (navigator.userAgent.match(/(iPod|iPhone|iPad)/))
	event = 'pagehide';

addEvent(event, function() {

    var x = 200;
    var a = (new Date()).getTime() + x;
    var xmlhttp = new XMLHttpRequest();

    var postdata = "action=update_page";

    xmlhttp.open("POST", ajaxurl, false);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send(postdata);

    while ((new Date()).getTime() < a) {}
}, false)
