﻿// JScript File

var currAlvisGalleryIndex = 0;

function alvisGallery()
{
    this.count = 0;
    
    this.addImage = function(image_id, image_file_name, title, caption, photo_credit, vertical_alignment, width, height, image_url) {
        this.count++;
        this[this.count - 1] = new alvisGalleryImage(image_id, image_file_name, title, caption, photo_credit, vertical_alignment, width, height, image_url);
    }
	
	this.find = function(image_id) {
		return this[this.exists(image_id)];
	}
		
	
	this.exists = function(image_id) {
	    var found = false;
		var i = 0;
		
		while(i < this.count && (!found))
		{
		    
			if(this[i].image_id == image_id)	{
				found = true;
			}
			else {
				i++;
			}
		}
		
		if(found)
			return i;
		else
			return -1;
	}
}

function alvisGalleryImage(image_id, image_file_name, title, caption, photo_credit, vertical_alignment, width, height, image_url)
{
    this.image_id = image_id;
    this.image_file_name = image_file_name;
    this.title = title;
    this.caption = caption;
    this.photo_credit = photo_credit;
    this.vertical_alignment = vertical_alignment;
    this.width = width;
    this.height = height;
    this.image_url = image_url;
}

function LoadAlvisImage(image_id)
{   
    document.getElementById('ImageHeader').innerHTML = "<div>" + gal.find(image_id).title + "</div>";
    document.getElementById("MainImage").src = gal.find(image_id).image_file_name;
    document.getElementById("MainImage").alt = gal.find(image_id).title;
    document.getElementById('ImagePhotoCredit').innerHTML = "<div>" + gal.find(image_id).photo_credit + "</div>";
    document.getElementById('ImageCaption').innerHTML = "<div>" + gal.find(image_id).caption + "</div>";
    document.getElementById('ImageUrl').href = gal.find(image_id).image_url;
    
    currAlvisGalleryIndex = gal.exists(image_id);
}

function LoadFirstAlvisImage()
{   
    document.getElementById('ImageHeader').innerHTML = "<div>" + gal[0].title + "</div>";
    document.getElementById("MainImage").src = gal[0].image_file_name;
    document.getElementById("MainImage").alt = gal[0].title;
    document.getElementById('ImagePhotoCredit').innerHTML = "<div>" + gal[0].photo_credit + "</div>";
    document.getElementById('ImageCaption').innerHTML = "<div>" + gal[0].caption + "</div>";
    document.getElementById('ImageUrl').href = gal[0].image_url;
    currAlvisGalleryIndex = 0;
    
}
function VerifyDeleteGallery()
{
	if(confirm("You are about to delete this Gallery.\n\nPlease verify that you wish to continue.")){
	alert('deleted');
	}
	else{
	alert('canceled')
	}
}
function VerifyDeleteImage()
{
	if(confirm("You are about to delete this Image.\n\nPlease verify that you wish to continue.")){
	alert('deleted');
	}
	else{
	alert('canceled')
	}
}
function MoveForward() {   
    var tempCurrAlvisIndex = (currAlvisGalleryIndex + 1);
    if(tempCurrAlvisIndex == gal.count){
    LoadAlvisImage(gal[0].image_id);
    }
    else{
    LoadAlvisImage(gal[tempCurrAlvisIndex].image_id);
    }
}
function MoveBackward() {   
    var tempCurrAlvisIndex = (currAlvisGalleryIndex - 1);
    var tempCurrAlvisCount = gal.count - 1;
    if(tempCurrAlvisIndex == -1){
    LoadAlvisImage(gal[tempCurrAlvisCount].image_id);
    }
    else{
    LoadAlvisImage(gal[tempCurrAlvisIndex].image_id);
    }
}