﻿
var xmlDoc = loadXML(strXML);
var arrImageName; // = new Array(18);
var arrImageCaption; // = new Array(18);

function imageChange(id) {
    
    var oCurrentImage = document.getElementById("divCurrentImage");
    var oAppearImage = document.getElementById("divAppearImage");
    
    oCurrentImage.style.background = oAppearImage.style.background;
    oCurrentImage.style.width = oAppearImage.style.width;
    oCurrentImage.style.height = oAppearImage.style.height;
    
	oAppearImage.style.display = 'none';
	oAppearImage.style.background = 'url(images/'+arrImageName[id-1]+')';
	
	if(id<5) {
	    oAppearImage.style.width = '550px';
        oAppearImage.style.height = '411px';
	}
	else {
	    oAppearImage.style.width = '411px';
        oAppearImage.style.height = '550px';
	}
	
	new Effect.Appear('divAppearImage'); // new Effect.Appear('divAppearImage', { duration: 3.0 })
	
	var oCaption = document.getElementById('PhotoCaption');
    oCaption.innerHTML = arrImageCaption[id-1];
}

function loadXML(xmlfile) {
    var xmldoc

    if(window.XMLHttpRequest) {
        xmldoc = new window.XMLHttpRequest();

        xmldoc.open("GET",xmlfile,false)
        xmldoc.send("")
        return xmldoc.responseXML;
    }
    else if(window.ActiveXObject) {
        xmldoc = new ActiveXObject("Microsoft.XMLDOM");
        xmldoc.async = false;
        xmldoc.load(xmlfile)
        return xmldoc
    } else {
        alert("XML loading not supported.");
        return null;
    }
}

function populateArrays() {
    if (xmlDoc!=null)
    {    
        var x=xmlDoc.getElementsByTagName("image");
        arrImageName = new Array(x.length);
        arrImageCaption = new Array(x.length);
        for (i=0; i<x.length; i++)
        { 
            arrImageName[i] = x[i].getElementsByTagName("filename")[0].childNodes[0].nodeValue;
            arrImageCaption[i] = x[i].getElementsByTagName("caption")[0].childNodes[0].nodeValue;
        }
    }
}

function setStartImage() {
    populateArrays();
     
    var oCurrentImage = document.getElementById("divCurrentImage");
    oCurrentImage.style.background = 'url(images/'+arrImageName[0]+')';
    oCurrentImage.style.width = '550px';
    oCurrentImage.style.height = '411px';
    var oAppearImage = document.getElementById("divAppearImage");
    oAppearImage.style.background = oCurrentImage.style.background;
    oAppearImage.style.width = oCurrentImage.style.width;
    oAppearImage.style.height = oCurrentImage.style.height;
     
    var oCaption = document.getElementById('PhotoCaption');
    oCaption.innerHTML = arrImageCaption[0];
}

function setRandomImage() {
    populateArrays();
    
    var iArray = Math.floor(Math.random()*5);
    var oMainImage = document.getElementById("imgMain");
    //oMainImage.src = 'images/' + arrImageName[iArray];
    oMainImage.src = 'images/mainImage.jpg';
}
