function lpWaitTimeNotifier(server, siteid, skill, refreshrate, callback) {

    //if not enough details, we're done
	if(server == null || server == '' || siteid == null || siteid == '' || skill == null || skill == '' || callback == null || refreshrate<0) 
	    return;
	    
	//if refresh rate is defined, it should be at least 30 secs
	if(refreshrate>0 && refreshrate<30) refreshrate = 30;    
	            
    this._LP_SERVICE_UP = 0;
    this._LP_SERVICE_UNAVAILABLE = -1;
    this._LP_REPS_UNAVAILABLE = -2;
    this._lpCountUnavailable = 0;
    this._lpStopPolling = false;
    this._currentImageWidth = -1;
    this._currentImageHeight = -1;
    this._lpProtocol = (document.location.toString().indexOf("https:")==0) ? "https" : "http";
    this._lpNumber = siteid;
    this._lpServer = server;
    this._lpWaitQueueSkill = skill;
    this._lpRefresh = refreshrate * 1000; // convert to millisecs;
    this._waitCallback = callback;
    this._imgid = "lpstatusimg" + new Date().getTime();
 }   

lpWaitTimeNotifier.prototype.lpRegisterWaitListener = function(){
        //get first read
        this._lpCheckFindQueueStats();
    };
    
 lpWaitTimeNotifier.prototype._lpCheckFindQueueStats = function () {

            //create the tracking image
            if(document.getElementById("lpstatusimg") != null){
                document.getElementsByTagName("body")[0].removeChild(document.getElementById("lpstatusimg"));
            }
            lpFindQueueStatsImage = new Image();
            lpFindQueueStatsImage = document.createElement('IMG');
            lpFindQueueStatsImage.style.visibility = "hidden";
            lpFindQueueStatsImage.id = this._imgid;
            document.getElementsByTagName("body")[0].appendChild(lpFindQueueStatsImage);

            lpFindQueueStatsImage.src = this._lpProtocol + "://" + this._lpServer + "/hc/" + this._lpNumber + "/?cmd=queueStats" +
                "&channel=web&site=" + this._lpNumber + "&skill=" + escape(this._lpWaitQueueSkill) + "&d=" + new Date().getTime();

           this._lpFindQueueStatsLoopImage();
};
    
lpWaitTimeNotifier.prototype._lpFindQueueStatsCheckImage = function() {
	   
	    try{
	        var imageWidth = lpFindQueueStatsImage.width;
	        var imageHeight = lpFindQueueStatsImage.height;
	        if (imageWidth == 30 || imageWidth == 31) {
	            this._lpCountUnavailable += 1;
	            if (this._lpCountUnavailable == 5)
	                this._lpStopPolling = true;
                this._lpNotifyVisitorQueueStats(0, 0, this._LP_SERVICE_UNAVAILABLE);
		        return true;
	        } else
	        if (imageWidth == 32) {
                this._lpNotifyVisitorQueueStats(0, 0, this._LP_REPS_UNAVAILABLE);
		        return true;
	        }
	        if (imageWidth >= 40) {
	            _lpCountUnavailable = 0;
                this._lpNotifyVisitorQueueStats(imageWidth - 40, imageHeight, this._LP_SERVICE_UP);
		        return true;
	        }
	       
	        return false;
        }
	    catch(e){
	        return false;
	    }
};

lpWaitTimeNotifier.prototype._lpFindQueueStatsLoopImage = function() {

        var me = this;  
        
        //try to check image width
        if (this._lpFindQueueStatsCheckImage()) {
    		
    		//if we have refresh rate
    		if(this._lpRefresh > 0){
	            setTimeout(function(){me._lpCheckFindQueueStats;}, this._lpRefresh);
	         }
        } 
        else{
	        this._lpCountUnavailable += 1;
    		
	        //more than 5 time without valid width, we're done
	        if (this._lpCountUnavailable == 5)
                    return;
    	    
            this._waitCallback(0,0, this._LP_SERVICE_UNAVAILABLE);     
             
	        setTimeout(function(){me._lpFindQueueStatsLoopImage();}, 1000);
        }	
};


lpWaitTimeNotifier.prototype._lpNotifyVisitorQueueStats = function(imageWidth, imageHeight, status) {
	    
	    if (this._currentImageWidth != imageWidth || this._currentImageHeight != imageHeight){
			    this._currentImageWidth = imageWidth;
			    this._currentImageHeight = imageHeight;
			    
			    //notify the subscriber
			    this._waitCallback(Math.max(30, imageWidth), imageHeight, status);
			    
		    }
};
		
lpWaitTimeNotifier.prototype.init = function (){
			
			var me = this;
			//Check wait time only once the page loads    
			if (window.attachEvent) window.attachEvent('onload',function(){me.lpRegisterWaitListener();});
			else window.addEventListener("load",function(){me.lpRegisterWaitListener();},false);
		
		
};