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 GalleryLinks(p_url, p_img)
{
    this.url = p_url;
    this.img = p_img;
}

function GalleryImages(p_prevLink, p_prevImage, p_currentLink, p_currentImage, p_title, p_description, p_nextLink, p_nextImage)
{
	this.previousLinks = new Array();
	this.previousLinks[0] = new GalleryLinks(p_prevLink, p_prevImage);
	
	this.currentLink = p_currentLink;
	this.currentImage = p_currentImage;
	this.title = p_title;
	this.description = p_description;
	
	this.nextLinks = new Array();
	this.nextLinks[0] = new GalleryLinks(p_nextLink, p_nextImage);
	
	this.index = 0;
	this.galleryImages = new Dictionary();
}

//function GalleryImages(previousGalleryLinks, p_currentLink, p_currentImage, p_title, p_description, nextGalleryLinks)
//{
//    this.previousLinks = previousGalleryLinks;
//    this.currentLink = p_currentLink;
//	this.currentImage = p_currentImage;
//	this.title = p_title;
//	this.description = p_description;
//	this.nextLinks = nextGalleryLinks;
//	this.index = 0;
//	this.galleryImages = new Dictionary();
//}

GalleryImages.prototype.appendPrevious = function(url, img)
{
    this.previousLinks[this.previousLinks.length] = new GalleryLinks(url, img);
}

GalleryImages.prototype.appendNext = function(url, img)
{
    this.nextLinks[this.nextLinks.length] = new GalleryLinks(url, img);
}

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.SetImageIndexOffset = function(title, description, anchor, img, offset)
{
    var offsetIndex = this.index + offset;
    
    // if the offsetIndex is less than 0, then offset the remain amount from the other end of the list of images
    if (offsetIndex < 0)
        offsetIndex = this.galleryImages.length + offsetIndex;
    // if the offsetIndex is greater than the length of the list of images, 
    // then offset the remaining amount from the other end of the list of images
    else if (offsetIndex > this.galleryImages.length - 1)
        offsetIndex = offsetIndex - this.galleryImages.length
    
    anchor.href = this.galleryImages[offsetIndex].url;
    img.src = this.galleryImages[offsetIndex].image;
    img.alt = this.galleryImages[offsetIndex].title;
    img.title = this.galleryImages[offsetIndex].title;
    
    
    if (title != null)
        title.innerHTML = this.galleryImages[this.index].title;
        
    if (description != null)
        description.innerHtml = this.galleryImages[this.index].description;
}

GalleryImages.prototype.updateGalleryImages = function()
{
    var previousLinksCount = this.previousLinks.length;
    for(var i=0; i<previousLinksCount; i++)
    {
        var indexOffset = -1 * previousLinksCount + i;
        this.SetImageIndexOffset(null, null, document.getElementById(this.previousLinks[i].url), document.getElementById(this.previousLinks[i].img), indexOffset)    
    }

    this.SetImageIndexOffset(document.getElementById(this.title), document.getElementById(this.description), document.getElementById(this.currentLink), document.getElementById(this.currentImage), 0)
    
    var nextLinksCount = this.nextLinks.length;
    for(var i=0; i<nextLinksCount; i++)
    {
        var indexOffset = i + 1;
        this.SetImageIndexOffset(null, null, document.getElementById(this.nextLinks[i].url), document.getElementById(this.nextLinks[i].img), indexOffset)
    }
}

