﻿//
// ImageGallery.js
//   for ~/Modules/ImageGallery.ascx
//

var ImageGallery_galleryCount = 0;
var ImageGallery_currentItem = 0;
var ImageGallery_itemWidth = 0;
var ImageGallery_sliding = false;

function ImageGallery_Init() {

    var $divImages = $('div.Images');
    
    var $divFirst = $('div:first', $divImages);
    ImageGallery_itemWidth = $divFirst.width();
    var h = $divFirst.height();

    ImageGallery_galleryCount = $('div', $divImages).size();

    $('div.Gallery').width(ImageGallery_itemWidth).height(h).css({
        'overflow': 'hidden',
        'position': 'relative'
    });
    $divImages.width(ImageGallery_itemWidth * ImageGallery_galleryCount);
    $divImages.css({
        'position': 'absolute'
    });
    $('div', '.Images').show();
    ImageGallery_ShowText();
}

function ImageGallery_moveImage(count) {
    var newItem = ImageGallery_currentItem + count;
    if (!ImageGallery_sliding && newItem >= 0 && newItem < ImageGallery_galleryCount) {
        ImageGallery_sliding = true;
        $('div.Images').animate({ left: '-' + (newItem * ImageGallery_itemWidth) },
                'normal', null, function() {
                    ImageGallery_currentItem = newItem;
                    ImageGallery_ShowText();
                    ImageGallery_sliding = false;
                }
            );
    }
}

function ImageGallery_ShowText() {
    $("div.ImageGallery .Title").html($('div:eq(' + ImageGallery_currentItem + ') span:eq(0)', '.Images').text());
    $("div.ImageGallery .Description").html($('div:eq(' + ImageGallery_currentItem + ') span:eq(1)', '.Images').text());
}

