// Script written by QDigital. Copyright 2007. Redistribution prohibited.
// Create our array for saving the current values of images on the page
var current_locations = {};

// Function to load image on screen
function load_image (image_id, image_array) {
// Grab the current index for this image
current_location = current_locations[image_id] - 1;
// Determine if we have to prefix our image
if (use_secondary == true) {
path_addon = 'http://www.bestrealtyfinder.com/engine/file_writing/file_uploads/';
image_addon = 'thumbnails/display_';
// Set our new source link
link_name = image_id + "_href";
document.getElementById(link_name).href = path_addon + 'thumbnails/full_' + image_array[current_location];
myLightbox.updateImageList();
} else {
path_addon = '';
image_addon = '';
}
// Set our new source file
document.getElementById(image_id).src = path_addon + image_addon + image_array[current_location];
}

// Function to cycle to the next image.
function next_image (image_id, image_array) {
// Make sure it is an array
if (isArray(image_array) == false)
return;
// See if we need to set our current location if it is undefined
if (current_locations[image_id] == null)
current_locations[image_id] = 1;
// Grab our current array location from our saved array
next_number = current_locations[image_id]+1;
// Now make sure our next array index exists, if we go over. reset the array
if (next_number > image_array.length)
next_number = 1;
// Now set our new location
current_locations[image_id] = next_number;
// Display the next image
load_image(image_id, image_array);
}

// Function to cycle to the next image.
function prev_image (image_id, image_array) {
// Make sure it is an array
if (isArray(image_array) == false)
return;
// See if we need to set our current location if it is undefined
if (current_locations[image_id] == null)
current_locations[image_id] = 1;
// Grab our current array location from our saved array
prev_number = current_locations[image_id]-1;
// Now make sure our prev array index exists, if we go over. reset the array
if (prev_number < 1)
prev_number = image_array.length;
// Now set our new location
current_locations[image_id] = prev_number;
// Display the prev image
load_image(image_id, image_array);
}

// To determine if an object is an array or not
function isArray (obj) {
//returns true is it is an array
if (obj.constructor.toString().indexOf('Array') == -1)
return false;
else
return true;
}