<!--//
// This file contains the gallery slideshow JavaScript object.
function gallery( _name, _imageCount, _timeout ) {

    // attributes
    this.imageCount = _imageCount;
    this.timeout = _timeout;

    this.lastMousedOverGalleryPanel = 0;
    this.activeGalleryPanel = 0;
    this.galleryPaused = true;
    this.galleryTimeOutId = 0;
    this.preMOpauseState = this.galleryPaused;
    this.name = _name;

    // methods
    this.hideGalleryPanel = function( panelId ) {
        hide( "_gallery_panel_" + panelId );
    }

    this.showGalleryPanel = function( panelId ) {
        show( "_gallery_panel_" + panelId );
    }

    this.displayGalleryPanel = function( panelId ) {
        // hide all panels which are not the current one
        for ( var i = 0; i < this.imageCount + 1; i++ ) {
             if ( i != panelId ) {
                 this.hideGalleryPanel( i );
             } else {
                 this.showGalleryPanel( i );
             }
        }
    }

    this.clickGalleryPanel = function( panelId ) {
        this.stopGallerySlideShow();
        this.preMOpauseState = true;        
        this.activeGalleryPanel = panelId;
        this.displayGalleryPanel( panelId );
    }

    this.mouseOverGalleryPanel = function( panelId ) {
        this.preMOpauseState = this.galleryPaused;
        this.displayGalleryPanel( panelId )
        this.lastMousedOverGalleryPanel = panelId;
        this.stopGallerySlideShow();
    }

    this.mouseOutGalleryPanel = function() {
        this.galleryPaused = this.preMOpauseState;
        this.displayGalleryPanel( this.activeGalleryPanel );
        if ( !this.galleryPaused ) {
            this.stopGallerySlideShow();
            this.galleryPaused = false;
            this.playSlideShow();
        }
    }

    this.startGallerySlideShow = function() {
        if ( this.imageCount < 1 ) {
            return;
        }

        if ( !this.galleryPaused ) {
            return;
        }
        this.galleryPaused = false;
        this.playSlideShow();
    }

    this.stopGallerySlideShow = function () {
        clearTimeout( this.galleryTimeOutId );
        this.galleryPaused = true;
    }

    this.loop = function() {
        this.activeGalleryPanel++;
        if ( this.activeGalleryPanel > 5 || this.activeGalleryPanel > this.imageCount ) {
            this.activeGalleryPanel = 0;
        }
        this.displayGalleryPanel( this.activeGalleryPanel );
        this.playSlideShow();
    }

    this.playSlideShow = function() {
        if ( !this.galleryPaused ) {
            this.galleryTimeOutId = setTimeout( this.name + '.loop()', this.timeout );
        }
    }
}

//-->

