﻿// JScript File

var currentScreen = "Gallery";
var currentGalleryPage = "gp1";
var images = new Array();
var defaultImageWidth = 500;

function showScreen(id)
{

    var cur = document.getElementById(currentScreen);
    if(cur!=null)cur.style.display = "none";
    
    var newEl = document.getElementById(id);
    if(newEl != null) newEl.style.display = "block";
    
    currentScreen = id;
}


function ImageData(img,title,alt)
{
    this.img = img;
    this.title =  title;
    this.alt = alt;
    this.width = -1;
}

//Hide the current gallery page and show a new one with
//the matching id.
function showGalleryPage(gpId)
{

    var gal = document.getElementById(gpId);
    if(gal == null) return;
 
    //hide the old gallery.
    if(currentGalleryPage != null)
        document.getElementById(currentGalleryPage).style.display = "none"
    
    //show the new gallery.    
    gal.style.display = "block";  
    currentGalleryPage = gal.id;
    
    //display first image of the new gallery.
    var imgs = gal.getElementsByTagName("img");
    if(imgs !=null && imgs.length>0) showImage(imgs[0].id);
    
}

function showImage(imgId)
{
   var i = document.getElementById("GalleryImage");
   if(i ==null)return;
   
   var parent = i.parentNode;
   parent.removeChild(i);
   
   var loadingMsg = document.getElementById("LoadingMsg");
   if(loadingMsg == null)
   {
     loadingMsg = document.createElement("div");
     loadingMsg.innerHTML = "Loading image...";
     loadingMsg.setAttribute("id", "LoadingMsg");
     parent.appendChild(loadingMsg);
    }
   
  
    var newImage = document.createElement("img");
    newImage.setAttribute("src", images[imgId].img);
    newImage.setAttribute("id", "GalleryImage");
    newImage.setAttribute("class", "GalleryImage");
    if(navigator.userAgent.indexOf("MSIE") > 0)
    {
        var w = newImage.width;
        if(w>500)w=500;
        newImage.style.width = w;
    }
    parent.appendChild(newImage);


    var t = document.getElementById("GalleryImageTitle");
    if(t == null)return;
    t.innerHTML = images[imgId].title;
}


