﻿// JScript File

function isDefined(property) {
  return (typeof property != 'undefined');
}

var rolloverInitialized = false;
function rolloverInit() {
  if (!rolloverInitialized && isDefined(document.images)) {
     var bodyId = document.body.id;    // ID of the BODY tag
     // get all images (including all <input type="image">s)
     // use getElementsByTagName() if supported
     var images = new Array();
     if (isDefined(document.getElementsByTagName)) {
        images = document.getElementsByTagName('img');
        var inputs = document.getElementsByTagName('input');
        for (var i = 0; i < inputs.length; i++) {
           if (inputs[i].type == 'image') {
              images[images.length] = inputs[i];
           }
        }
     }

     // otherwise, use document.images and document.forms collections
     // remove if not supporting IE4, Opera 4-5
     else {
        images = document.images;
        inputs = new Array();
        for (var formIndex = 0; formIndex < document.forms.length; formIndex++) {
           for (var elementIndex = 0; elementIndex < document.forms.elements.length; elementIndex++) {
              if (isDefined(document.forms.elements[i].src)) {
                 inputs[inputs.length] = document.forms.elements[i];
              }
           }
        }
     }

     // get all images with '_off.' in src value excepting the one that is for the BODY
     for (var i = 0; i < images.length; i++) {
        if (images[i].src.indexOf('_off.') != -1) {

           // check for BODY image, and turn it 'on' if found
           if (images[i].src.indexOf(bodyId) != -1)
              images[i].src = images[i].src.replace(/_off\./, '_on.');
           else {
           var image = images[i];

           // store the off state filename in a property of the image object
           image.offImage = new Image();
           image.offImage.src = image.src;

           // store the on state filename in a property of the image object
           // (also preloads the on state image)
           image.onImage = new Image();
           image.onImage.imageElement = image;

           // add onmouseover and onmouseout event handlers once the on state image has loaded
           // Safari's onload is screwed up for off-screen images; temporary fix
           if (navigator.userAgent.toLowerCase().indexOf('safari') != - 1) {
              image.onmouseover = function() {
                 this.src = this.onImage.src;
              };
              image.onmouseout = function() {
                 this.src = this.offImage.src;
              };
           }
           else {
              image.onImage.onload = function() {
                 this.imageElement.onmouseover = function() {
                    this.src = this.onImage.src;
                 };
                 this.imageElement.onmouseout = function() {
                    this.src = this.offImage.src;
                 };
              };
           }

           // set src of on state image after defining onload event handler
           // so cached images (that load instantly in IE) will trigger onload
           image.onImage.src = image.src.replace(/_off\./, '_on.');

          }
        }
     }
  }
  rolloverInitialized = true;
}
// call rolloverInit when document finishes loading
if (isDefined(window.addEventListener)) {
   window.addEventListener('load', rolloverInit, false);
}
else if (isDefined(window.attachEvent)) {
   window.attachEvent('onload', rolloverInit);
}


ImageNames = new Object();
ImageNames.length = 19; 
for (counter = 0; counter < 20; counter++) {
    file_number = counter + 1;
    file_name = ("images/gallery_" + file_number + ".jpg");
    ImageNames[counter] = file_name;
}

which_image_loaded = 0;



function changeImage(direction) {
    which_image_loaded += direction;
    if (which_image_loaded < 0)
        which_image_loaded = 19;
    if (which_image_loaded > 19)
    which_image_loaded = 0;
    if (document.images)
        document.myimage.src = ImageNames[which_image_loaded];
}

 var aryImages = new Array(19);
    aryImages[0] = "images/gallery_1.jpg";
    aryImages[1] = "images/gallery_2.jpg";
    aryImages[2] = "images/gallery_3.jpg";
    aryImages[3] = "images/gallery_4.jpg";
    aryImages[4] = "images/gallery_5.jpg";
    aryImages[5] = "images/gallery_6.jpg";
    aryImages[6] = "images/gallery_7.jpg";
    aryImages[7] = "images/gallery_8.jpg";
    aryImages[8] = "images/gallery_9.jpg";
    aryImages[9] = "images/gallery_10.jpg";
    aryImages[10] = "images/gallery_11.jpg";
    aryImages[11] = "images/gallery_12.jpg";
    aryImages[12] = "images/gallery_13.jpg";
    aryImages[13] = "images/gallery_14.jpg";
    aryImages[14] = "images/gallery_15.jpg";
    aryImages[15] = "images/gallery_16.jpg";
    aryImages[16] = "images/gallery_17.jpg";
    aryImages[17] = "images/gallery_18.jpg";
    aryImages[18] = "images/gallery_19.jpg";
    aryImages[19] = "images/gallery_20.jpg";
    
  for (i=0; i < aryImages.length; i++) {
    var preload = new Image();
    preload.src = aryImages[i];
  }

  function swap(imgIndex) {
    document['imgMain'].src = aryImages[imgIndex];
  }
