// START UFE_ROLLOVER namespace
var ROLLOVER = {

  // START loadRollover function
  // The overall function to load the rollover script.
  loadRollover: function() {
  
    var i;
    var j;
    var image_path = '/images/';
    var image_extension = 'jpg';
    var image_suffix = ['_over', '_out'];
    var image_list = ['about-us','contact-us','customer-login','home','services','testimonials','why-ansercomm','sitemap','home_footer','contact-us_footer','customer-login_footer','privacy-policy','info'];
    var image_container_list = ['sidebar-nav','footer-nav'];

    // START rollOver function
    // This actually performs the image swapping on mouseover/out or tab focus/blur.
    function rollOver() {
      var target_image = this.firstChild; // Locate the image inside the A tag.
      if (target_image.src.indexOf(image_suffix[0]) !== -1 ) { // Change the image to the 'on' or 'off' version.
        target_image.src = target_image.src.replace (image_suffix[0],image_suffix[1]); }
      else {
        target_image.src = target_image.src.replace (image_suffix[1],image_suffix[0]);
      }
    }
    // END rollOver function

    // START preLoad function
    // This loads the array of images and adds the event handler to the links to perform the image rollover effect.
    function preLoad() {
      if (document.images) { // If the browser doesn't support images, don't do it.
        for (i=0; i<image_list.length; i++) { // For each image...
          var the_image = image_list[i];
          for (j=0; j<image_suffix.length; j++) { // Preload its 'on' and 'off' image.
            var suffix = image_suffix[j];
            self[the_image+ '_' + suffix] = new Image();
            self[the_image + '_' + suffix].src = image_path + the_image + suffix + '.' + image_extension;
          }
        }

        for (i=0; i<image_container_list.length; i++) { // For each containing block of links with rollovers...
          if (document.getElementById(image_container_list[i])) { // Make sure the links are actually on the page.
            var link_list = document.getElementById(image_container_list[i]).getElementsByTagName('a'); // Get the list of links in the containing block.
            for (j=0; j<link_list.length; j++) { // Assign the rollover functions to each link.
              link_list[j].onmouseover = rollOver;
              link_list[j].onmouseout = rollOver;
              link_list[j].onfocus = rollOver;
              link_list[j].onblur = rollOver;
            }
          }
        }
      }
    }
    // END preLoad function
  
    preLoad();
  }
  // END loadRollover function

};
// END ROLLOVER namespace

// Add the rollover script to any other scripts designated to run onload.
window.onload = ROLLOVER.loadRollover;