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

var MaxMin_first_image = 1;
var MaxMin_last_image = 4;

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

var MaxMin_image_array = new Array();
MaxMin_image_array[1] = "http://www.srh.noaa.gov/data/ifps/hgx/GFE/graphics/MaxT/MaxT1.png";
MaxMin_image_array[2] = "http://www.srh.noaa.gov/data/ifps/hgx/GFE/graphics/MinT/MinT2.png";
MaxMin_image_array[3] = "http://www.srh.noaa.gov/data/ifps/hgx/GFE/graphics/MaxT/MaxT2.png";
MaxMin_image_array[4] = "http://www.srh.noaa.gov/data/ifps/hgx/GFE/graphics/MinT/MinT3.png";


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

var MaxMin_current_image = MaxMin_first_image;
var MaxMin_image = new Array();
var MaxMin_normal_delay = 1000;
var MaxMin_dwell_delay = 3000;
var MaxMin_delay_increment = 100;
var MaxMin_delay_max = 8000;
var MaxMin_delay_min = 10;
var MaxMin_repeat_delay
var MaxMin_play_mode = 0;
var MaxMin_play_status = 0;


for (var i = MaxMin_first_image; i <= MaxMin_last_image; i++) {
   MaxMin_image[i] = new Image();
   MaxMin_image[i].src = MaxMin_image_array[i];
}

MaxMin_browser_name = navigator.appName;
MaxMin_browser_version = parseInt(navigator.appVersion);
if (MaxMin_browser_name == "Microsoft Internet Explorer" && MaxMin_browser_version >= 4) MaxMin_browser = "ie4";
else if (MaxMin_browser_name == "Netscape" && MaxMin_browser_version >= 3) MaxMin_browser = "n3";
else {
   MaxMin_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 MaxMin_on_load() {
   MaxMin_current_image = MaxMin_first_image;
   MaxMin_play_status = 0;
   MaxMin_play_mode = 0;
   document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
}

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

function MaxMin_forward_play() {
   MaxMin_current_image++;
   if (MaxMin_current_image > MaxMin_last_image) {
      if (MaxMin_play_mode == 0) {
         MaxMin_current_image = MaxMin_first_image;
         document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
         MaxMin_repeat_delay = setTimeout("MaxMin_forward_play()", MaxMin_normal_delay);
      }
      if (MaxMin_play_mode == 1) {
         MaxMin_current_image = MaxMin_last_image - 1;
         document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
         MaxMin_repeat_delay = setTimeout("MaxMin_reverse_play()", MaxMin_normal_delay);
      }
      if (MaxMin_play_mode == 2) {
         MaxMin_current_image = MaxMin_last_image;
         MaxMin_stop();
      }
   }
   else {
      if (MaxMin_current_image == MaxMin_last_image) {
         document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
         MaxMin_repeat_delay = setTimeout("MaxMin_forward_play()", MaxMin_dwell_delay);
      }
      else {
         document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
         MaxMin_repeat_delay = setTimeout("MaxMin_forward_play()", MaxMin_normal_delay);
      }
   }
}

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

function MaxMin_reverse_play() {
   MaxMin_current_image--;
   if (MaxMin_current_image < MaxMin_first_image) {
      if (MaxMin_play_mode == 0) {
         MaxMin_current_image = MaxMin_last_image;
         document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
         MaxMin_repeat_delay = setTimeout("MaxMin_reverse_play()", MaxMin_normal_delay);
      }
      if (MaxMin_play_mode == 1) {
         MaxMin_current_image = MaxMin_first_image + 1;
         document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
         MaxMin_repeat_delay = setTimeout("MaxMin_forward_play()", MaxMin_normal_delay);
      }
      if (MaxMin_play_mode == 2) {
         MaxMin_current_image = MaxMin_first_image;
         MaxMin_stop();
      }
   }
   else {
      if (MaxMin_current_image == MaxMin_first_image) {
         document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
         MaxMin_repeat_delay = setTimeout("MaxMin_reverse_play()", MaxMin_dwell_delay);
      }
      else {
         document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
         MaxMin_repeat_delay = setTimeout("MaxMin_reverse_play()", MaxMin_normal_delay);
      }
   }
}

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

function MaxMin_forward() {
   MaxMin_stop();
   MaxMin_play_status = 1;
   MaxMin_forward_play();
}

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

function MaxMin_reverse() {
   MaxMin_stop();
   MaxMin_play_status = 1;
   MaxMin_reverse_play();
}

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

function MaxMin_stop() {
   if (MaxMin_play_status == 1) clearTimeout(MaxMin_repeat_delay);
   MaxMin_play_status = 0;
}

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

function MaxMin_forward_image() {
   MaxMin_stop();
   if (MaxMin_current_image == MaxMin_last_image) MaxMin_current_image = MaxMin_first_image;
   else MaxMin_current_image++;
   document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
}

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

function MaxMin_reverse_image() {
   MaxMin_stop();
   if (MaxMin_current_image == MaxMin_first_image) MaxMin_current_image = MaxMin_last_image;
   else MaxMin_current_image--;
   document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
}

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

function MaxMin_goto_image(go_to) {
   MaxMin_stop();
   if (go_to > MaxMin_last_image) {
      alert("Image " + "does not exsist.");
      MaxMin_current_image = MaxMin_last_image;
   }
   else if (go_to < MaxMin_first_image) {
      alert("Image " + "does not exsist.");
      MaxMin_current_image = MaxMin_first_image;
   }
   else MaxMin_current_image = go_to;
   document.MaxMin_image.src = MaxMin_image[MaxMin_current_image].src;
}

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

function MaxMin_normal_speed(dvdt, delay) {
   if (dvdt == -1) MaxMin_normal_delay += delay;
   else if (dvdt == 1) MaxMin_normal_delay -= delay;
   if (MaxMin_normal_delay > MaxMin_delay_max) MaxMin_normal_delay = MaxMin_delay_max;
   else if (MaxMin_normal_delay < MaxMin_delay_min) MaxMin_normal_delay = MaxMin_delay_min;
}

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

function MaxMin_dwell_speed(dvdt, delay) {
   if (dvdt == -1) MaxMin_dwell_delay += delay;
   else if (dvdt == 1) MaxMin_dwell_delay -= delay;
   if (MaxMin_dwell_delay > MaxMin_delay_max) MaxMin_dwell_delay = MaxMin_delay_max;
   else if (MaxMin_dwell_delay < MaxMin_delay_min) MaxMin_dwell_delay = MaxMin_delay_min;
}

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

function MaxMin_change_mode(chmod) {
   MaxMin_play_mode = chmod;
}

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

function button() {
}

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