
var tottime = 0;
var mydelay = 30;
//versione normal var mydelay = 30;
//versione superLight var mydelay = 60;

var autoClose = false;
(function($){
		$.jheartbeat = {
		options: {
			url: "/", firstdelay: 1000
		},
		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;
			}
			$("body").append("<div id=\"HeartBeatDIV\" style=\"display: none;\"></div>");
			this.timeoutobj.id = setTimeout("$.jheartbeat.beat();", this.options.firstdelay);
		},
		
		beat: function() {
			$("#HeartBeatDIV").load(
				this.options.url,
				function(a,b,c){
					if (b=='success' && a != 'False'){
						if (autoClose == true) {$.jGrowl(a,{ sticky: true,closer: false });}
						else {$.jGrowl(a)}
					}
				}
			);
			
			switch(tottime)
			{
				
				case 300:
					mydelay *= 2;
					break; 
				case 900:
					mydelay *= 3;
					break; 
				case 2700:
					mydelay *= 3;
					autoClose = true;
					break;

			};
			this.timeoutobj.id = setTimeout("$.jheartbeat.beat();", mydelay * 1000);
			this.beatfunction();
			//$("body").prepend("<div id=\"HeartBeat\">dopo "+ tottime +" secondi l\'intervallo &#232; " + mydelay +" sec. "+ Date()+"</div>");
			tottime += mydelay;
		}
		};
})(jQuery);

(function($){
	$(document).ready(function(){
		$.jheartbeat.set({ url: "/en/notifiche/callback/notifiche.asp" }, function () { } );
	});
})(jQuery);
	

