/*
 * jHeartbeat 0.2.0
 * (C)Alex Richards - http://www.ajtrichards.co.uk/heartbeat
 */
 
 jQuery.jheartbeat = {

    options: {
		url: "heartbeat_default.asp",
		delay: 10000,
		div_id: "test_div",
		timer_id : 0,
		project_name: "1Time",
		tab_only:false
    },
	
	beatfunction:  function(){
	
	},
	
	timeoutobj:  {
		id: -1
	},

    set: function(options, onbeatfunction) {
		if (this.timeoutobj.id > -1) {
			clearTimeout(this.timeoutobj);
		}
        if (options) {
            jQuery.extend(this.options, options);
        }
        if (onbeatfunction) {
            this.beatfunction = onbeatfunction;
        }

		// Add the HeartBeatDIV to the page
		jQuery("body").append("<div id=\"" + this.options.div_id + "\" style=\"display: none;\"></div>");
		this.timeoutobj.id = setTimeout("jQuery.jheartbeat.beat();", this.options.delay);
    },

    beat: function() {
		jQuery.ajax({
				url: "/server_handler.php",
				type: "POST",
				data:{use_common:true, page:this.options.url, timer_id: this.options.timer_id} ,
				error: function(e)   { 
					jQuery('#'+ jQuery.jheartbeat.options.div_id).append("Error Requesting Data"); 
				},
				success: function(data){ 
				
			
					if (data == "0")
						;
					else
					 {
						 
						var temp = jQuery('#'+ jQuery.jheartbeat.options.div_id).html();
						
						jQuery('#' + jQuery.jheartbeat.options.div_id).html("<div>" + data + "</div>"); 
						if (temp != data)
						 {
							if(data != "" || data !="0")
							{
								jQuery(document).attr("title", data + " - " + jQuery.jheartbeat.options.project_name);
								//jQuery('#'+ jQuery.jheartbeat.options.div_id).vkfade("ff0000");
							}
						 }
					 }
				
				}
			   });
		this.timeoutobj.id = setTimeout("jQuery.jheartbeat.beat();", this.options.delay);
        this.beatfunction();
    }
};
