﻿// JScript File
function createNewImgElement(thisObj)
{
    var newElement = document.createElement("img");
    newElement.setAttribute("id", thisObj.getAttributeNode("id").nodeValue);
    newElement.setAttribute("src", thisObj.getAttributeNode("src").nodeValue);
    newElement.setAttribute("alt", thisObj.getAttributeNode("alt").nodeValue);
    newElement.setAttribute("width", "300px");
    return newElement;
}

function showLargePhoto(thisObj)
{
    var imgElement = thisObj;
    var photoDiv;
    var description;
    var clinic = imgElement.parentNode.parentNode.parentNode.parentNode.parentNode.getAttributeNode("id").nodeValue;
    
    if(clinic == "vancouverPhoto"){
        photoDiv = document.getElementById("vancouverLargePhoto");
        description = document.getElementById("vancouverPhotoDescription");
    }
    else if(clinic == "torontoPhoto"){
        photoDiv = document.getElementById("torontoLargePhoto");
        description = document.getElementById("torontoPhotoDescription");
    }
    else if(clinic == "ottawaPhoto"){
        photoDiv = document.getElementById("ottawaLargePhoto");
        description = document.getElementById("ottawaPhotoDescription");
    }
    var newElement = createNewImgElement(thisObj);
    var firstChild = photoDiv.firstChild;
    if(firstChild == null)
    {
        description.innerHTML = newElement.getAttributeNode("alt").nodeValue;
        photoDiv.appendChild(newElement);
    }
    else{
        if(firstChild.nodeName.toLowerCase() == "img"){
            photoDiv.removeChild(firstChild);
        }
        photoDiv.appendChild(newElement);
        description.innerHTML = newElement.getAttributeNode("alt").nodeValue;
    }
}
