//  Global variables

   var zoomw;
   var struxw;
   var zoomexists;
   var showpointers;
   var showlabels;
   var showstrux;
   var zoomiplane;
   var pln = new Array(3);
   var axl = new Object();
   var sag = new Object();
   var cor = new Object();
   function Group(nstruct) {
      this.nstruct = nstruct;
   }

   var grp = new Array(4);
   grp[0] = new Group(42);
   grp[1] = new Group(20);
   grp[2] = new Group(25);
   grp[3] = new Group(21);
   grp[0].struct = [ { name:"<no struct>",sn:[-1,-1,-1] },
                     { name:"amygdala",sn:[65,77,73] },
                     { name:"angular g",sn:[87,102,26] },
                     { name:"anterior cingulate",sn:[95,63,81] },
                     { name:"anterior commissure",sn:[73,71,71] },
                     { name:"calcarine fissure",sn:[51,67,27] },
                     { name:"caudate body",sn:[86,80,58] },
                     { name:"caudate head",sn:[83,79,72] },
                     { name:"c callosum genu",sn:[82,66,84] },
                     { name:"c callosum splenium ",sn:[80,64,48] },
                     { name:"central s",sn:[100,40,47] },
                     { name:"centrum semiovale ",sn:[90,53,75] },
                     { name:"cerebral peduncle",sn:[62,61,66] },
                     { name:"collateral s",sn:[49,83,39] },
                     { name:"corona radiata",sn:[93,47,87] },
                     { name:"cuneus",sn:[59,73,20] },
                     { name:"fornix",sn:[68,72,67] },
                     { name:"fusiform g",sn:[48,89,43] },
                     { name:"globus pallidus",sn:[76,60,70] },
                     { name:"hippocampus",sn:[61,91,60] },
                     { name:"inf frontal g",sn:[85,35,82] },
                     { name:"inf temporal g",sn:[56,34,62] },
                     { name:"insula",sn:[74,45,64] },
                     { name:"internal capsule",sn:[79,78,74] },
                     { name:"intraparietal s",sn:[89,92,21] },
                     { name:"lingual g",sn:[50,76,40] },
                     { name:"marginal s",sn:[88,75,33] },
                     { name:"mid frontal g",sn:[99,44,83] },
                     { name:"mid temporal g",sn:[63,30,68] },
                     { name:"orbital g",sn:[72,62,86] },
                     { name:"parahippocampal g",sn:[55,90,63] },
                     { name:"parieto-occipital s" ,sn:[67,68,19] },
                     { name:"posterior cingulate",sn:[94,74,34] },
                     { name:"posterior commissure",sn:[66,70,53] },
                     { name:"putamen ",sn:[78,88,69] },
                     { name:"straight g",sn:[69,65,88] },
                     { name:"sup frontal g",sn:[111,54,89] },
                     { name:"sup occipital g",sn:[64,58,19] },
                     { name:"sup parietal g",sn:[92,87,28] },
                     { name:"supramarginal g",sn:[91,29,42] },
                     { name:"sup temporal g",sn:[70,36,90] },
                     { name:"Sylvian fissure",sn:[77,38,76] } ];
   grp[1].struct = [ { name:"<no struct>" ,sn:[-1,-1,-1] },
                     { name:"basis pontis",sn:[47,81,61] },
                     { name:"cerebellar hemisphere",sn:[37,94,41] },
                     { name:"cerebellar tonsils",sn:[24,78,54] },
                     { name:"cerebellar vermis",sn:[35,68,42] },
                     { name:"dentate nucleus",sn:[36,79,47] },
                     { name:"horizontal fissure",sn:[40,102,56] },
                     { name:"hypothalamus",sn:[65,67,65] },
                     { name:"inf colliculus",sn:[57,71,50] },
                     { name:"inferior olive",sn:[33,76,66] },
                     { name:"mamillary bodies",sn:[64,69,68] },
                     { name:"medulla-pyramid" ,sn:[34,74,67] },
                     { name:"optic tract",sn:[66,62,70] },
                     { name:"periaqueductal gray",sn:[56,70,53] },
                     { name:"pons",sn:[49,75,64] },
                     { name:"red nucleus",sn:[61,66,60] },
                     { name:"spinal cord",sn:[5,73,69] },
                     { name:"substantia nigra",sn:[63,60,62] },
                     { name:"sup colliculus",sn:[60,63,49] },
                     { name:"thalamus",sn:[75,64,57] } ];
   grp[2].struct = [ { name:"<no struct>" ,sn:[-1,-1,-1] },
                     { name:"ambient cistern",sn:[59,71,47] },
                     { name:"ant cerebral a",sn:[69,68,81] },
                     { name:"aqueduct of Sylvius",sn:[64,69,53] },
                     { name:"atrium",sn:[77,79,45] },
                     { name:"basilar a",sn:[45,72,73] },
                     { name:"cavernous sinus",sn:[65,63,75] },
                     { name:"choroid plexus",sn:[82,58,51] },
                     { name:"cisterna magna",sn:[19,74,58] },
                     { name:"foramen of Monro",sn:[79,67,68] },
                     { name:"fourth ventricle",sn:[39,75,54] },
                     { name:"frontal horn",sn:[83,82,83] },
                     { name:"internal carotid a",sn:[50,60,79] },
                     { name:"mid cerebral a",sn:[67,56,74] },
                     { name:"occipital horn",sn:[53,83,26] },
                     { name:"post cerebral a",sn:[60,81,63] },
                     { name:"post communicating a",sn:[61,77,72] },
                     { name:"prepontine cistern",sn:[44,80,69] },
                     { name:"septum pellucidum",sn:[80,73,70] },
                     { name:"sigmoid sinus",sn:[42,106,42] },
                     { name:"superior sagittal sinus",sn:[84,65,15] },
                     { name:"suprasellar cistern",sn:[63,64,71] },
                     { name:"temporal horn",sn:[58,47,65] },
                     { name:"third ventricle",sn:[72,70,67] },
                     { name:"vertebral a",sn:[40,76,64] } ];
   grp[3].struct = [ { name:"<no struct>" ,sn:[-1,-1,-1] },
                     { name:"clivus",sn:[56,62,75] },
                     { name:"cribriform plate",sn:[71,74,105] },
                     { name:"ethmoid sinus",sn:[61,72,104] },
                     { name:"facial/auditory nn",sn:[41,49,65] },
                     { name:"falx cerebri",sn:[102,68,95] },
                     { name:"foramen magnum",sn:[19,71,60] },
                     { name:"frontal sinus",sn:[81,88,115] },
                     { name:"infundibulum",sn:[63,69,77] },
                     { name:"mastoid sinus",sn:[25,111,61] },
                     { name:"maxillary sinus",sn:[49,57,110] },
                     { name:"oculomotor n",sn:[60,64,69] },
                     { name:"optic chiasm",sn:[65,67,76] },
                     { name:"optic n",sn:[66,51,106] },
                     { name:"petrous bone",sn:[50,102,58] },
                     { name:"pineal",sn:[64,70,49] },
                     { name:"pituitary",sn:[57,65,79] },
                     { name:"sella turcica",sn:[58,73,78] },
                     { name:"sphenoid sinus",sn:[53,63,88] },
                     { name:"tentorium cerebelli",sn:[47,56,40] },
                     { name:"trigeminal n",sn:[52,81,70] } ];
   function initgeomh(plns,axls,sags,cors)
   {
      plns[0].hi = [ 4,5,7,9,11,12,14,16,18,19,21,23,25,26,28,30,31,33,35,37,38,40,42,44,45,47,49,51,52,54,56,58,59,61,63,65,66,68,70,72,73,75,77,79,80,82,84,86,87,89,91,93,94,96,98,100,101,103,105,107,108,110,112,114,115,117,119,121,122,124,126,127,129,131,133,134,136,138,140,141,143,145,147,148,150,152,154,155,157,159,161,162,164,166,168,169,171,173,175,176,178,180,182,183,185,187,189,190,192,194,196,197,199,201,203,204,206,208,210,211,213,215,217,218,220,222,223 ];
      plns[0].vi = [ 234,233,231,229,227,226,224,222,220,219,217,215,213,212,210,208,206,205,203,201,199,198,196,194,192,191,189,187,185,184,182,180,178,177,175,173,172,170,168,166,165,163,161,159,158,156,154,152,151,149,147,145,144,142,140,138,137,135,133,131,130,128,126,124,123,121,119,117,116,114,112,110,109,107,105,103,102,100,98,96,95,93,91,89,88,86,84,82,81,79,77,76,74,72,70,69,67,65,63,62,60,58,56,55,53,51,49,48,46,44,42,41,39,37,35,34,32,30,28,27,25,23,21,20 ];
      plns[1].hi = [ 234,233,231,229,227,226,224,222,220,219,217,215,213,212,210,208,206,205,203,201,199,198,196,194,192,191,189,187,185,184,182,180,178,177,175,173,172,170,168,166,165,163,161,159,158,156,154,152,151,149,147,145,144,142,140,138,137,135,133,131,130,128,126,124,123,121,119,117,116,114,112,110,109,107,105,103,102,100,98,96,95,93,91,89,88,86,84,82,81,79,77,76,74,72,70,69,67,65,63,62,60,58,56,55,53,51,49,48,46,44,42,41,39,37,35,34,32,30,28,27,25,23,21,20 ];
      plns[1].vi = [ 250,249,247,245,243,242,240,238,236,235,233,231,229,228,226,224,223,221,219,217,216,214,212,210,209,207,205,203,202,200,198,196,195,193,191,189,188,186,184,182,181,179,177,175,174,172,170,168,167,165,163,161,160,158,156,154,153,151,149,147,146,144,142,140,139,137,135,133,132,130,128,127,125,123,121,120,118,116,114,113,111,109,107,106,104,102,100,99,97,95,93,92,90,88,86,85,83,81,79,78,76,74,72,71,69,67,65,64,62,60,58,57,55,53,51,50,48,46,44,43,41,39,37,36,34,32,31 ];
      plns[2].hi = [ 4,5,7,9,11,12,14,16,18,19,21,23,25,26,28,30,31,33,35,37,38,40,42,44,45,47,49,51,52,54,56,58,59,61,63,65,66,68,70,72,73,75,77,79,80,82,84,86,87,89,91,93,94,96,98,100,101,103,105,107,108,110,112,114,115,117,119,121,122,124,126,127,129,131,133,134,136,138,140,141,143,145,147,148,150,152,154,155,157,159,161,162,164,166,168,169,171,173,175,176,178,180,182,183,185,187,189,190,192,194,196,197,199,201,203,204,206,208,210,211,213,215,217,218,220,222,223 ];
      plns[2].vi = [ 250,249,247,245,243,242,240,238,236,235,233,231,229,228,226,224,223,221,219,217,216,214,212,210,209,207,205,203,202,200,198,196,195,193,191,189,188,186,184,182,181,179,177,175,174,172,170,168,167,165,163,161,160,158,156,154,153,151,149,147,146,144,142,140,139,137,135,133,132,130,128,127,125,123,121,120,118,116,114,113,111,109,107,106,104,102,100,99,97,95,93,92,90,88,86,85,83,81,79,78,76,74,72,71,69,67,65,64,62,60,58,57,55,53,51,50,48,46,44,43,41,39,37,36,34,32,31 ];

      axls.n1 = [  1.000,-0.000,-0.000 ];
      axls.n2 = [  0.000,-0.000,-1.000 ];
      axls.n3 = [  0.000,-1.000,-0.000 ];
      sags.n1 = [ -0.000,-0.000,-1.000 ];
      sags.n2 = [  0.000, 1.000, 0.000 ];
      sags.n3 = [  1.000,-0.000,-0.000 ];
      cors.n1 = [  1.000, 0.000, 0.000 ];
      cors.n2 = [  0.000, 1.000, 0.000 ];
      cors.n3 = [  0.000, 0.000, 1.000 ];
      axls.sd = [
                  [  0.000,250.939,234.845 ],
                  [  0.000,249.194,234.845 ],
                  [  0.000,247.448,234.845 ],
                  [  0.000,245.703,234.845 ],
                  [  0.000,243.957,234.845 ],
                  [  0.000,242.212,234.845 ],
                  [  0.000,240.466,234.845 ],
                  [  0.000,238.721,234.845 ],
                  [  0.000,236.975,234.845 ],
                  [  0.000,235.230,234.845 ],
                  [  0.000,233.485,234.845 ],
                  [  0.000,231.739,234.845 ],
                  [  0.000,229.994,234.845 ],
                  [  0.000,228.248,234.845 ],
                  [  0.000,226.503,234.845 ],
                  [  0.000,224.757,234.845 ],
                  [  0.000,223.012,234.845 ],
                  [  0.000,221.266,234.845 ],
                  [  0.000,219.521,234.845 ],
                  [  0.000,217.775,234.845 ],
                  [  0.000,216.030,234.845 ],
                  [  0.000,214.285,234.845 ],
                  [  0.000,212.539,234.845 ],
                  [  0.000,210.794,234.845 ],
                  [  0.000,209.048,234.845 ],
                  [  0.000,207.303,234.845 ],
                  [  0.000,205.557,234.845 ],
                  [  0.000,203.812,234.845 ],
                  [  0.000,202.066,234.845 ],
                  [  0.000,200.321,234.845 ],
                  [  0.000,198.575,234.845 ],
                  [  0.000,196.830,234.845 ],
                  [  0.000,195.085,234.845 ],
                  [  0.000,193.339,234.845 ],
                  [  0.000,191.594,234.845 ],
                  [  0.000,189.848,234.845 ],
                  [  0.000,188.103,234.845 ],
                  [  0.000,186.357,234.845 ],
                  [  0.000,184.612,234.845 ],
                  [  0.000,182.866,234.845 ],
                  [  0.000,181.121,234.845 ],
                  [  0.000,179.375,234.845 ],
                  [  0.000,177.630,234.845 ],
                  [  0.000,175.885,234.845 ],
                  [  0.000,174.139,234.845 ],
                  [  0.000,172.394,234.845 ],
                  [  0.000,170.648,234.845 ],
                  [  0.000,168.903,234.845 ],
                  [  0.000,167.157,234.845 ],
                  [  0.000,165.412,234.845 ],
                  [  0.000,163.666,234.845 ],
                  [  0.000,161.921,234.845 ],
                  [  0.000,160.175,234.845 ],
                  [  0.000,158.430,234.845 ],
                  [  0.000,156.685,234.845 ],
                  [  0.000,154.939,234.845 ],
                  [  0.000,153.194,234.845 ],
                  [  0.000,151.448,234.845 ],
                  [  0.000,149.703,234.845 ],
                  [  0.000,147.957,234.845 ],
                  [  0.000,146.212,234.845 ],
                  [  0.000,144.466,234.845 ],
                  [  0.000,142.721,234.845 ],
                  [  0.000,140.975,234.845 ],
                  [  0.000,139.230,234.845 ],
                  [  0.000,137.485,234.845 ],
                  [  0.000,135.739,234.845 ],
                  [  0.000,133.994,234.845 ],
                  [  0.000,132.248,234.845 ],
                  [  0.000,130.503,234.845 ],
                  [  0.000,128.757,234.845 ],
                  [  0.000,127.012,234.845 ],
                  [  0.000,125.266,234.845 ],
                  [  0.000,123.521,234.845 ],
                  [  0.000,121.775,234.845 ],
                  [  0.000,120.030,234.845 ],
                  [  0.000,118.285,234.845 ],
                  [  0.000,116.539,234.845 ],
                  [  0.000,114.794,234.845 ],
                  [  0.000,113.048,234.845 ],
                  [  0.000,111.303,234.845 ],
                  [  0.000,109.557,234.845 ],
                  [  0.000,107.812,234.845 ],
                  [  0.000,106.066,234.845 ],
                  [  0.000,104.321,234.845 ],
                  [  0.000,102.575,234.845 ],
                  [  0.000,100.830,234.845 ],
                  [  0.000,99.085,234.845 ],
                  [  0.000,97.339,234.845 ],
                  [  0.000,95.594,234.845 ],
                  [  0.000,93.848,234.845 ],
                  [  0.000,92.103,234.845 ],
                  [  0.000,90.357,234.845 ],
                  [  0.000,88.612,234.845 ],
                  [  0.000,86.866,234.845 ],
                  [  0.000,85.121,234.845 ],
                  [  0.000,83.375,234.845 ],
                  [  0.000,81.630,234.845 ],
                  [  0.000,79.885,234.845 ],
                  [  0.000,78.139,234.845 ],
                  [  0.000,76.394,234.845 ],
                  [  0.000,74.648,234.845 ],
                  [  0.000,72.903,234.845 ],
                  [  0.000,71.157,234.845 ],
                  [  0.000,69.412,234.845 ],
                  [  0.000,67.666,234.845 ],
                  [  0.000,65.921,234.845 ],
                  [  0.000,64.175,234.845 ],
                  [  0.000,62.430,234.845 ],
                  [  0.000,60.685,234.845 ],
                  [  0.000,58.939,234.845 ],
                  [  0.000,57.194,234.845 ],
                  [  0.000,55.448,234.845 ],
                  [  0.000,53.703,234.845 ],
                  [  0.000,51.957,234.845 ],
                  [  0.000,50.212,234.845 ],
                  [  0.000,48.466,234.845 ],
                  [  0.000,46.721,234.845 ],
                  [  0.000,44.975,234.845 ],
                  [  0.000,43.230,234.845 ],
                  [  0.000,41.485,234.845 ],
                  [  0.000,39.739,234.845 ],
                  [  0.000,37.994,234.845 ],
                  [  0.000,36.248,234.845 ],
                  [  0.000,34.503,234.845 ],
                  [  0.000,32.757,234.845 ],
                  [  0.000,31.012,234.845 ]
               ];
      sags.sd = [
                  [  4.061, 0.000,234.845 ],
                  [  5.806, 0.000,234.845 ],
                  [  7.552, 0.000,234.845 ],
                  [  9.297, 0.000,234.845 ],
                  [ 11.043, 0.000,234.845 ],
                  [ 12.788, 0.000,234.845 ],
                  [ 14.534, 0.000,234.845 ],
                  [ 16.279, 0.000,234.845 ],
                  [ 18.025, 0.000,234.845 ],
                  [ 19.770, 0.000,234.845 ],
                  [ 21.515, 0.000,234.845 ],
                  [ 23.261, 0.000,234.845 ],
                  [ 25.006, 0.000,234.845 ],
                  [ 26.752, 0.000,234.845 ],
                  [ 28.497, 0.000,234.845 ],
                  [ 30.243, 0.000,234.845 ],
                  [ 31.988, 0.000,234.845 ],
                  [ 33.734, 0.000,234.845 ],
                  [ 35.479, 0.000,234.845 ],
                  [ 37.225, 0.000,234.845 ],
                  [ 38.970, 0.000,234.845 ],
                  [ 40.715, 0.000,234.845 ],
                  [ 42.461, 0.000,234.845 ],
                  [ 44.206, 0.000,234.845 ],
                  [ 45.952, 0.000,234.845 ],
                  [ 47.697, 0.000,234.845 ],
                  [ 49.443, 0.000,234.845 ],
                  [ 51.188, 0.000,234.845 ],
                  [ 52.934, 0.000,234.845 ],
                  [ 54.679, 0.000,234.845 ],
                  [ 56.425, 0.000,234.845 ],
                  [ 58.170, 0.000,234.845 ],
                  [ 59.915, 0.000,234.845 ],
                  [ 61.661, 0.000,234.845 ],
                  [ 63.406, 0.000,234.845 ],
                  [ 65.152, 0.000,234.845 ],
                  [ 66.897, 0.000,234.845 ],
                  [ 68.643, 0.000,234.845 ],
                  [ 70.388, 0.000,234.845 ],
                  [ 72.134, 0.000,234.845 ],
                  [ 73.879, 0.000,234.845 ],
                  [ 75.625, 0.000,234.845 ],
                  [ 77.370, 0.000,234.845 ],
                  [ 79.115, 0.000,234.845 ],
                  [ 80.861, 0.000,234.845 ],
                  [ 82.606, 0.000,234.845 ],
                  [ 84.352, 0.000,234.845 ],
                  [ 86.097, 0.000,234.845 ],
                  [ 87.843, 0.000,234.845 ],
                  [ 89.588, 0.000,234.845 ],
                  [ 91.334, 0.000,234.845 ],
                  [ 93.079, 0.000,234.845 ],
                  [ 94.825, 0.000,234.845 ],
                  [ 96.570, 0.000,234.845 ],
                  [ 98.315, 0.000,234.845 ],
                  [ 100.061, 0.000,234.845 ],
                  [ 101.806, 0.000,234.845 ],
                  [ 103.552, 0.000,234.845 ],
                  [ 105.297, 0.000,234.845 ],
                  [ 107.043, 0.000,234.845 ],
                  [ 108.788, 0.000,234.845 ],
                  [ 110.534, 0.000,234.845 ],
                  [ 112.279, 0.000,234.845 ],
                  [ 114.025, 0.000,234.845 ],
                  [ 115.770, 0.000,234.845 ],
                  [ 117.515, 0.000,234.845 ],
                  [ 119.261, 0.000,234.845 ],
                  [ 121.006, 0.000,234.845 ],
                  [ 122.752, 0.000,234.845 ],
                  [ 124.497, 0.000,234.845 ],
                  [ 126.243, 0.000,234.845 ],
                  [ 127.988, 0.000,234.845 ],
                  [ 129.734, 0.000,234.845 ],
                  [ 131.479, 0.000,234.845 ],
                  [ 133.225, 0.000,234.845 ],
                  [ 134.970, 0.000,234.845 ],
                  [ 136.715, 0.000,234.845 ],
                  [ 138.461, 0.000,234.845 ],
                  [ 140.206, 0.000,234.845 ],
                  [ 141.952, 0.000,234.845 ],
                  [ 143.697, 0.000,234.845 ],
                  [ 145.443, 0.000,234.845 ],
                  [ 147.188, 0.000,234.845 ],
                  [ 148.934, 0.000,234.845 ],
                  [ 150.679, 0.000,234.845 ],
                  [ 152.425, 0.000,234.845 ],
                  [ 154.170, 0.000,234.845 ],
                  [ 155.915, 0.000,234.845 ],
                  [ 157.661, 0.000,234.845 ],
                  [ 159.406, 0.000,234.845 ],
                  [ 161.152, 0.000,234.845 ],
                  [ 162.897, 0.000,234.845 ],
                  [ 164.643, 0.000,234.845 ],
                  [ 166.388, 0.000,234.845 ],
                  [ 168.134, 0.000,234.845 ],
                  [ 169.879, 0.000,234.845 ],
                  [ 171.625, 0.000,234.845 ],
                  [ 173.370, 0.000,234.845 ],
                  [ 175.115, 0.000,234.845 ],
                  [ 176.861, 0.000,234.845 ],
                  [ 178.606, 0.000,234.845 ],
                  [ 180.352, 0.000,234.845 ],
                  [ 182.097, 0.000,234.845 ],
                  [ 183.843, 0.000,234.845 ],
                  [ 185.588, 0.000,234.845 ],
                  [ 187.334, 0.000,234.845 ],
                  [ 189.079, 0.000,234.845 ],
                  [ 190.825, 0.000,234.845 ],
                  [ 192.570, 0.000,234.845 ],
                  [ 194.315, 0.000,234.845 ],
                  [ 196.061, 0.000,234.845 ],
                  [ 197.806, 0.000,234.845 ],
                  [ 199.552, 0.000,234.845 ],
                  [ 201.297, 0.000,234.845 ],
                  [ 203.043, 0.000,234.845 ],
                  [ 204.788, 0.000,234.845 ],
                  [ 206.534, 0.000,234.845 ],
                  [ 208.279, 0.000,234.845 ],
                  [ 210.025, 0.000,234.845 ],
                  [ 211.770, 0.000,234.845 ],
                  [ 213.515, 0.000,234.845 ],
                  [ 215.261, 0.000,234.845 ],
                  [ 217.006, 0.000,234.845 ],
                  [ 218.752, 0.000,234.845 ],
                  [ 220.497, 0.000,234.845 ],
                  [ 222.243, 0.000,234.845 ],
                  [ 223.988, 0.000,234.845 ]
               ];
      cors.sd = [
                  [  0.000, 0.000, 0.000 ],
                  [  0.000, 0.000, 1.745 ],
                  [  0.000, 0.000, 3.491 ],
                  [  0.000, 0.000, 5.236 ],
                  [  0.000, 0.000, 6.982 ],
                  [  0.000, 0.000, 8.727 ],
                  [  0.000, 0.000,10.473 ],
                  [  0.000, 0.000,12.218 ],
                  [  0.000, 0.000,13.964 ],
                  [  0.000, 0.000,15.709 ],
                  [  0.000, 0.000,17.455 ],
                  [  0.000, 0.000,19.200 ],
                  [  0.000, 0.000,20.945 ],
                  [  0.000, 0.000,22.691 ],
                  [  0.000, 0.000,24.436 ],
                  [  0.000, 0.000,26.182 ],
                  [  0.000, 0.000,27.927 ],
                  [  0.000, 0.000,29.673 ],
                  [  0.000, 0.000,31.418 ],
                  [  0.000, 0.000,33.164 ],
                  [  0.000, 0.000,34.909 ],
                  [  0.000, 0.000,36.655 ],
                  [  0.000, 0.000,38.400 ],
                  [  0.000, 0.000,40.145 ],
                  [  0.000, 0.000,41.891 ],
                  [  0.000, 0.000,43.636 ],
                  [  0.000, 0.000,45.382 ],
                  [  0.000, 0.000,47.127 ],
                  [  0.000, 0.000,48.873 ],
                  [  0.000, 0.000,50.618 ],
                  [  0.000, 0.000,52.364 ],
                  [  0.000, 0.000,54.109 ],
                  [  0.000, 0.000,55.855 ],
                  [  0.000, 0.000,57.600 ],
                  [  0.000, 0.000,59.345 ],
                  [  0.000, 0.000,61.091 ],
                  [  0.000, 0.000,62.836 ],
                  [  0.000, 0.000,64.582 ],
                  [  0.000, 0.000,66.327 ],
                  [  0.000, 0.000,68.073 ],
                  [  0.000, 0.000,69.818 ],
                  [  0.000, 0.000,71.564 ],
                  [  0.000, 0.000,73.309 ],
                  [  0.000, 0.000,75.055 ],
                  [  0.000, 0.000,76.800 ],
                  [  0.000, 0.000,78.545 ],
                  [  0.000, 0.000,80.291 ],
                  [  0.000, 0.000,82.036 ],
                  [  0.000, 0.000,83.782 ],
                  [  0.000, 0.000,85.527 ],
                  [  0.000, 0.000,87.273 ],
                  [  0.000, 0.000,89.018 ],
                  [  0.000, 0.000,90.764 ],
                  [  0.000, 0.000,92.509 ],
                  [  0.000, 0.000,94.255 ],
                  [  0.000, 0.000,96.000 ],
                  [  0.000, 0.000,97.745 ],
                  [  0.000, 0.000,99.491 ],
                  [  0.000, 0.000,101.236 ],
                  [  0.000, 0.000,102.982 ],
                  [  0.000, 0.000,104.727 ],
                  [  0.000, 0.000,106.473 ],
                  [  0.000, 0.000,108.218 ],
                  [  0.000, 0.000,109.964 ],
                  [  0.000, 0.000,111.709 ],
                  [  0.000, 0.000,113.455 ],
                  [  0.000, 0.000,115.200 ],
                  [  0.000, 0.000,116.945 ],
                  [  0.000, 0.000,118.691 ],
                  [  0.000, 0.000,120.436 ],
                  [  0.000, 0.000,122.182 ],
                  [  0.000, 0.000,123.927 ],
                  [  0.000, 0.000,125.673 ],
                  [  0.000, 0.000,127.418 ],
                  [  0.000, 0.000,129.164 ],
                  [  0.000, 0.000,130.909 ],
                  [  0.000, 0.000,132.655 ],
                  [  0.000, 0.000,134.400 ],
                  [  0.000, 0.000,136.145 ],
                  [  0.000, 0.000,137.891 ],
                  [  0.000, 0.000,139.636 ],
                  [  0.000, 0.000,141.382 ],
                  [  0.000, 0.000,143.127 ],
                  [  0.000, 0.000,144.873 ],
                  [  0.000, 0.000,146.618 ],
                  [  0.000, 0.000,148.364 ],
                  [  0.000, 0.000,150.109 ],
                  [  0.000, 0.000,151.855 ],
                  [  0.000, 0.000,153.600 ],
                  [  0.000, 0.000,155.345 ],
                  [  0.000, 0.000,157.091 ],
                  [  0.000, 0.000,158.836 ],
                  [  0.000, 0.000,160.582 ],
                  [  0.000, 0.000,162.327 ],
                  [  0.000, 0.000,164.073 ],
                  [  0.000, 0.000,165.818 ],
                  [  0.000, 0.000,167.564 ],
                  [  0.000, 0.000,169.309 ],
                  [  0.000, 0.000,171.055 ],
                  [  0.000, 0.000,172.800 ],
                  [  0.000, 0.000,174.545 ],
                  [  0.000, 0.000,176.291 ],
                  [  0.000, 0.000,178.036 ],
                  [  0.000, 0.000,179.782 ],
                  [  0.000, 0.000,181.527 ],
                  [  0.000, 0.000,183.273 ],
                  [  0.000, 0.000,185.018 ],
                  [  0.000, 0.000,186.764 ],
                  [  0.000, 0.000,188.509 ],
                  [  0.000, 0.000,190.255 ],
                  [  0.000, 0.000,192.000 ],
                  [  0.000, 0.000,193.745 ],
                  [  0.000, 0.000,195.491 ],
                  [  0.000, 0.000,197.236 ],
                  [  0.000, 0.000,198.982 ],
                  [  0.000, 0.000,200.727 ],
                  [  0.000, 0.000,202.473 ],
                  [  0.000, 0.000,204.218 ],
                  [  0.000, 0.000,205.964 ],
                  [  0.000, 0.000,207.709 ],
                  [  0.000, 0.000,209.455 ],
                  [  0.000, 0.000,211.200 ],
                  [  0.000, 0.000,212.945 ],
                  [  0.000, 0.000,214.691 ]
               ];
   }
