refreshQueueStatus = function()
        { 
            jQuery.getJSON("/Queue/GetQueueStatus",
            function(json)
            {
                loading= jQuery("#QueueStatusDisplay #divLoadingQueueStatus");
                contents = jQuery("#QueueStatusDisplay #divContentsQueueStatus")

                // Abort if there is no QueueStatus list on the page to update.
                if (contents.length==0)
                {
                    return;
                }

                //loading.fadeIn(1000);
                //contents.fadeOut(1000);
                
                // If no response was given, ask again in two seconds!
                if (json == "")
                {
                    setTimeout(refreshQueueStatus, 2*1000);
                    return;
                }                
                
                loading.fadeOut(1000);

                while (contents[0].childNodes[0]) {
                    contents[0].removeChild(contents[0].childNodes[0]);
                }

                var table1=document.createElement("table");
                table1.id="QueueStatus";
                table1.setAttribute("className","QueueStatus");
                                
                var table1body = document.createElement("tbody");
                table1.appendChild(table1body);
                                
                jQuery.each(json, function(i, item)
                {
                    
                    tmpRow=document.createElement("tr");
                    table1body.appendChild(tmpRow);

                    tmpCell = document.createElement("td");
                    tmpRow.appendChild(tmpCell);

                    tmpCell.appendChild( document.createTextNode ( item.QueueName + " (" + item.Count + ")" ));
                });

                contents[0].appendChild(table1);
                
                jQuery(contents).fadeIn(1000);
                
                // Success! The queue status change all the time; we refresh every half second.
                setTimeout(refreshQueueStatus, 500);
            });         
        }
jQuery("QueueStatusDisplay").ready( refreshQueueStatus )
