/**
 * Hugh & McKinnon Javascript Functions
 * ImageX Media, imagexmedia [dot] com
 * Authors: Robert Phillips, mrrjpp [at] gmail [dot] com
 */
 
/**
 * This function provides an alternative way to link to other pages
 * based on the path which is passed to it. This is used exclusively
 * in the rental listings pages.
 */
function hm_gotoAddress(path) {
  this.location.href = path;
};

/**
 * This function provides a way to change the background color of
 * an element.
 */
function hm_changeBackground(element, status) {
  if (status == "rollOut")  { element.style.backgroundColor = '#fff'; };
  if (status == "rollOver") { element.style.backgroundColor = '#edf1f4'; };
};

/**
 * This function provides a thumbnail switching control to the
 * rental listings type.
 */
function hm_changeImage(photos, method) {  
  /* Get the current image being displayed */
  var image_holder  = document.getElementById('listing-photo-display');
  var index_holder  = document.getElementById('listing-photo-index');
  var img_tag       = document.getElementById('listing-photo');
  var current_image = img_tag.src;

  /* Split photos into an array */
  var individual_photos = photos.split(',');
  var total_photos = individual_photos.length - 1;
  
  /* Loop through the array of photos and find the next or previous one */
  for (i = 0; i < individual_photos.length; i++) {
    var split_photo = individual_photos[i].split('>');
    var thumb_path  = split_photo[0];      
    var photo_index = parseInt(split_photo[2]);

    /* Finds the current matching image path */
    if (('http://www.hughmckinnon.com' + thumb_path) == current_image || ('http://hughmckinnon.com' + thumb_path) == current_image) {
      /* Get the next photo and display it */
      if (method == 'next') {
        var next_photo = individual_photos[i + 1].split('>');
        if (next_photo[2] != undefined) {
          image_holder.innerHTML = '<a href="' + next_photo[1] + '" target="_blank"><img src="' + next_photo[0] + '" id="listing-photo" border="0" alt="" /></a>';
          index_holder.innerHTML   = (photo_index + 1) + ' of ' + total_photos;
        };
      };
      
      /* Get the previous photo and display it */
      if (method == 'previous') {
        if (individual_photos[i -1] != undefined) {
          var previous_photo = individual_photos[i -1].split('>');
          image_holder.innerHTML = '<a href="' + previous_photo[1] + '" target="_blank"><img src="' + previous_photo[0] + '" id="listing-photo" border="0" alt="" /></a>';
          index_holder.innerHTML = (photo_index - 1) + ' of ' + total_photos;
        };
      };
    };
  };
};

function hm_changeImage_revise(images, action) {
  
}