//  Initializations; called after page is loaded

   function init3dnav() {
     var i;
     var dmf = document.mainform;

     zoomexists   = false;
     showpointers = true;
     showlabels   = true;
     showstrux    = false;

     dmf.pointercb.checked = showpointers;
     dmf.labelcb.checked   = showlabels;
     dmf.struxcb.checked   = showstrux;

     pln[0] =  new SlicePlane(0,"axl",127,0,0,72,dmf.axl_snselect,
                  dmf.axl_groupselect,dmf.axl_structselect,dmf.axl_modality,
                  "axlslice","axlhbar","axlvbar");
     pln[1] =  new SlicePlane(1,"sag",127,0,0,70,dmf.sag_snselect,
                  dmf.sag_groupselect,dmf.sag_structselect,dmf.sag_modality,
                  "sagslice","saghbar","sagvbar");
     pln[2] =  new SlicePlane(2,"cor",124,0,0,51,dmf.cor_snselect,
                  dmf.cor_groupselect,dmf.cor_structselect,dmf.cor_modality,
                  "corslice","corhbar","corvbar");

     initgeomh(pln,axl,sag,cor);

     redrawSimages();   // draw initial slices
     pln[0].updatelvlind();
     pln[1].updatelvlind();
     pln[2].updatelvlind();
  }

  function close3dnav() {  // cleanup upon leaving
     if( zoomexists ) zoomw.close();
     if( showstrux ) struxw.close();
  }

