﻿      rotating_images = new Array();

      //Duplicate these lines here to add new images to the rotation.
      rotating_images.push(new RotatingImage('images/home1.jpg', 'WhatisHHW.aspx'));
      rotating_images.push(new RotatingImage('images/home2.jpg', 'WhyisHHWHarmful.aspx'));
      rotating_images.push(new RotatingImage('images/home3.jpg', 'CommonHHW.aspx'));
      rotating_images.push(new RotatingImage('images/home4.jpg', 'RuleofThumb.aspx'));
      
      var active_image_delay = 4; //in seconds

      var active_image_index = 0

      function rotateImages() {

        //Ensure routine runs only if my_images exists on the page.
        if (!document.getElementById('my_images') || rotating_images.length < 1) return;
        var new_image_code = '';

        new_image = document.createElement('IMG');
        new_image.src = rotating_images[active_image_index].image;
        new_image.border = "0";
        new_image.width = "815";
        new_image.height = "505";
        new_link = document.createElement('A');
        new_link.href = rotating_images[active_image_index].url;

        new_link.appendChild(new_image);


        if (document.getElementById('my_images').hasChildNodes() ) {
          while (document.getElementById('my_images').childNodes.length >= 1 ) {
            document.getElementById('my_images').removeChild(document.getElementById('my_images').firstChild );
          }
        }

        document.getElementById('my_images').appendChild(new_link);

        active_image_index = Math.round(Math.random() * (rotating_images.length - 1));

        setTimeout('rotateImages();',active_image_delay*1000);
      }
      
      function RotatingImage (image_url, url) {
        this.image = image_url;
        this.url = url;
      }


