var pwswind_note = '<table>';
    pwswind_note += '<tr>';
    pwswind_note += '<td><p style="text-align:justify">';
    pwswind_note += 'The image depicts the measured (red) and the University of Alaska, Anchorage 4-km WRF model-simulated (black) surface winds in the Prince William Sound region. The direction the arrow points represents the direction towards which the wind blows. The length of the arrow represents the wind speed (in meters per second), which is also shown in color. The measurement locations are indicated by white dots.  <br<br>This image is updated hourly. At each hour, for example 8:00, the image for the previous hour, 7:00 in this example, will be posted. Some observations can take a few hours to get into the system, so check images from previous hours for more complete data coverage.  <br><br>Move the mouse over an observing station to see the geographic coordinates of the station, as well as the wind speed and direction (from which the wind blows) at the time displayed on the image. Click on an observing station in an image to see time series of wind speed and direction for the previous 48 hours, along with predictions for the closest land or sea model grid point as appropriate, for a 96-hour window around the image time. Click anywhere else within the model domain to see wind speed and direction for a 96-hour window centered on the time of the latest model run. The animation (click the link below the image) shows the surface winds during the past 48 hours and the forecast winds for the upcoming 24 hours.<br><br>';
    pwswind_note += '</p></td>';
    pwswind_note += '</tr>';
    pwswind_note += '</table>';

var stopAnimation = false;
var starthr = 0;
var animatedTimes = 0; //safe guard

/*
function doGetWRFLatestDate()
{
  var option = "iname=/myocean/PWS/bin/wind/lastupdate" ;
  xmlPost('/PWS/servlet/GetLastDate', option, getWRFLastDateHandler);
}

function getWRFLastDateHandler()
{
  alert('doWRFLatestDateHandler');
  // Make sure the request is loaded (readyState = 4)
  if (req.readyState == 4)
  {
    alert('doWRFLatestDateHandler(): 4');
    // Make sure the status is "OK"
    if (req.status == 200)
    {
      alert('doWRFLatestDateHandler(): 200 - req.responseXML.xml = ' + req.responseXML.xml);
      var notes = req.responseXML.getElementsByTagName('note');
      var noteNode = notes.item(0);
      var date = noteNode.firstChild.nodeValue;
      alert('date = ' + date);
      if (date != "N/A")
      {
        doDisplayWRF(date);
      }
    } //200
    else
    {
      alert("doWRFPlotHandler()::There was a problem retrieving the XML data:\n" + req.statusText);
    }
  }
}
*/

function doSelectWindDate(what)
{
  //alert('doSelectWindDate()');
  var val = what.value;
  var year = val.substring(0,4);
  var month = val.substring(4,6); 
  var day = val.substring(6,8); 
  var time = val.substring(8,10); 

  document.pwsform.selectedHour.value = what.selectedIndex;

  var datestr = month + '/' + day + '/' + year + ' ' + time + ':00:00';
  var tablehtml = '<table width="100%">';
  tablehtml += '<tr>';
  tablehtml += '<td class="bluebold10" align="center">';
  tablehtml += 'PWS Realtime Wind Product';
  tablehtml += '</td>';
  tablehtml += '</tr>';
  tablehtml += '<tr>';
  tablehtml += '<td align="center" class="bold10" id="wtitle" name="wtitle">';
  tablehtml += 'Wind for ' + datestr + ' GMT Time';
  tablehtml += '</td>';
  tablehtml += '</tr>';
  tablehtml += '</table>';
  setInnerHTML('description', tablehtml);

  var iname = '/repository/PWSwind/map/2009/PWSwind_' + val + '.png';
  setImage('pwsimage', 'visible', iname);
}

function showSubImageWind(station)
{
  //alert('showSubImageWind():: station = ' + station);
  var year = document.pwsform.selectedYear.value-0;
  var month = document.pwsform.selectedMonth.value-0;
  var day = document.pwsform.selectedDay.value-0;
  var hour = document.pwsform.selectedHour.value-0;

  var val = '' + year + pad(month,2) + pad(day,2) + pad(hour,2);

  var url = 'http://ourocean.jpl.nasa.gov/repository/PWSwind/timeseries/' + station + '/' + year + '/TS_' + station + '_' + val + '.png';
  //alert('showSubImageWind():: url = ' + url);
  popWindow=open(url,'popWindow','resizable=yes,width=580,height=480,scrollbars=yes');
  if (popWindow.opener == null)
    popWindow.opener = self;
  else
    popWindow.focus();
}

function doStartAnimate()
{
  //alert('doStartAnimate()::start');
  setDisable('start', true);
  setDisable('stop', false);
  setDisable('pause', false);
  setDisable('resume', true);
  animatedTimes = 0; //safe guard
  stopAnimation = false;
  starthr = document.pwsform.selectedHour.value; 
  doAnimation();
}

function doStopAnimate()
{
  //alert('doStopAnimate()');
  stopAnimation = true;
  setDisable('start', false);
  setDisable('stop', true);
  setDisable('pause', true);
  setDisable('resume', true);
  var year = document.pwsform.selectedYear.value;
  var month = document.pwsform.selectedMonth.value;
  var day = document.pwsform.selectedDay.value; 
  starthr = document.pwsform.selectedHour.value; 

  iname = '/repository/PWSwind/map/2009/PWSwind_' + year + pad(month,2) + pad(day,2) + pad(starthr,2) + '.png';
  document.getElementById("pwsimage").src = iname;
}

function doResumeAnimate()
{
  //alert('doResumeAnimate()');
  setDisable('start', true);
  setDisable('stop', false);
  setDisable('pause', false);
  setDisable('resume', true);
  
  stopAnimation = false;
  doAnimation();
}

function doPauseAnimate()
{
  //alert('doPauseAnimate()');
  stopAnimation = true;
  setDisable('start', true);
  setDisable('stop', false);
  setDisable('pause', true);
  setDisable('resume', false);
}

function doAnimation()
{
  if (stopAnimation) return;

  if (animatedTimes++ == 240)
  {
    doStopAnimate();
    return;
  }

  var year = document.pwsform.selectedYear.value;
  var month = document.pwsform.selectedMonth.value;
  var day = document.pwsform.selectedDay.value; 
  var llength=document.getElementById("datelist").length;

  iname = '/repository/PWSwind/map/2009/PWSwind_' + year + pad(month,2) + pad(day,2) + pad(starthr,2) + '.png';
  document.getElementById("pwsimage").src = iname;
  //alert(iname);
  starthr++;
  if ((starthr%24 == 0) || (starthr%llength == 0))
    starthr = 0;
  setTimeout("doAnimation()", 500); // every 1/2 seconds
}