//  Constructors

  function SlicePlane(isec,ornt,nslice,imodality,igroup,sn,snSelect,
            groupSelect,structSelect,modSelect,imgname,hbarname,vbarname)
  {
     this.initializing = true;
     this.isec = isec;
     this.ornt = ornt;
     this.nslice = nslice;
     this.snSelect = snSelect;
     this.groupSelect = groupSelect;
     this.structSelect = structSelect;
     this.modalitySelect = modSelect;
     this.imgname = imgname;
     this.hbarname = hbarname;
     this.vbarname = vbarname;

     this.populate_snSelect();

     this.sn = 0;
     this.imodality = 0;
     this.changegroup(igroup,true);  // populates the structure Select
     this.changesn(sn,true);
     this.changemodality(imodality,true);

     this.initializing = false;
  }
  SlicePlane.prototype.changesn = function(sn,updateslct) {
     if( sn<0 || sn>this.nslice-1 ) return;
     this.sn = sn;
     this.updateinternals();
     if( !this.initializing ) this.updatelvlind();
     this.updateimages();
     if( showlabels ) this.structSelect.selectedIndex = this.istruct;
     else             this.structSelect.selectedIndex = 0;
     if( updateslct ) this.snSelect.selectedIndex = this.sn;
  };
  SlicePlane.prototype.changegroup = function(igroup,updateslct) {
     var i;
     this.igroup = igroup;
     this.updateinternals();  // get new structure
     this.updateimages();
// update structure Select
     this.structSelect.options.length = 0;  // delete old structures
     for( i=0 ; i<grp[this.igroup].nstruct; i++ )
        this.structSelect.options[this.structSelect.options.length] =
	     new Option(grp[this.igroup].struct[i].name,i.toString());
     if( showlabels ) this.structSelect.selectedIndex = this.istruct;
     else             this.structSelect.selectedIndex = 0;
     if( updateslct ) this.groupSelect.selectedIndex = this.igroup;
  };
  SlicePlane.prototype.changestruct = function(istruct,updateslct) {
     this.istruct = istruct;
     if( this.istruct!=0 ) {
        this.sn = grp[this.igroup].struct[this.istruct].sn[this.isec];
        if( !this.initializing ) this.updatelvlind();
        this.updateimages();
        this.snSelect.selectedIndex = this.sn;
     }
     if( updateslct ) {
        if( showlabels ) this.structSelect.selectedIndex = this.istruct;
        else             this.structSelect.selectedIndex = 0;
     }
  };
  SlicePlane.prototype.changemodality = function(imod,updateslct) {
     this.imodality = imod;
     this.updateimages();
     if( updateslct ) this.modalitySelect.selectedIndex = this.imodality;
  };
  SlicePlane.prototype.updateimages = function() {
     var modality;
     if(      this.imodality==0 ) modality = "gr";
     else if( this.imodality==1 ) modality = "mr";
     else if( this.imodality==2 ) modality = "fg";
     else if( this.imodality==3 ) modality = "gr-fg";
     else if( this.imodality==4 ) modality = "mr-fg";
     this.img0  = modality + "/" + this.ornt + "/" + charSN(this.sn) + ".png";
     this.img0z = this.img0;
     if( this.istruct!=0 ) {  // structure visible
        this.imgp  = modality + "/" + this.ornt + "p" + this.igroup.toString() + "/"
	                      + charSN(this.sn) + ".png" ;
        this.imgpz = this.imgp;
     } else {
        this.imgp  = null;
        this.imgpz = null;
     }
  };
  SlicePlane.prototype.updateinternals = function() {
     var i;
     for( i=0 ; i<grp[this.igroup].nstruct ; i++ )  // update istruct
        if( grp[this.igroup].struct[i].sn[this.isec]==this.sn ) break;
     if( i<grp[this.igroup].nstruct ) this.istruct = i;
     else                             this.istruct = 0;
  };
  SlicePlane.prototype.updatelvlind = function() {
     if( this.isec==0 ) {
        pln[1].updatevbar(this.sn); // sagittal vertical
        pln[2].updatevbar(this.sn); // coronal  vertical
     } else if( this.isec==1 ) {
	pln[0].updatehbar(this.sn); // axial    horizontal
	pln[2].updatehbar(this.sn); // coronal  horizontal
     } else if( this.isec==2 ) {
	pln[0].updatevbar(this.sn); // axial    vertical
	pln[1].updatehbar(this.sn); // sagittal horizontal
     }
  };
  SlicePlane.prototype.updatehbar = function(sn) {
     document.images[this.hbarname].src = "hbar/" + charSN(this.hi[sn]) + ".png";
  };
  SlicePlane.prototype.updatevbar = function(sn) {
     document.images[this.vbarname].src = "vbar/" + charSN(this.vi[sn]) + ".png";
  };
  SlicePlane.prototype.populate_snSelect = function() {
     var slct = this.snSelect;
     slct.options.length = 0;  // zero it out first
     for( var i = 0 ; i < this.nslice ; i++ )
        slct.options[slct.options.length] = new Option(i.toString(),i.toString());
  };

  function charSN( ii ) {
     if(      ii<10  ) return( "00" + ii );
     else if( ii<100 ) return( "0"  + ii );
     else              return( ""   + ii );
  }


