//##########################################################################
//                           * image looper *
//##########################################################################

var PoP_first_image = 1;
var PoP_last_image =  5;

//##########################################################################
// set up images (EX: .jpg .gif .png)

var PoP_image_array = new Array();
PoP_image_array[1] = "http://www.srh.noaa.gov/data/ifps/hgx/GFE/graphics/PoP/PoP00.png";
PoP_image_array[2] = "http://www.srh.noaa.gov/data/ifps/hgx/GFE/graphics/PoP/PoP12.png";
PoP_image_array[3] = "http://www.srh.noaa.gov/data/ifps/hgx/GFE/graphics/PoP/PoP24.png";
PoP_image_array[4] = "http://www.srh.noaa.gov/data/ifps/hgx/GFE/graphics/PoP/PoP36.png";
PoP_image_array[5] = "http://www.srh.noaa.gov/data/ifps/hgx/GFE/graphics/PoP/PoP48.png";

//###################### time variables for loop ###########################
//normal_delay = delay between each image
//dwell_delay = delay between last image and first image

var PoP_current_image = PoP_first_image;
var PoP_image = new Array();
var PoP_normal_delay = 1000;
var PoP_dwell_delay = 3000;
var PoP_delay_increment = 100;
var PoP_delay_max = 8000;
var PoP_delay_min = 10;
var PoP_repeat_delay
var PoP_play_mode = 0;
var PoP_play_status = 0;


for (var i = PoP_first_image; i <= PoP_last_image; i++) {
   PoP_image[i] = new Image();
   PoP_image[i].src = PoP_image_array[i];
}

PoP_browser_name = navigator.appName;
PoP_browser_version = parseInt(navigator.appVersion);
if (PoP_browser_name == "Microsoft Internet Explorer" && PoP_browser_version >= 4) PoP_browser = "ie4";
else if (PoP_browser_name == "Netscape" && PoP_browser_version >= 3) PoP_browser = "n3";
else {
   PoP_browser = "xx";
   document.write("You need Microsoft Internet Explorer 4+ or Netscape Navigator 3+ for this page to work");
}

//##########################################################################
// sets all the modes when page loaded

function PoP_on_load() {
   PoP_current_image = PoP_first_image;
   PoP_play_status = 0;
   PoP_play_mode = 0;
   document.PoP_image.src = PoP_image[PoP_current_image].src;
}

//##########################################################################
// plays animation forward

function PoP_forward_play() {
   PoP_current_image++;
   if (PoP_current_image > PoP_last_image) {
      if (PoP_play_mode == 0) {
         PoP_current_image = PoP_first_image;
         document.PoP_image.src = PoP_image[PoP_current_image].src;
         PoP_repeat_delay = setTimeout("PoP_forward_play()", PoP_normal_delay);
      }
      if (PoP_play_mode == 1) {
         PoP_current_image = PoP_last_image - 1;
         document.PoP_image.src = PoP_image[PoP_current_image].src;
         PoP_repeat_delay = setTimeout("PoP_reverse_play()", PoP_normal_delay);
      }
      if (PoP_play_mode == 2) {
         PoP_current_image = PoP_last_image;
         PoP_stop();
      }
   }
   else {
      if (PoP_current_image == PoP_last_image) {
         document.PoP_image.src = PoP_image[PoP_current_image].src;
         PoP_repeat_delay = setTimeout("PoP_forward_play()", PoP_dwell_delay);
      }
      else {
         document.PoP_image.src = PoP_image[PoP_current_image].src;
         PoP_repeat_delay = setTimeout("PoP_forward_play()", PoP_normal_delay);
      }
   }
}

//##########################################################################
// plays animation in reverse

function PoP_reverse_play() {
   PoP_current_image--;
   if (PoP_current_image < PoP_first_image) {
      if (PoP_play_mode == 0) {
         PoP_current_image = PoP_last_image;
         document.PoP_image.src = PoP_image[PoP_current_image].src;
         PoP_repeat_delay = setTimeout("PoP_reverse_play()", PoP_normal_delay);
      }
      if (PoP_play_mode == 1) {
         PoP_current_image = PoP_first_image + 1;
         document.PoP_image.src = PoP_image[PoP_current_image].src;
         PoP_repeat_delay = setTimeout("PoP_forward_play()", PoP_normal_delay);
      }
      if (PoP_play_mode == 2) {
         PoP_current_image = PoP_first_image;
         PoP_stop();
      }
   }
   else {
      if (PoP_current_image == PoP_first_image) {
         document.PoP_image.src = PoP_image[PoP_current_image].src;
         PoP_repeat_delay = setTimeout("PoP_reverse_play()", PoP_dwell_delay);
      }
      else {
         document.PoP_image.src = PoP_image[PoP_current_image].src;
         PoP_repeat_delay = setTimeout("PoP_reverse_play()", PoP_normal_delay);
      }
   }
}

//##########################################################################
// start forward animation

function PoP_forward() {
   PoP_stop();
   PoP_play_status = 1;
   PoP_forward_play();
}

//##########################################################################
// start reverse animation

function PoP_reverse() {
   PoP_stop();
   PoP_play_status = 1;
   PoP_reverse_play();
}

//##########################################################################
// stops animation

function PoP_stop() {
   if (PoP_play_status == 1) clearTimeout(PoP_repeat_delay);
   PoP_play_status = 0;
}

//##########################################################################
// forward to next image

function PoP_forward_image() {
   PoP_stop();
   if (PoP_current_image == PoP_last_image) PoP_current_image = PoP_first_image;
   else PoP_current_image++;
   document.PoP_image.src = PoP_image[PoP_current_image].src;
}

//##########################################################################
// reverse to previous image

function PoP_reverse_image() {
   PoP_stop();
   if (PoP_current_image == PoP_first_image) PoP_current_image = PoP_last_image;
   else PoP_current_image--;
   document.PoP_image.src = PoP_image[PoP_current_image].src;
}

//##########################################################################
// go to a desired image

function PoP_goto_image(go_to) {
   PoP_stop();
   if (go_to > PoP_last_image) {
      alert("Image " + "does not exsist.");
      PoP_current_image = PoP_last_image;
   }
   else if (go_to < PoP_first_image) {
      alert("Image " + "does not exsist.");
      PoP_current_image = PoP_first_image;
   }
   else PoP_current_image = go_to;
   document.PoP_image.src = PoP_image[PoP_current_image].src;
}

//##########################################################################
// change the normal delay

function PoP_normal_speed(dvdt, delay) {
   if (dvdt == -1) PoP_normal_delay += delay;
   else if (dvdt == 1) PoP_normal_delay -= delay;
   if (PoP_normal_delay > PoP_delay_max) PoP_normal_delay = PoP_delay_max;
   else if (PoP_normal_delay < PoP_delay_min) PoP_normal_delay = PoP_delay_min;
}

//##########################################################################
// change the dwell delay

function PoP_dwell_speed(dvdt, delay) {
   if (dvdt == -1) PoP_dwell_delay += delay;
   else if (dvdt == 1) PoP_dwell_delay -= delay;
   if (PoP_dwell_delay > PoP_delay_max) PoP_dwell_delay = PoP_delay_max;
   else if (PoP_dwell_delay < PoP_delay_min) PoP_dwell_delay = PoP_delay_min;
}

//##########################################################################
// change the play mode

function PoP_change_mode(chmod) {
   PoP_play_mode = chmod;
}

//##########################################################################
// button

function button() {
}

//##########################################################################
