/*
 * lastseenusers 0.3.0
 * (C)Alex Richards - http://www.ajtrichards.co.uk/
 */

/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2011 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: jquery.kmo.js
| Title: Ki mit olvas?
| CVS Version: 1.00
| Author: Mathias
| Web: http://www.bltfm.hu/
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/

 $.kmo = {

    options: {
		url: "heartbeat_default.asp",
		delay: 10000,
		div_id: "test_div"
    },
	
	beatfunction:  function(){
	
	},
	
	timeoutobj:  {
		id: -1
	},

    set: function(options, onbeatfunction) {
		if (this.timeoutobj.id > -1) {
			clearTimeout(this.timeoutobj);
		}
        if (options) {
            $.extend(this.options, options);
        }
        if (onbeatfunction) {
            this.beatfunction = onbeatfunction;
        }

		// Add the HeartBeatDIV to the page
		$("body").append("<div id=\"" + this.options.div_id + "\" style=\"display: none;\"></div>");
		this.timeoutobj.id = setTimeout("$.kmo.beat();", this.options.delay);
    },

    beat: function() {
		$.ajax({
				url: this.options.url + '?time=' + (new Date().getTime()),
				dataType: "html",
				type: "GET",
				error: function(e)   { 
					$('#'+ $.kmo.options.div_id).append("Error Requesting Data"); 
				},
				success: function(data){ 
					$('#'+ $.kmo.options.div_id).html(""); 
					$('#'+ $.kmo.options.div_id).html(data); 
				}
			   });
		this.timeoutobj.id = setTimeout("$.kmo.beat();", this.options.delay);
        this.beatfunction();
    }
};
