    var galleries = [null, null, null];
    var cur = null;
    var curGallery;
    var curOpacity = 0;

    function initGallery(g) {
      galleries[g] = [];
      var img;

      if (g == 0) {
	img = new Image();
	img.src = 'images/gallery3/dyrehaven1b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery3/dyrehaven2b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery3/dyrehaven3b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery3/dyrehaven4b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery3/dyrehaven5b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery3/dyrehaven6b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery3/dyrehaven7b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery3/dyrehaven8b.jpg';
	galleries[g].push(img);
      } else if (g == 1) {
	img = new Image();
	img.src = 'images/gallery1/aarhus1b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery1/aarhus7b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery1/aarhus3b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery1/aarhus5b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery1/aarhus4b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery1/aarhus8b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery1/aarhus9b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery1/aarhus10b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery1/aarhus11b.jpg';
	galleries[g].push(img);

      } else if (g == 2) {
	img = new Image();
	img.src = 'images/gallery2/rom1b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery2/rom2b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery2/rom3b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery2/rom4b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery2/rom5b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery2/rom6b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery2/rom7b.jpg';
	galleries[g].push(img);
      } else if (g == 3) {
	img = new Image();
	img.src = 'images/gallery4/efteraar1b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery4/efteraar2b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery4/efteraar3b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery4/efteraar7b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery4/efteraar5b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery4/efteraar6b.jpg';
	galleries[g].push(img);

	img = new Image();
	img.src = 'images/gallery4/efteraar4b.jpg';
	galleries[g].push(img);
      }
    }


    function show(g, idx) {
	if (galleries[g] == null)
		initGallery(g);
	
        var wrapper = document.getElementById("photo-wrapper");
	var cnt = wrapper.parentNode;
	wrapper.style.width = (cnt.offsetWidth - 6) + "px";
	wrapper.style.height = (cnt.offsetHeight - 4) + "px";
        wrapper.style.display = "block";
	var layer = document.getElementById("photo-layer");
	layer.style.display = "block";
	layer.style.width = (cnt.offsetWidth - 8) + "px";
	layer.style.height = (cnt.offsetHeight - 8) + "px";

	var hm = (cnt.offsetHeight - 100) / 2;
	document.getElementById("prev-button").style.marginTop = hm + "px";
	document.getElementById("next-button").style.marginTop = hm + "px";

	var photo = document.getElementById("photo");
	curOpacity = 0;
	photo.style.opacity = curOpacity / 100;
	photo.style.filter = "alpha(opacity=" + curOpacity + ")";

        photo.style.backgroundImage = "url(" + galleries[g][idx].src + ")";
	photo.style.display = "block";

	setTimeout(checkImage, 100);

	cur = idx;
	curGallery = g;

	document.getElementById("prev-button").style.display = cur == 0 ? "none" : "block";
	document.getElementById("next-button").style.display = (cur == (galleries[g].length - 1)) ? "none" : "block";
    }

    function checkImage() {
	if (curOpacity < 100) {
	    var photo = document.getElementById("photo");
	    if (galleries[curGallery][cur].width > 0) {
		var wrapper = document.getElementById("photo-wrapper");
		var cnt = wrapper.parentNode;

	        photo.style.width = galleries[curGallery][cur].width + "px";
	        photo.style.height = galleries[curGallery][cur].height + "px";
	        photo.style.left = ((cnt.offsetWidth - galleries[curGallery][cur].width) / 2) + "px";
	        photo.style.top = ((cnt.offsetHeight - galleries[curGallery][cur].height) / 2) + "px";
	    }

	    curOpacity += 10;
	    photo.style.opacity = curOpacity / 100;
	    photo.style.filter = "alpha(opacity=" + curOpacity + ")";
	    setTimeout(checkImage, 40);
	}
    }


    function showNext() {
	if (cur < galleries[curGallery].length - 1) {
	    cur++;
	    show(curGallery, cur);
	}
    }

    function showPrev() {
	if (cur > 0) {
 	    cur--;
	    show(curGallery, cur);
	}
    }

    function closeGallery() {
	document.getElementById("photo-layer").style.display = "none";
	document.getElementById("photo-wrapper").style.display = "none";
    }
