function GalleryImage(p_url, p_image, p_title, p_description)
{
	this.url = p_url;
	this.image = p_image;
	this.title = p_title;
	this.description = p_description;
}

function GalleryImages(p_prevLink, p_prevImage, p_currentLink, p_currentImage, p_title, p_description, p_nextLink, p_nextImage)
{
	this.prevLink = p_prevLink;
	this.prevImage = p_prevImage;
	this.currentLink = p_currentLink;
	this.currentImage = p_currentImage;
	this.title = p_title;
	this.description = p_description;
	this.nextLink = p_nextLink;
	this.nextImage = p_nextImage;
	this.index = 0;
	this.galleryImages = new Dictionary();
}

GalleryImages.prototype.imageNext = function()
{
	if (this.index < this.galleryImages.length - 1)
		this.index++;
	else
		this.index = 0;
	this.updateGalleryImages();
}

GalleryImages.prototype.imagePrevious = function()
{
	if (this.index > 0)
		this.index--;
	else
		this.index = this.galleryImages.length - 1;
	this.updateGalleryImages();
}

GalleryImages.prototype.updateGalleryImages = function()
{
    var images = this.galleryImages;
    var currentIndex = this.index

    if (images.length > 0)
    {
        if (currentIndex == 0)
        {
            if (document.getElementById(this.prevLink) != null && images[images.length - 1].url != null)
                document.getElementById(this.prevLink).href = images[images.length - 1].url;

            var img = document.getElementById(this.prevImage)

            if (img != null)
            {
                img.src = images[images.length - 1].image;
                img.alt = images[images.length - 1].title;
                img.title = images[images.length - 1].title;
            }

            if (document.getElementById(this.currentLink) != null && images[currentIndex].url != null)
                document.getElementById(this.currentLink).href = images[currentIndex].url;

            var img = document.getElementById(this.currentImage)

            if (img != null)
            {
                if (images[currentIndex].image != null)
                    img.src = images[currentIndex].image;

                if (images[currentIndex].title != null)
                {
                    img.alt = images[currentIndex].title;
                    img.title = images[currentIndex].title;
                }
            }

            if (document.getElementById(this.title) != null && images[currentIndex].title != null)
                document.getElementById(this.title).innerHTML = images[currentIndex].title;

            if (document.getElementById(this.description) != null && images[currentIndex].description != null)
                document.getElementById(this.description).innerHTML = images[currentIndex].description;

            if (document.getElementById(this.nextLink) != null && images[currentIndex + 1].url != null)
                document.getElementById(this.nextLink).href = images[currentIndex + 1].url;

            var img = document.getElementById(this.nextImage)

            if (img != null)
            {
                if (images[currentIndex + 1].image != null)
                    img.src = images[currentIndex + 1].image;

                if (images[currentIndex + 1].title != null)
                {
                    img.alt = images[currentIndex + 1].title;
                    img.title = images[currentIndex + 1].title;
                }
            }
        }
        else if (currentIndex == images.length - 1)
        {
            document.getElementById(this.prevLink).href = images[currentIndex - 1].url;
            var img = document.getElementById(this.prevImage)
            img.src = images[currentIndex - 1].image;
            img.alt = images[currentIndex - 1].title;
            img.title = images[currentIndex - 1].title;

            document.getElementById(this.currentLink).href = images[currentIndex].url;
            var img = document.getElementById(this.currentImage)
            img.src = images[currentIndex].image;
            img.alt = images[currentIndex].title;
            img.title = images[currentIndex].title;
            document.getElementById(this.title).innerHTML = images[currentIndex].title;
            document.getElementById(this.description).innerHTML = images[currentIndex].description;

            document.getElementById(this.nextLink).href = images[0].url;
            var img = document.getElementById(this.nextImage)
            img.src = images[0].image;
            img.alt = images[0].title;
            img.title = images[0].title;
        }
        else
        {
            if (images[currentIndex - 1].url != null)
                document.getElementById(this.prevLink).href = images[currentIndex - 1].url;

            var img = document.getElementById(this.prevImage)

            if (images[currentIndex - 1].image != null)
                img.src = images[currentIndex - 1].image;

            if (images[currentIndex - 1].title != null)
            {
                img.alt = images[currentIndex - 1].title;
                img.title = images[currentIndex - 1].title;
            }

            if (images[currentIndex].url != null)
                document.getElementById(this.currentLink).href = images[currentIndex].url;

            var img = document.getElementById(this.currentImage)

            if (images[currentIndex].image != null)
                img.src = images[currentIndex].image;

            if (images[currentIndex].title != null)
            {
                img.alt = images[currentIndex].title;
                img.title = images[currentIndex].title;
            }

            if (images[currentIndex].title != null)
                document.getElementById(this.title).innerHTML = images[currentIndex].title;

            if (images[currentIndex].description != null)
                document.getElementById(this.description).innerHTML = images[currentIndex].description;

            if (images[currentIndex + 1].url != null)
                document.getElementById(this.nextLink).href = images[currentIndex + 1].url;

            var img = document.getElementById(this.nextImage)

            if (images[currentIndex + 1].url != null)
                img.src = images[currentIndex + 1].image;

            if (images[currentIndex + 1].title != null)
            {
                img.alt = images[currentIndex + 1].title;
                img.title = images[currentIndex + 1].title;
            }
        }
    }
}


