﻿function WhatADay()
{
    this.index = 0;
    this.ControlID = '';
    this.gallery = new Array();
    this.imgMain = null;
    this.descMain = null;
    this.aNext = null;
    this.aPrev = null;
    this.divThumbs = null;
    
    this.Create = function(ControlID, WADGallery) {
        this.ControlID = ControlID;
        try {
            this.gallery = WADGallery.Images;    
        } catch (e) {
            this.gallery = new Array();
        }
        this.imgMain = document.getElementById('imgMain_' + ControlID);    
        this.descMain = document.getElementById('descMain_' + ControlID);    
        this.aNext = document.getElementById('aNext_' + ControlID);    
        this.aPrev = document.getElementById('aPrev_' + ControlID);    
        this.divThumbs = document.getElementById('divThumbs_' + ControlID);
        
        this.DisplayImage(0);
        this.ConstructThumbs();
    },
    
    this.ConstructThumbs = function() {
        for (var i=0; i<this.gallery.length; i++) {
            var img = document.createElement("IMG");
            var href = document.createElement("A");
            
            img.src= this.gallery[i].Location;
            img.alt = this.gallery[i].Title;
            img.border = "0";
            href.title = this.gallery[i].Title;
            href.href = "javascript:wadGallery_" + this.ControlID + ".DisplayImage(" + i + ");";
            href.appendChild(img);
            this.divThumbs.appendChild(href);      
        }
    },
    
    this.DisplayImage = function(Index) {
        try {
            if ((Index >= 0) && (Index < this.gallery.length)) {
                this.index = Index;
                this.imgMain.src = this.gallery[this.index].Location;
                this.imgMain.alt = this.gallery[this.index].Title;
                if (this.descMain)
                    this.descMain.innerHTML = this.gallery[this.index].Description;
                
                if (this.aPrev) {
                    this.aPrev.style.display = (this.index == 0 ? 'none' : 'block');
                    this.aPrev.href = "javascript:wadGallery_" + this.ControlID + ".DisplayImage(" + (Index - 1) + ");";
                }
                if (this.aNext) {
                    this.aNext.style.display = (this.index < (this.gallery.length - 1) ? 'block' : 'none');
                    this.aNext.href = "javascript:wadGallery_" + this.ControlID + ".DisplayImage(" + (Index + 1) + ");";
                }
            }
        } catch (e) {
            alert(e.message);
        }
    } 
}