﻿// NOTE: 'bannerslideshow_images_list_Left' and 'bannerslideshow_images_list_Right' are generated in Index.aspx.cs and PtrpColumns.master.cs.

// Current image path for Left and Right banner slideshow images.
var bannerslideshow_currentimagepath_Left = '';
var bannerslideshow_currentimagepath_Right = '';

// Last image random number for Left and Right banner slideshow images.
var bannerslideshow_lastimgnum_Left = -1;
var bannerslideshow_lastimgnum_Right = -1;

// Slideshow timer delay.
var bannerslideshow_timer = 15000;  // 15 seconds

// Variable to hold the returned setTimeout() object.
var bannerslideshow_timeout_var = null;

// Variable to mark whether or not the banner slideshow image preload has executed.
var exec_preload_bannerslideshow_images = false;

// Internal bannerslideshow_Run() storage variables.
var _bannerslideshow_imgidLeft = null;
var _bannerslideshow_imgsizeLeft = null;
var _bannerslideshow_imgidRight = null;
var _bannerslideshow_imgsizeRight = null;


function bannerslideshow_GetImageCount(direction, size)
{
    if (direction == 'Left')
    {
        return (bannerslideshow_images_list_Left[size].length);
    }
    //else if (direction == 'Right')
    return (bannerslideshow_images_list_Right[size].length);
}

// Preload the banner slideshow images.
function bannerslideshow_PreloadImages()
{
    if (document.images && !exec_preload_bannerslideshow_images)
    {
        preload_image_object = new Image();

        for (var i = 0; i < bannerslideshow_images_list_Left['large'].length; i++)
        {
            preload_image_object.src = bannerslideshow_images_list_Left['large'][i];
            preload_image_object.src = bannerslideshow_images_list_Left['large'][i].replace('.jpg', '_bw.jpg');
        }
        for (var i = 0; i < bannerslideshow_images_list_Left['medium'].length; i++)
        {
            preload_image_object.src = bannerslideshow_images_list_Left['medium'][i];
            preload_image_object.src = bannerslideshow_images_list_Left['medium'][i].replace('.jpg', '_bw.jpg');
        }
        for (var i = 0; i < bannerslideshow_images_list_Left['small'].length; i++)
        {
            preload_image_object.src = bannerslideshow_images_list_Left['small'][i];
            preload_image_object.src = bannerslideshow_images_list_Left['small'][i].replace('.jpg', '_bw.jpg');
        }

        for (var i = 0; i < bannerslideshow_images_list_Right['large'].length; i++)
        {
            preload_image_object.src = bannerslideshow_images_list_Right['large'][i];
            preload_image_object.src = bannerslideshow_images_list_Right['large'][i].replace('.jpg', '_bw.jpg');
        }
        for (var i = 0; i < bannerslideshow_images_list_Right['medium'].length; i++)
        {
            preload_image_object.src = bannerslideshow_images_list_Right['medium'][i];
            preload_image_object.src = bannerslideshow_images_list_Right['medium'][i].replace('.jpg', '_bw.jpg');
        }
        for (var i = 0; i < bannerslideshow_images_list_Right['small'].length; i++)
        {
            preload_image_object.src = bannerslideshow_images_list_Right['small'][i];
            preload_image_object.src = bannerslideshow_images_list_Right['small'][i].replace('.jpg', '_bw.jpg');
        }

        exec_preload_bannerslideshow_images = true;
    }

    return;
}


