Index: trunk/FACT++/www/smartfact/index.js
===================================================================
--- trunk/FACT++/www/smartfact/index.js	(revision 14143)
+++ trunk/FACT++/www/smartfact/index.js	(revision 14144)
@@ -38,5 +38,5 @@
             {
                 //alert("ERROR[0] - HTTP request '"+xmlLoad.statusText+" ["+xmlLoad.status+"]");
-                return;
+                //return;
             }
             if (xmlLoad.responseText.length>0)
@@ -742,6 +742,9 @@
 
     // This might create the scroll bar
-    img.style.height = ih+"px";
-    canv.height      = ih;
+
+    if (img.style.height!=ih+"px")
+        img.style.height = ih+"px";
+    if (canv.height!=ih)
+        canv.height = ih;
 
     // now we can evaluate the correct view-port
@@ -750,6 +753,8 @@
     var sW = fixedw ? fixedw : canv.parentNode.clientWidth;
 
-    img.style.width = sW+"px";
-    canv.width      = sW;
+    if (img.style.width!=sW+"px")
+        img.style.width = sW+"px";
+    if (canv.width!=sW)
+        canv.width = sW;
 
     // ------ debug -----
@@ -905,4 +910,5 @@
             cycleCol($("ldot"+z));
             update_text(fname, xmlText.responseText);
+            doresize(z);
         }
         timeoutText = setTimeout(refresh_text, 3000);
@@ -967,5 +973,5 @@
     if (header.length>=3 && $("body").sound)
     {
-        $("speaker"+z).style.display ="none";
+        $("speaker"+z).style.display = "none";
 
         var audio = $("audio");
@@ -985,19 +991,11 @@
             ogg.src = name+".ogg";
 
-            // If audio file has changed play the new one
-            if (audio.firstChild.src!=mp3.src)
-            {
-                audio.replaceChild(mp3, audio.firstChild);
-                audio.replaceChild(ogg, audio.lastChild);
-
-            }
+            audio.replaceChild(mp3, audio.firstChild);
+            audio.replaceChild(ogg, audio.lastChild);
+
+            audio.load();
+            audio.play();
 
             audio.date = audio_date;
-
-            /*
-             audio.firstChild.src = name_mp3;
-             audio.lastChild.src  = name_ogg;
-             audio.load();
-             */
         }
     }
@@ -1304,5 +1302,5 @@
     for (var i=0; i<11; i++)
     {
-        ctx.strokeStyle = "#"+color(16*i);
+        ctx.strokeStyle = "#"+color(126*i/10);
         ctx.strokeText((v0+diff*i/10).toPrecision(3)+unit, cw-5, 125-i*12);
     }
@@ -1327,5 +1325,6 @@
     var umax = vals[2]+unit;
 
-    var stat = vals[3]+unit+"   /   "+vals[4]+unit+"   /   "+vals[5]+unit;
+    var stat = vals.length==4 ? vals[3] :
+        vals[3]+unit+"   /   "+vals[4]+unit+"   /   "+vals[5]+unit;
 
     var cw = canv.width;
@@ -1433,90 +1432,16 @@
 }
 
