Index: trunk/FACT++/www/index.js
===================================================================
--- trunk/FACT++/www/index.js	(revision 13565)
+++ trunk/FACT++/www/index.js	(revision 13567)
@@ -34,4 +34,11 @@
 function onload()
 {
+    try { xmlHttp = new XMLHttpRequest(); }
+    catch(e)
+    {
+        alert("Your browser doesn't support dynamic reload.");
+        return;
+    }
+
     /*
      alert("0 -- "+navigator.appCodeName+"\n"+
@@ -52,37 +59,24 @@
 function loadPage(name, z)
 {
-    var xmlHttp = null;
-
-    try { xmlHttp = new XMLHttpRequest(); }
-    catch(e)
-    {
-        alert("Your browser doesn't support dynamic reload.");
-        return;
-    }
-
+    var xmlHttp = new XMLHttpRequest();
     xmlHttp.open('POST', name+'.table', true);
-
-    xmlHttp.onreadystatechange =
-        function ()
-        {
-            if (xmlHttp.readyState == 4)
-            {
-                if (xmlHttp.status!=0 && xmlHttp.status!=200)
-                {
-                    alert("ERROR[0] - HTTP request '"+name+".table': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
-                    //setTimeout("loadPage('+name+')", 5000);
-                    /****** invalidate ******/
-                    return;
-                }
-
-                buildPage(name, xmlHttp.responseText, (z+1)%2);
-                changePage(z);
-
-                //changePage(name, xmlHttp.resposeText);
-                //slideOut(name, xmlHttp.responseText);
-                //displayPage(name, xmlHttp.responseText);
-                //onresize(true);
-            }
-        };
+    xmlHttp.onload = function ()
+    {
+        if (xmlHttp.status!=200)
+        {
+            alert("ERROR[0] - HTTP request '"+name+".table': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
+            //setTimeout("loadPage('+name+')", 5000);
+            /****** invalidate ******/
+            return;
+        }
+
+        buildPage(name, xmlHttp.responseText, (z+1)%2);
+        changePage(z);
+
+        //changePage(name, xmlHttp.resposeText);
+        //slideOut(name, xmlHttp.responseText);
+        //displayPage(name, xmlHttp.responseText);
+            //onresize(true);
+    };
 
     xmlHttp.send(null);
@@ -136,6 +130,36 @@
         }
 
-        if (cols[1].substring(0, 7)=="canvas=")
-        {
+        /*
+         <span class="ui-icon ui-icon-arrow-r ui-icon-shadow">
+    -webkit-box-shadow: rgba(255, 255, 255, 0.398438) 0px 1px 0px 0px;
+background-attachment: scroll;
+background-clip: border-box;
+background-color: rgba(0, 0, 0, 0.398438);
+background-image: url(http://code.jquery.com/mobile/1.1.0/images/icons-18-white.png);
+background-origin: padding-box;
+background-position: -60px 50%;
+background-repeat: no-repeat;
+box-shadow: rgba(255, 255, 255, 0.398438) 0px 1px 0px 0px;
+margin-bottom: 0px;
+margin-left: 0px;
+margin-right: 0px;
+margin-top: -9px;
+padding: 0;
+position: absolute;
+right: 10px;
+top: 50%;
+white-space: nowrap;
+width: 18px;
+height: 18px;
+zoom: 1;
+         </span>
+         */
+
+        var check = cols[1].split("=");
+
+        if (check.length>1 && (check[0]=="camera" || check[0]=="hist"))
+        {
+            var data = cols[1].substring(check[0].length+1).split("/");
+
             var tr = document.createElement("tr");
             tr.setAttribute("class", "row");
@@ -153,5 +177,7 @@
             canv.setAttribute("width",  "1");
             canv.setAttribute("height", "1");
-            canv.setAttribute("data-file", cols[1].substring(7));
+            canv.setAttribute("data-type", check[0]);
+            canv.setAttribute("data-file", data[0]);
+            canv.setAttribute("data-data", cols[1].substring(check[0].length+data[0].length+2));
             canv.setAttribute("style", "display:none;");
             td.appendChild(canv);
@@ -281,4 +307,7 @@
 
         doresize(1);
+
+        //setInterval(refresh_text, 1000);
+        //setInterval(refresh_graphics, 5000);
 
         refresh_text();
@@ -302,5 +331,5 @@
 
     $("body").setAttribute("data-visible", (z+1)%2);
-    intervalSlide = setInterval("doShift("+z+")", 75);
+    intervalSlide = setInterval(doShift, 75, z);
 }
 
@@ -456,40 +485,26 @@
     if (isSliding() || !valid(fname))
     {
-        setTimeout("refresh_text()", 1000);
-        return;
-    }
-
-    var xmlHttp = null;
-
-    try { xmlHttp = new XMLHttpRequest(); }
-    catch(e)
-    {
-        alert("Your browser doesn't support dynamic reload.");
-        return;
-    }
-
+        setTimeout(refresh_text, 1000);
+        return;
+    }
+
+    var xmlHttp = new XMLHttpRequest();
     xmlHttp.open('POST', fname+'.txt', true);
