// questo plugin serve per stressare l'utente :D
// l'utente deve inserire i dati per completare il suo profilo
(function($){
	var methods = {
		timeout:5000,
		indervalId:undefined,
		setStressActive:function(active){
			if(active){
				if(typeof this.intervalId!=undefined){ //se non ho gia fatto partire una volta
					this.intervalId=setInterval(this.doStress,this.timeout);
				}
			}else{
				clearInterval(this.intervalId);
				delete this.intervalId;
			}
		},
		setStressTimeout:function(timeout){
			this.timeout=timeout;
		},
		doStress:function(){
			//$.trace("Stressa !");
			$.post("/profile/getconfirmations",function(response){
				if(response.success){// se è loggato
					$.trace(response.data);
					if(response.data.birthday=="0"||response.data.hobbies=="0"||response.data.places=="0"||response.data.introduction=="0"){
						homeClass.showCompleteProfile();
						methods.setStressActive(false);
						//mostra completeprofile
						//spegne stress
						//riattiva eventualmente stress con un altro timeout
					}
				}else{
					//$.trace(response.error);
				}
			},"json");
		}
  		
	};
	
	var stressuser=function(active,timeout){ 
		if(typeof active === "boolean"&&typeof timeout === "number"){      	
			methods.setStressTimeout(timeout);
			methods.setStressActive(active);	    	
	    }else if(typeof active === "boolean" && typeof timeout === "undefined"){
	    	methods.setStressActive(active);
	    }else{
	    	$.trace('Parametri insufficenti o sbagliati : $.stressuser(true/false , timeout seconds)');
	    }  
	};

  $.fn.stressuser=stressuser;
  $.stressuser=stressuser;
  
})(jQuery);


