function openGallery (galleryId) {
	var w = window.open (document.urlPrefix + 'galerie/popup/' + galleryId, name, 'width=742,height=630,resizable=yes,scrollbars=no,status=yes,toolbar=no,menubar=no');
	w.focus ();
}

function openYouTube (galleryId, width, height) {
	var w = window.open (document.urlPrefix + 'galerie/popup/' + galleryId, name, 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=no,status=yes,toolbar=no,menubar=no');
	w.focus ();
}

function showGalleryImage (id, w, h, caption) {
	// do not forget the caption!!
	var img0 = document.getElementById ('gallery-img');
	if (img0) {
		document.getElementById ('gallery-wait').style.display = 'block';
		var div0 = img0.parentNode;
		var parent = div0.parentNode;
		if (img0 && div0) {
			var div1  = document.createElement ('DIV');
			var img1 = document.createElement ('IMG');
			img1.onload = function () {
							try {
								parent.replaceChild (div1, div0);
								img1.id = 'gallery-img';
								document.getElementById ('gallery-wait').style.display = 'none';
							} catch (ex) {}
			              };
			img1.onerror = function () {
							try {
								document.getElementById ('gallery-wait').style.display = 'none';
							} catch (ex) {}
			               };
			img1.src = img0.src.substring (0, img0.src.indexOf ('&id=')) + '&id=' + id;
			img1.width = w;
			img1.height = h;
			img1.className = 'gallery';
			div1.appendChild (img1);
			div1.className = 'wrap4';
			if (caption) {
				var div2 = document.createElement ('DIV');
				if (w < h) {
					div2.className = 'gallery-caption-right';
					div2.style.width = (600 - w - 10) + 'px';
				}
				else {
					div2.className = 'gallery-caption-bottom';
					div2.style.width = w + 'px';
				}
				div2.innerHTML = caption;
				div1.appendChild (div2);
			}
		}
	}
	// reset the active thumbnail
	var offset = 0;
	var idFound = false;
	for (var i = 0; i < imgIDs.length; i++) {
		try {
			if (imgIDs[i] == id) { idFound = true; offset += (18 + 33); }
			if (!idFound) { offset += (18 + 66); } 
			document.getElementById ('thumb' + imgIDs[i]).className = 'gallery-thumb';
		} catch (ex) {}
	}
	document.getElementById ('thumb' + id).className = 'gallery-thumb active';
	// scroll the thumbs
	document.getElementById ('imagewrapper').scrollTop = Math.max (0, offset - 315);
}

function preloadImages () {
	var d = document; 
	if (d.images) {
		if (!d.p) d.p = new Array ();
		var i, j = d.p.length, a = preloadImages.arguments;
		for (i = 0; i < a.length; i++) {
			if (a[i].indexOf ("#") != 0) {
				d.p[j] = new Image;
				d.p[j++].src = a[i];
			}
		}
	}
}