-
-    xmlHttp.onreadystatechange =
-        function ()
-        {
-            if (xmlHttp.readyState == 4)
-            {
-                if (xmlHttp.status!=0 && xmlHttp.status!=200)
-                {
-                    alert("ERROR[1] - HTTP request '"+fname+".txt': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
-                    setTimeout("refresh_text()", 10000);
-                    return;
-                }
-
-                if (!isSliding())
-                {
-                    cycleCol($("ldot"+z));
-                    update_text(fname, xmlHttp.responseText);
-                }
-                setTimeout("refresh_text()", 3000);
-            }
-        };
-
+    xmlHttp.onload = function ()
+    {
+        if (xmlHttp.status!=200)
+        {
+            alert("ERROR[1] - HTTP request '"+fname+".txt': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
+            setTimeout(refresh_text, 10000);
+            return;
+        }
+
+        if (!isSliding())
+        {
+            cycleCol($("ldot"+z));
+            update_text(fname, xmlHttp.responseText);
+        }
+        setTimeout(refresh_text, 3000);
+    };
     xmlHttp.send(null);
 }
@@ -612,40 +627,27 @@
     if (isSliding() || !valid(fname))
     {
-        setTimeout("refresh_graphics()", 1000);
-        return;
-    }
-
-    var xmlHttp = null;
-
-    try { xmlHttp = new XMLHttpRequest(); }
-    catch(e)
-    {
-        alert("Your browser doesn't support dynamic reload.");
-        return;
-    }
-
+        setTimeout(refresh_graphics, 1000);
+        return;
+    }
+
+    var xmlHttp = new XMLHttpRequest();
     xmlHttp.open('POST', fname, true);
-    xmlHttp.onload =
-        function ()
-        {
-            if (xmlHttp.readyState == 4)
-            {
-                if (xmlHttp.status!=0 && xmlHttp.status!=200)
-                {
-                    alert("ERROR[2] - Request '"+fname+"': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
-                    setTimeout("refresh_text()", 10000);
-                    //****** invalidate ******
-                    return;
-                }
-
-                if (!isSliding())
-                {
-                    cycleCol($("rdot"+z));
-                    process_eventdata(xmlHttp.responseText);
-                }
-                setTimeout("refresh_graphics()", 5000)
-            }
-        };
-
+    xmlHttp.onload = function()
+    {
+        if (xmlHttp.status!=200)
+        {
+            alert("ERROR[2] - Request '"+fname+"': "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
+            setTimeout(refresh_text, 10000);
+            //****** invalidate ******
+            return;
+        }
+
+        if (!isSliding())
+        {
+            cycleCol($("rdot"+z));
+            process_eventdata(xmlHttp.responseText);
+        }
+        setTimeout(refresh_graphics, 5000)
+    };
     xmlHttp.send(null);
 }
@@ -841,4 +843,9 @@
 function drawCamLegend(canv)
 {
+    //alert(canv.getAttribute("data-data"));
+
+    var vals = canv.getAttribute("data-data").split("/");
+    var diff = vals[1]-vals[0];
+
     var cw = canv.width;
     var ch = canv.height;
@@ -850,7 +857,10 @@
     ctx.textBaseline = "top";
 
-    ctx.strokeStyle = "#"+color(0);
-    ctx.strokeText("-2.0V", cw-5, 135);
-
+    for (var i=0; i<9; i++)
+    {
+        ctx.strokeStyle = "#"+color(16*i);
+        ctx.strokeText((vals[1]-diff*i/8)+vals[2], cw-5, 135-i*15);
+    }
+    /*
     ctx.strokeStyle = "#"+color(16);
     ctx.strokeText("-1.5V", cw-5, 120);
@@ -875,5 +885,5 @@
 
     ctx.strokeStyle = "#"+color(127);
-    ctx.strokeText("2.0V", cw-5, 5);
+    ctx.strokeText("2.0V", cw-5, 5); */
 }
 
@@ -929,4 +939,5 @@
     ctx.stroke();
     ctx.closePath();
+
 }
 
@@ -941,13 +952,15 @@
         return;
 
+    var type = canv.getAttribute("data-type");
+
     var ctx = canv.getContext("2d");
     ctx.clearRect(0, 0, canv.width, canv.height);
 
-//    drawGraph(canv, result);
-
-//    drawCam(result);
-    drawFullCam(result);
-//    drawFullCam(result);
-//    drawCamLegend(canv);
+    switch (type)
+    {
+    case "hist":   drawGraph(canv, result); break;
+    //case "camera": drawCam(result);     break;
+    case "camera": drawFullCam(result); drawCamLegend(canv); break;
+    }
 
     $("image"+z).src = canv.toDataURL("image/png");