-/*
-function drawZd(result)
-{
-    function frac(x)   { return(x-Math.floor(x));     }
-    function Mod(a, b) { return(a-Math.floor(a/b)*b); }
-
-    var z    = $("body").visiblePage;
-    var canv = $("canvas"+z);
-
+function invalidateCanvas(canv)
+{
     var ctx = canv.getContext("2d");
 
-    // 16:57:58.210572 -  Mrk 421:       Ra=11.074266h Dec= 38.208801deg
-    // 16:57:58.210782 -  Mrk 501:       Ra=16.897867h Dec= 39.760201deg
-    // 16:57:58.210941 -  1ES 2344+51.4: Ra=23.784733h Dec= 51.705002deg
-    // 16:57:58.211060 -  PKS 2155-304:  Ra=21.981134h Dec=-30.225599deg
-    // 16:57:58.211189 -  Crab:          Ra= 5.575539h Dec= 22.014500deg
-    // 16:57:58.211312 -  H 1426+428:    Ra=14.475734h Dec= 42.674702deg
-    // 16:57:58.211429 -  1ES 1959+650:  Ra=19.999933h Dec= 65.148499deg
-    // 16:57:58.211544 -  Dark Patch 3:  Ra= 3.100000h Dec= 31.183333deg
-    // 16:57:58.211651 -  1ES 1218+304:  Ra=12.356089h Dec= 30.176897deg
-
-    var now = new Date();
-
-    var RAD = Math.Pi/180.;
-
-    var lon = -(17.+53./60+26.525/3600) * Math.PI/180;
-    var lat =  (28.+45./60+42.462/3600) * Math.PI/180;
-
-    var ra  = 16.897867 * Math.PI/ 12; //h
-    var dec = 39.760201 * Math.PI/180; //deg
-
-    var arr = "";
-
-    var date = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
-    date /= 86400000;
-    date += 40587;
-
-    var coslat = Math.cos(lat);
-    var sinlat = Math.sin(lat); 
-
-    // 21
-    for (var h=-4*12; h<6*12; h++)
-    {
-        var mjd = date + h/(24.*12);      // Modified julian date
-        var t   = (mjd-51544.5) / 36525;  // Julian centuries since J2000.
-
-        // GMST at this UT1
-        var r    = 24110.54841+(8640184.812866+(0.093104-6.2e-6*t)*t)*t;
-        var sum  = r/86400 + frac(mjd);
-        var gmst = frac(sum)*Math.PI*2;
-
-        var lmst = Mod(gmst + lon, Math.PI*2);
-        var lha  = ra - lmst;
-
-        var alt  = Math.asin(sinlat * Math.sin(dec) +
-                             coslat * Math.cos(dec) * Math.cos(lha));
-        alt *= 256/Math.PI; // 128/90*180/Math.Pi
-        if (alt<0)
-            alt = 0;
-        if (alt>127)
-            alt=127;
-
-        arr += String.fromCharCode(alt);
-    }
-
-    var vals = new Array(5);//[] = { 0, 0, 0, 0, 0 };
-    vals[1] = "90";
-    vals[2] = " 0";
-    vals[3] = "  ";
-    vals[4] = "  ";
-    vals[5] = "  ";
-    drawGraph(canv, vals, arr);
-}
-*/
-
-function process_eventdata(result)
+    ctx.fillStyle = "rgba(255, 255, 255, 0.75)";
+    ctx.fillRect(0, 0, canv.width, canv.height);
+}
+
+function processGraphicsData(canv, result)
 {
     if (result.length==0)
-        return;
-
-    var z = $("body").visiblePage;//getAttribute("data-visible");
-    var canv = $("canvas"+z);
-    if (!canv)
-        return;
-
-    var type = canv.dataType;//getAttribute("data-type");
+        return false;
 
     var ctx = canv.getContext("2d");
@@ -1525,11 +1450,11 @@
     var data = result.split('\x7f');
     if (data.length<2)
-        return;
+        return false;
 
     var header = data[0].split('\n');
     if (header.length<4)
-        return;
-
-    switch (type)
+        return false;
+
+    switch (canv.dataType)
     {
         //case "camera": drawCam(result);     break;
@@ -1545,12 +1470,23 @@
     var now = new Date();
     var tm  = new Date();
-    tm.setTime(data[0]);
+    tm.setTime(header[0]);
+
     if (tm.getTime()+60000<now.getTime())
-    {
-        ctx.fillStyle = "rgba(255, 255, 255, 0.75)";
-        ctx.fillRect(0, 0, canv.width, canv.height);
-    }
+        return false;
 
     //$("image"+z).src = canv.toDataURL("image/png");
+
+    return true;
+}
+
+function process_eventdata(result)
+{
+    var z = $("body").visiblePage;//getAttribute("data-visible");
+    var canv = $("canvas"+z);
+    if (!canv)
+        return;
+
+    if (!processGraphicsData(canv, result))
+        invalidateCanvas(canv);
 }
 