//  General utilities

  function newSN(iplane,sn,updatesn) {
     pln[iplane].changesn(sn,updatesn);
     newSimage(iplane);
  }

  function newSimage(iplane) {
     var plnc = pln[iplane];
     if( showpointers && plnc.imgp!=null ) document.images[plnc.imgname].src = plnc.imgp;
     else                                  document.images[plnc.imgname].src = plnc.img0;
     newZoom(iplane);
  }

  function incrementSlice(iplane,incr) {
     newSN(iplane,pln[iplane].sn+incr,true);
  }

  function redrawSimages() {
     for( var i = 0 ; i < 3 ; i++ ) newSimage(i);
  }

  function nSl(iaxl,isag,icor) {
     if( iaxl>=0 ) newSN(0,iaxl,true);
     if( isag>=0 ) newSN(1,isag,true);
     if( icor>=0 ) newSN(2,icor,true);
  }

  function groupSelect(iplane) {  // called by Select event handler
     var slctgrp = pln[iplane].groupSelect;
     pln[iplane].changegroup(slctgrp.selectedIndex,false); // don't change Select
     newSimage(iplane);
  }

  function groupChange(iplane,igroup) {
     pln[iplane].changegroup(igroup,true); // update Select accordingly
     newSimage(iplane);
  }

  function structureSelect(iplane) {
     var slctstr = pln[iplane].structSelect;
     pln[iplane].changestruct(slctstr.selectedIndex,false);
     newSimage(iplane);
  }

  function structureChange(iplane,istruct) {
     pln[iplane].changestruct(istruct,true);
     newSimage(iplane);
  }

  function modalitySelect(iplane) {
     var slctmod = pln[iplane].modalitySelect;
     pln[iplane].changemodality(slctmod.selectedIndex,false);
     newSimage(iplane);
  }

  function modalityChange(iplane,imod) {
     pln[iplane].changemodality(imod,true);
     newSimage(iplane);
  }

  function modalityglobal(slctg) {
     for( var i = 0 ; i<3 ; i++ ) modalityChange(i,slctg.selectedIndex);
  }

  function sliceSelect(iplane) {
     newSN(iplane,pln[iplane].snSelect.selectedIndex,false);
  }

  function syncronize(iplane) {
     var plnc = pln[iplane];
     for( var i = 0 ; i<3 ; i++ ) {
        if( i==iplane ) continue;
	pln[i].changegroup(plnc.igroup,true);
	pln[i].changestruct(plnc.istruct,true);
	pln[i].changemodality(plnc.imodality,true);
	newSimage(i);
     }
  }

  function sliceZoom() {
     for( var i = 0 ; i < document.mainform.zoomrb.length ; i++ )
        if( document.mainform.zoomrb[i].checked ) break;
     zoomiplane = i;
     if( zoomexists ) newZoom(i);
     else             createzoomwindow();
  }

  function newZoom(iplane) {
     if( zoomexists && iplane==zoomiplane ) {
        if( showpointers && pln[iplane].imgpz!=null )
           zoomw.document.zoomimg.src = pln[iplane].imgpz;
	else
	   zoomw.document.zoomimg.src = pln[iplane].img0z;
     }
  }

  function createzoomwindow() { // request new window and wait for it to load
     zoomw = window.open("zoom.htm","zoomwin","width=535,height=560");
  }

  function zoomloaded() {  // load the real stuff
     var imgsrc;
     zoomexists = true;
     if( showpointers && pln[zoomiplane].imgpz!=null ) imgsrc = pln[zoomiplane].imgpz;
     else                                              imgsrc = pln[zoomiplane].img0z;
     zoomw.document.zoomimg.src = imgsrc;
  }
  function zoomclosed() {
     zoomexists = false;
     for( var i = 0 ; i < document.mainform.zoomrb.length ; i++ )
        document.mainform.zoomrb[i].checked = false;
  }

  function pointerCheck(cb) {
     showpointers = cb.checked;
     redrawSimages();
  }

  function labelCheck(cb) {
     showlabels = cb.checked;
     for( var i = 0 ; i < 3 ; i++ ) pln[i].changegroup(pln[i].igroup,false);
  }

  function struxCheck(cb) {
     showstrux = cb.checked;
     if( showstrux ) createstrlwindow();
     else            struxw.close();
  }

  function createstrlwindow() {
     struxw = window.open("strl.htm","strlwin",
                          "width=700,height=400,resizable,scrollbars");
  }

  function strlwindowclosed() {
     showstrux = false;
     document.mainform.struxcb.checked = false;
  }

  function strlClick(igrp,istruct) {
     for( var i = 0 ; i<3 ; i++ ) {
        pln[i].changegroup(igrp,true);
        pln[i].changestruct(istruct,true);
        newSimage(i);
     }
  }

  function sliceClick(e,iplane) {
     var xc = new Array(2);
     var x = new Array(3);
     determineCoords(e,xc);
//   window.status="coords "+xc[0]+","+xc[1];
     if( iplane==0 ) {
        for( var k = 0 ; k<3 ; k++ ) x[k] = axl.sd[0][k]+xc[0]*axl.n1[k]+xc[1]*axl.n2[k];
        var sagn = find_nearslice( x,0,sag.sd );
        var corn = find_nearslice( x,2,cor.sd );
        nSl( -1,sagn,corn );
     } else if( iplane==1 ) {
        for( var k = 0 ; k<3 ; k++ ) x[k] = sag.sd[0][k]+xc[0]*sag.n1[k]+xc[1]*sag.n2[k];
        var axln = find_nearslice( x,1,axl.sd );
        var corn = find_nearslice( x,2,cor.sd );
        nSl( axln,-1,corn );
     } else if( iplane==2 ) {
        for( var k = 0 ; k<3 ; k++ ) x[k] = cor.sd[0][k]+xc[0]*cor.n1[k]+xc[1]*cor.n2[k];
        var axln = find_nearslice( x,1,axl.sd );
        var sagn = find_nearslice( x,0,sag.sd );
        nSl( axln,sagn,-1 );
     }
  }

  function find_nearslice( x,isd,sd ) {
     var imin;
     var dst;
     var dstmin = 1.0e10;
     for( var i=0 ; i<sd.length ; i++ ) {
        dst = Math.abs( x[isd]-sd[i][isd] );
        if( dst<dstmin ) {
  	   imin   = i;
	   dstmin = dst;
        }
     }
     return imin;
  }

  function determineCoords(e,x) {
    var eloc;
    if( e ) eloc = e;
    else    eloc = window.event;
    if( eloc.layerX ) {
      x[0] = eloc.layerX;
      x[1] = eloc.layerY;
    } else if( eloc.offsetX ) {
      x[0] = eloc.offsetX;
      x[1] = eloc.offsetY;
    } else {
      x[0] = 0;
      x[1] = 0;
    }
    if( x[0]<0 ) x[0] = 0;
    if( x[0]>255 ) x[0] = 255;
    if( x[1]<0 ) x[1] = 0;
    if( x[1]>255 ) x[1] = 255;
  }
