    var prisnum = 0;
    var fullMsg;
    
    // ticker() variables
    var widgetOne = "_";
    var widgetTwo = "-";
    var widgetNone = "";
    var leadString = "&nbsp;";
    var t;
    

    function startTicker(){ 
        
        currentLength = 0;
    
        if (document.getElementById) {
          // 'ticker' is the id of the element (in this case a DIV) that will contain the ticker text.
          anchorObject = document.getElementById('ticker');
          runTheTicker(); // do it baby
        }
        else {
          //alert('lame');
          //document.write("<style>#ticker{display:none;}");
          return true;
        }
    }
    
    function runTheTicker(){
    
        if(currentLength == 0){
          prefix = "<span class=\"tickerls\">" + leadString + "</span>";
        }
    
        // WITH a PREFIX: 
        //anchorObject.innerHTML = prefix + fullMsg.substring(0,currentLength) + whatWidget();
        
        anchorObject.innerHTML = fullMsg.substring(0,currentLength) + whatWidget();
        currentLength++;
    
        t = setTimeout("tickSanely()", 100);
    }
    
    function tickSanely(){
        if (currentLength == fullMsg.length) {
          clearTimeout(t)
        } else {
          runTheTicker()
        }
    }
    
    
    // Widget generator
    function whatWidget(){
        if(currentLength == fullMsg.length) {
          return widgetNone;
        }
        if((currentLength % 2) == 1){
          return widgetOne;
        }
        else{
          return widgetTwo;
        }
    }

function latest_message(){
	
	jQuery.ajax({
               url: '/msg/latest.pl',
               type: 'POST',
               data: "pn=" + prisnum,
               dataType: 'html',
               error: function(){
                 //alert("Error loading the latest message.");
               },
               
               success: function(html){
                  dat = html.split('|');
                  newMsg = dat[0];
                  prisnum = dat[1];
                  var msg = ' ' + dat[2] + ' ';         
                  var user = ' ' + dat[3] + ' ';
         
                  var age = ' ';
                  if (dat[4]) age = dat[4];         
                  var userFrom = ' ';
                  if (dat[5]) userFrom = dat[5];
                  
                  fullMsg = "<strong>Latest messages:</strong>" + " Prisoner number " + prisnum + " says: " + msg + "  ++++----++++  " + user + age + userFrom;

                  if (newMsg === 'true'){
                     // Delay the ticker slightly to let the page get a headstart loading. 
                     // The delay seems to make the ticker run more smoothly. Season to taste.\
                     //startit = setTimeout(" startTicker()", 1000);
                     startTicker()
                  }           
               }
            });
            lm = setTimeout("latest_message()", 60000);
}


jQuery(document).ready(function() {
    latest_message();
});