// NOTE: By default, we display the B&W image ... because the Color image is only used when the image is 'large'
//       (i.e., the side is showing).  Since images are stored in bannerslideshow_images_list_Left and
//       bannerslideshow_images_list_Right without their corresponding B&W equivalents (example img1.jpg, img2.jpg, ...),
//       we use the JavaScript "replace('.jpg', '_bw.jpg')" to load the B&W image as necessary.
function bannerslideshow_RandomizeStart(imgsizeLeft, imgsizeRight)
{
    var randidxLeft = 0;

    do
    {
        randidxLeft = common_RandBetween(0, bannerslideshow_images_list_Left[imgsizeLeft].length);
    }
    while (randidxLeft == bannerslideshow_lastimgnum_Left);

    if (imgsizeLeft == 'large')
    {
        bannerslideshow_currentimagepath_Left = bannerslideshow_images_list_Left[imgsizeLeft][randidxLeft];
    }
    else
    {
        bannerslideshow_currentimagepath_Left = bannerslideshow_images_list_Left[imgsizeLeft][randidxLeft].replace('.jpg', '_bw.jpg');
    }

    var randidxRight = 0;

    do
    {
        randidxRight = common_RandBetween(0, bannerslideshow_images_list_Right[imgsizeRight].length);
    }
    while (randidxRight == bannerslideshow_lastimgnum_Right);

    if (imgsizeRight == 'large')
    {
        bannerslideshow_currentimagepath_Right = bannerslideshow_images_list_Right[imgsizeRight][randidxRight];
    }
    else
    {
        bannerslideshow_currentimagepath_Right = bannerslideshow_images_list_Right[imgsizeRight][randidxRight].replace('.jpg', '_bw.jpg');
    }

    return;
}


function bannerslideshow_Run(imgidLeft, imgsizeLeft, imgidRight, imgsizeRight)
{
    if (document.images)
    {
        // Stop the current execution of the slideshow.
        bannerslideshow_Stop();

        // Randomize the current banner slideshow images.
        bannerslideshow_RandomizeStart(imgsizeLeft, imgsizeRight);

        // Display the current left banner slideshow image.
        document.getElementById(imgidLeft).style.backgroundImage = 'url(' + bannerslideshow_currentimagepath_Left + ')';

        // Display the current right banner slideshow image.
        document.getElementById(imgidRight).style.backgroundImage = 'url(' + bannerslideshow_currentimagepath_Right + ')';

        // Set the banner slideshow to switch image based on the image type.
        bannerslideshow_timeout_var = setTimeout("bannerslideshow_Run('" + imgidLeft + "', '" + imgsizeLeft + "', '" + imgidRight + "', '" + imgsizeRight + "');", bannerslideshow_timer);

        // Store the banner slideshow restart variables.
        _bannerslideshow_imgidLeft = imgidLeft;
        _bannerslideshow_imgsizeLeft = imgsizeLeft;
        _bannerslideshow_imgidRight = imgidRight;
        _bannerslideshow_imgsizeRight = imgsizeRight;
    }

    return;
}


function bannerslideshow_Stop()
{
    if (document.images)
    {
        if (bannerslideshow_timeout_var != null)
        {
            clearTimeout(bannerslideshow_timeout_var);
            bannerslideshow_timeout_var = null;
        }
    }

    return;
}


function _bannerslideshow_Restart()
{
    if (document.images)
    {
        bannerslideshow_timeout_var = setTimeout("bannerslideshow_Run('" + _bannerslideshow_imgidLeft + "', '" + _bannerslideshow_imgsizeLeft + "', '" + _bannerslideshow_imgidRight + "', '" + _bannerslideshow_imgsizeRight + "');", bannerslideshow_timer);
    }

    return;
}


function bannerslideshow_OnMouseOver(toggleblackwhiteimg, jsObj)
{
    jsObj.style.cursor = 'pointer';

    if (toggleblackwhiteimg && (jsObj.style.backgroundImage.indexOf('_bw.jpg') != -1))
    {
        bannerslideshow_Stop();

        jsObj.style.backgroundImage = jsObj.style.backgroundImage.replace('_bw.jpg', '.jpg');
    }

    return (true);
}


function bannerslideshow_OnMouseOut(toggleblackwhiteimg, jsObj)
{
    jsObj.style.cursor = 'default';

    if (toggleblackwhiteimg && (jsObj.style.backgroundImage.indexOf('_bw.jpg') == -1))
    {
        _bannerslideshow_Restart();

        jsObj.style.backgroundImage = jsObj.style.backgroundImage.replace('.jpg', '_bw.jpg');
    }

    return (true);
}
