/**
 * @author	Johannes Donath
 * @copyright	2010 Punksoft
 * @package	net.punksoft.lite.pm
 */

onloadEvents.push(function() { window.setTimeout('PmNotification.checkPms()', 10000); });

var PmNotification = {
    ajaxRequest: new AjaxRequest(),

    checkPms: function() {
	this.ajaxRequest.openGet('index.php?page=UnreadPmMessages'+SID_ARG_2ND, function() { PmNotification.pmCallback(); });
	window.setTimeout('PmNotification.checkPms()', 10000);
    },

    pmCallback: function() {
	if (this.ajaxRequest && this.ajaxRequest.xmlHttpRequest.readyState == 4 && this.ajaxRequest.xmlHttpRequest.status == 200 && this.ajaxRequest.xmlHttpRequest.responseText) {
	    var pmNotification = $('pmNotification');

	    var pmData = eval('(' + this.ajaxRequest.xmlHttpRequest.responseText + ')');

	    if (pmData) {
		pmNotification.innerHTML = "<p class=\"info\">" + pmData + "</div>";
		if (pmNotification.style.display == 'none') {
		    pmNotification.appear();
		} else {
		    Effect.Pulsate('pmNotification');
		}
	    }
	}
    }
}
