$(document).ready(function(){

	//keep session alive
	function readcontent(){
		var intervalID = setInterval(function () {
		 $.ajax({
				url:'ajax.php?action=keep-session-active',
				type:'post',
				data:'somedata',
				success: function(msg){

					var tmp = msg.split("\n");
					var time = tmp[0];

					tmp[0] = "";

					var notif = tmp.join("\n");


					if ($(".server-time").length > 0){
						$(".server-time").html(time);
					}

					if ($(".notifications").length > 0){

						if (time == "logout"){
							window.location.reload();
						}


						var old = $(".notifications").clone();
						var oldNotifs = 0;
				
						old.find(".notify").each(function() {
							oldNotifs += parseInt($(this).html());
						});

						$(".notifications").html(notif);
						$('.notifications .notify-tooltip').tooltip({
							placement: 'bottom',
							html: 'true'
						});


						//count new notigs
						var newNotifs = 0;
						$(".notifications").find(".notify").each(function() {
							newNotifs += parseInt($(this).html());
						});

						if (newNotifs > oldNotifs){
							$.playSound('assets/sound/notif');
						}
						
					}

				}
			});
		}, 30000);
	}
	readcontent();

	$('.notify-tooltip').tooltip({
        placement: 'bottom',
        html: 'true'
    });


});