﻿//************************************************************************************* 
// File     :   mf_mls_gallery.js
// Version  :   1.0
// Requires :   mf_domLibrary_0.1.js, prototype.js
// Author   :   Kyle Weems (ksw)
// Origin   :   mindfly.com
// Created  :   September 17, 2007
// Modified :   September 17, 2007 (ksw)
// Purpose  :   
//*************************************************************************************

// Version History (only for changes of at least 0.0.1 in version number)
// ===============
// Version 1.0   (09/17/2007) - Basic functionality.


//=============================================================================================
// Global Variables
//=============================================================================================
// mlsPhotoGallery should be set to the list that holds the photos used by the MLS gallery.
var mlsPhotoGallery = "imgListingDetail";


//=============================================================================================
// loadMLSGallery()
//=============================================================================================
// Called on page load. Adds the onclick function to the pictures in the mls gallery.
function loadMLSGallery()
{
    // If the list mlsPhotoGallery exists, then...
    if($(mlsPhotoGallery))
    {
        // ...Get an array of all img elements inside the list mlsPhotoGallery
        var mlsPhotos = $(mlsPhotoGallery).getElementsBySelector('img');
        // If any img elements were acquired, then...
        if(mlsPhotos.length)
        {
            // ... cycle through each img.
            for(i=0;i<mlsPhotos.length;i++)
            {
                // For each one, add an id of mlsPhoto_i...
                mlsPhotos[i].id = 'mlsPhoto_'+i;
                // ... and add an onclick event.
                mlsPhotos[i].onclick = function() { changeMLSPhoto(this.id);}
            } // end of for(i=0;i<mlsPhotos) loop
        } // end of if(mlsPhotos.length)
    }// end of if($(mlsPhotoGallery))
} // end of function loadMLSGallery()


//=============================================================================================
// changeMlsPhoto()
//=============================================================================================
// Called by a click on the photos in  the mls gallery. Changes the photo of the top image.
function changeMLSPhoto(photo)
{
    // Replace the 'src' of the img mlsPhoto_0 with that of 'photo'.
    $('mlsPhoto_0').src = $(photo).src;
} // end of function changeMlsPhoto()


// When the script loads, call the function loadMLSGallery()
addLoadEvent(loadMLSGallery);