﻿/// <reference name="MicrosoftAjax.js"/>

var _FADE_RATE = 300;

var _unfadedClients;
var _clientPics;

// Clients init
$(function() {
    // Grab a jquery object containing all client picture img elements
    _clientPics = $('#clientTable img');

    // Initial hide of all images
    _clientPics.hide();

    // Put each client index into the unfaded array
    _unfadedClients = new Array();
    for (var i = 0; i < _clientPics.length; i++) {
        _unfadedClients.push(i);
    }

    // Now start the recursive process to fade them all in
    fadeInRandomClient();
});

// Recurses until out of clients
function fadeInRandomClient() {
    // Pick an index at random from the remaining indices
    var randIdx = Math.floor(Math.random() * (_unfadedClients.length - 1));

    // Fade it in
    _clientPics.eq(_unfadedClients[randIdx]).fadeIn('slow');

    // Remove it from the array of clients remaining to fade
    _unfadedClients[randIdx] = _unfadedClients[_unfadedClients.length - 1];
    _unfadedClients.pop();

    // And recurse, if we're not yet out of clients
    if (_unfadedClients.length != 0) {
        setTimeout(fadeInRandomClient, _FADE_RATE);
    }
}