    var currentPhoto = 0;
    var secondPhoto = 1;

    var currentOpacity = new Array();
    var imageArray = new Array();

    if (document.all) {
        var FADE_STEP = 100;
        var FAST_FADE_STEP = 100;
        var FADE_INTERVAL = 0;
    } else {
        var FADE_STEP = 6;
        var FAST_FADE_STEP = 10;
        var FADE_INTERVAL = 1;
    }
    
    pauseLength = 6000;
    
    var blnContinue = true;
    var photo1 = 0;
    var photo2 = 0;

    var vCheck = true;
    var sCheck = true;

	var xmlDoc;
	var lgPath;
	var disLowNum;
	var disHighNum;
	var sliderLeftMargin = 0.0;
	var marginShift = 1.8;

	function init() {
		if (document.implementation && document.implementation.createDocument) {
			xmlDoc = document.implementation.createDocument("", "", null);
			xmlDoc.onload = loadImages();
		} else 
			if (window.ActiveXObject) {
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.onreadystatechange = function () {
				if (xmlDoc.readyState == 4) loadImages();
			}
		} else {
			alert('Problem with browser');
			return;
		}

        var scriptTags = document.getElementsByTagName("script");
        var params = new Array();

        for (var i=0; i<scriptTags.length; i++) {
            if(scriptTags[i].src && scriptTags[i].src.match(/galleryv2\.js(\?.*)?$/)) {
                idx = scriptTags[i].src.indexOf('?');
                if (idx != -1) {
                    var pairs = scriptTags[i].src.substring(idx+1, scriptTags[i].src.length).split('&');
                    for (var x=0; x<pairs.length; x++) {
                        nameVal = pairs[x].split('=');
                        params[x] = nameVal[1];
                    }
                }
            }
        }

        var xmlDocName = params[0];
		xmlDoc.load(xmlDocName);
	}

	function loadImages() {
		//check for ff to make sure it is open
		if (xmlDoc.documentElement == null) {
			ti = setTimeout("loadImages()",100); 
			return;
		}

		var album = xmlDoc.getElementsByTagName('album');
		document.getElementById('gallery-top').innerHTML = '<h1>' + album[0].getAttribute('description') + '</h1>';
		
		lgPath = album[0].getAttribute('lgPath');
		var arrCnt = 0
		
		for (i=0; i<album[0].childNodes.length; i++) {
			if (album[0].childNodes[i].nodeName == 'img') {
                if (album[0].childNodes[i].getAttribute('sell') == 'N') imageArray[arrCnt] = [album[0].childNodes[i].getAttribute('src'),album[0].childNodes[i].getAttribute('caption'),album[0].childNodes[i].getAttribute('photoLayout'),""];
                else {
                    image = lgPath.substring(7) + album[0].childNodes[i].getAttribute('src')
                    pictopia = '<a href="http://pictopia.com/perl/ptp/roanoke?photo_name=' + image + '&title=' + album[0].childNodes[i].getAttribute('src') + '&t_url=' + image + '" target=_blank><img src="/images/v2005/buythisprint.gif" /></a>'
                    imageArray[arrCnt] = [album[0].childNodes[i].getAttribute('src'),album[0].childNodes[i].getAttribute('caption'),album[0].childNodes[i].getAttribute('photoLayout'),pictopia];
                }
				arrCnt++;
			}
		}
		displayImgs();
	}

    function displayImgs() {
        currentOpacity[0]=99;

        for(i=1;i<imageArray.length;i++) currentOpacity[i]=0;

        var mHTML="";
        var nav = '';
        var displayInt;

        for (i=0;i<imageArray.length;i++) {
            if (imageArray[i][2] == 'H') mHTML+='<div id="photo" name="photo" class="mPhoto" onmouseover="if (blnContinue) { document.getElementById(\'btn-auto-controls\').value=\'Slideshow Paused\'; clearTimeout(mInterval) }" onmouseout="if (blnContinue) { document.getElementById(\'btn-auto-controls\').value=\'Stop Slideshow\'; mInterval = setTimeout(\'crossFade()\',FADE_INTERVAL); }"><img src="' + lgPath + imageArray[i][0] + '"></div>';
            else mHTML+='<div id="photo" name="photo" class="mPhoto" onmouseover="if (blnContinue) { document.getElementById(\'btn-auto-controls\').value=\'Slideshow Paused\'; clearTimeout(mInterval) };" onmouseout="if (blnContinue) { document.getElementById(\'btn-auto-controls\').value=\'Stop Slideshow\'; mInterval = setTimeout(\'crossFade()\',FADE_INTERVAL); }"><img src="' + lgPath + imageArray[i][0] + '" style="height:450px"></div>';

			displayInt = '0' + eval(i + 1);
			if (i==0) nav = '<a id="photoID' + i + '" class="activePhoto" href="javascript:skipTo(' + i + ', false)">' + displayInt.substring(displayInt.length-2) + '</a>';
			else nav += '<a id="photoID' + i + '" class="passivePhoto" href="javascript:skipTo(' + i + ', false)">' + displayInt.substring(displayInt.length-2) + '</a>';
        }
        
        if (imageArray.length>10) {
            document.getElementById('more-right').style.visibility = 'visible';
            disHighNum = 9;
        } else disHighNum = imageArray.length - 1;
        
        disLowNum = 0;
        	            
        document.getElementById("mContainer").innerHTML = mHTML;
        document.getElementById('caption').value = imageArray[0][1];
        document.getElementById('buy-print').innerHTML = imageArray[0][3];
        document.getElementById("image-numbers").innerHTML = nav;
        
        if(document.all) {
            document.getElementsByName("photo")[currentPhoto].style.filter="alpha(opacity=100)";
        } else {
            document.getElementsByName("photo")[currentPhoto].style.MozOpacity = .99;
        }

        mInterval = setTimeout("crossFade()",pauseLength);
    }

    function imageSlider() {
        if (secondPhoto > disHighNum) { //move to the left
            if (secondPhoto == imageArray.length - 1) {
                sliderLeftMargin = -(imageArray.length - 10) * marginShift;
                document.getElementById('more-right').style.visibility = 'hidden';
            } else sliderLeftMargin = sliderLeftMargin - marginShift;
            disHighNum = secondPhoto;
            disLowNum = secondPhoto - 9;
            
            document.getElementById('more-left').style.visibility = 'visible';
            document.getElementById('image-numbers').style.marginLeft = sliderLeftMargin + 'em';
        }
        
        if (secondPhoto < disLowNum) { //move to the right
            if (secondPhoto == 0) {
                sliderLeftMargin = 0;
                document.getElementById('more-left').style.visibility = 'hidden';
            } else sliderLeftMargin = sliderLeftMargin + marginShift;
            disHighNum = secondPhoto + 9;
            disLowNum = secondPhoto;
            
            document.getElementById('more-right').style.visibility = 'visible';
            document.getElementById('image-numbers').style.marginLeft = sliderLeftMargin + 'em';
        }
    }
                
    function crossFade() {
        currentOpacity[currentPhoto]-=FADE_STEP;
        currentOpacity[secondPhoto] += FADE_STEP;

        if (imageArray[secondPhoto][2] == 'V' && vCheck) {
            vCheck = false;
            document.getElementsByName("photo")[secondPhoto].style.paddingLeft = "0px";
            padding = (document.getElementById("mContainer").offsetWidth - document.getElementsByName("photo")[secondPhoto].offsetWidth) / 2;
            document.getElementsByName("photo")[secondPhoto].style.paddingLeft = padding + "px";
        }
         	             
        if(document.all) {
            document.getElementsByName("photo")[currentPhoto].style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")";
            document.getElementsByName("photo")[secondPhoto].style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";
        } else {
            document.getElementsByName("photo")[currentPhoto].style.MozOpacity = currentOpacity[currentPhoto]/100;
            document.getElementsByName("photo")[secondPhoto].style.MozOpacity =currentOpacity[secondPhoto]/100;
        }

        //if (currentOpacity[secondPhoto]/100>=.50) {
        if (currentOpacity[secondPhoto]/100>=.50 && sCheck) {
            sCheck = false;
            document.getElementById('caption').value = imageArray[secondPhoto][1];
            document.getElementById('buy-print').innerHTML = imageArray[secondPhoto][3];
            document.getElementById('photoID' + currentPhoto).className = 'passivePhoto';
            document.getElementById('photoID' + secondPhoto).className = 'activePhoto';
            
            imageSlider();
        }

        if(currentOpacity[secondPhoto]/100>=.98) {
            currentPhoto = secondPhoto;
            secondPhoto++;
            sCheck = true;
            vCheck = true;
            if(secondPhoto == imageArray.length)secondPhoto=0;
            if (blnContinue) mInterval = setTimeout("crossFade()",pauseLength);
            else blnContinue = true;
        } else mInterval = setTimeout("crossFade()",FADE_INTERVAL);
    }

    function skipToFade() {
        if (currentOpacity[photo1]/100 > 0)	currentOpacity[photo1]-=FAST_FADE_STEP;
        if ((currentOpacity[photo2]/100 > 0) && (photo2 != secondPhoto)) currentOpacity[photo2] -= FAST_FADE_STEP;
        currentOpacity[secondPhoto] += FAST_FADE_STEP;

        if (imageArray[secondPhoto][2] == 'V' && vCheck) {
            vCheck = false;
            document.getElementsByName("photo")[secondPhoto].style.paddingLeft = "0px";
            padding = (document.getElementById("mContainer").offsetWidth - document.getElementsByName("photo")[secondPhoto].offsetWidth) / 2;
            document.getElementsByName("photo")[secondPhoto].style.paddingLeft = padding + "px";
        }

        if(document.all) {
            document.getElementsByName("photo")[photo1].style.filter = "alpha(opacity=" + currentOpacity[photo1] + ")";
            if (photo2 != secondPhoto) document.getElementsByName("photo")[photo2].style.filter = "alpha(opacity=" + currentOpacity[photo2] + ")";
            document.getElementsByName("photo")[secondPhoto].style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";
        } else {
            document.getElementsByName("photo")[photo1].style.MozOpacity = currentOpacity[photo1]/100;
            if (photo2 != secondPhoto) document.getElementsByName("photo")[photo2].style.MozOpacity = currentOpacity[photo2]/100;
            document.getElementsByName("photo")[secondPhoto].style.MozOpacity =currentOpacity[secondPhoto]/100;
        }

        if(currentOpacity[secondPhoto]/100>=.50) {
            document.getElementById('caption').value = imageArray[secondPhoto][1];
            document.getElementById('buy-print').innerHTML = imageArray[secondPhoto][3];
            document.getElementById('photoID' + photo1).className = 'passivePhoto';
            document.getElementById('photoID' + photo2).className = 'passivePhoto';
            document.getElementById('photoID' + secondPhoto).className = 'activePhoto';
            
            imageSlider();
        }

        if(currentOpacity[secondPhoto]/100>=.98) {
            currentPhoto = secondPhoto;
            secondPhoto++;
            sCheck = true;
            vCheck = true;
            if(secondPhoto == imageArray.length)secondPhoto=0;
            if (blnContinue) {
                mInterval = setTimeout("crossFade()",pauseLength);
                document.getElementById('btn-auto-controls').value = 'Stop Slideshow';
            } else document.getElementById('btn-auto-controls').value = 'Start Slideshow';
        } else mInterval = setTimeout("skipToFade()",FADE_INTERVAL);
    }

    function skipTo(newPhoto, blnC) {
        clearTimeout(mInterval);
        photo1 = currentPhoto;
        photo2 = secondPhoto;
        secondPhoto = newPhoto;
        blnContinue = blnC;
        mInterval = setTimeout("skipToFade()",FADE_INTERVAL);
    }

    function skipToPrevNext(pnFlag, blnC) {
        clearTimeout(mInterval);
        photo1 = currentPhoto;
        photo2 = secondPhoto;
        if (pnFlag == 'p') {
            if (currentPhoto == 0) secondPhoto = currentPhoto;
            else secondPhoto = currentPhoto - 1;
        } else {
            if (currentPhoto == (imageArray.length - 1)) secondPhoto = currentPhoto;
            else secondPhoto = currentPhoto + 1;
        }
        blnContinue = blnC;
        mInterval = setTimeout("skipToFade()",FADE_INTERVAL);
    }

    function autoPlay(btn) {
        if (btn.value == 'Stop Slideshow') {
            btn.value = 'Start Slideshow';
            
            clearTimeout(mInterval);
            blnContinue = false;
        } else {
            btn.value = 'Stop Slideshow';
            
            blnContinue = true;
            mInterval = setTimeout("crossFade()",FADE_INTERVAL);
        }
    }