// Pop-up player
function openPlayer() {
	window.open ('/player/', 'picker', config='height=255, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
	}


function openPage(id) {
	url = "/page/" + id + "/";
	window.open (url, 'picker', config='height=480, width=580, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
	}






function countChar(obj,limit,target)
{
	if (obj.value.length > limit) obj.value = obj.value.substring(0, limit);
	numDisp = limit-obj.value.length;
	document.getElementById(target).innerHTML = (numDisp);
}




			// CHANGE GALLERY IMAGE (PLUS CAPTION ETC)
			function galleryChange(move,slide) {
				if (firstrun == 1) galleryBuild();
				prev = slide - 1;
				next = slide + 1;
				if (prev == 0) prev = total;
				if (next > total) next = 1;
				if (move == 1) {
					position = (slide-1) * -82;
					document.getElementById("thumbnails").style.left = position + "px";
				}
				document.getElementById("dispImage").src = image[slide];
				document.getElementById("dispCaption").innerHTML = caption[slide];
				document.getElementById("dispCount").innerHTML = "Image " + slide + " of " + total;
				var i=1;
				for (i=1;i<=total;i++)
					{
						document.getElementById("thumb" + i).className = 'inactive-thumb';
					}
				document.getElementById("thumb" + slide).className = 'active-thumb';
				document.getElementById("left").onclick = function() { galleryChange(1,prev); return false;};
				document.getElementById("right").onclick = function() { galleryChange(1,next); return false;};
			}

			function galleryCaption(id) {
				if (id == 0) document.getElementById("caption").style.display = 'none';
				if (id == 1) document.getElementById("caption").style.display = 'block';
				if (id == 0) document.getElementById("captions-hidden").style.display = 'block';
				if (id == 1) document.getElementById("captions-hidden").style.display = 'none';
			}


			// SCROLL THUMBNAILS
			function startThumbScroll(direction) {
				clearTimeout(scrolltimer);
				if (direction > 0) doThumbScroll(direction);
			}
			function doThumbScroll(direction) {
				scrolltimer = setTimeout("doThumbScroll("+direction+")", 1);
				moveThumbnails(direction);
			}
			function moveThumbnails(direction) {
				if (direction == 1) position = position + 3;
				if (direction == 2) position = position - 3;
				if (position > 0) position = 0;
				if (position < scrolllimit) position = scrolllimit;
				document.getElementById("thumbnails").style.left = position + "px";
			}


			// SLIDE SHOW
			function startSlideshow(id) {
				if (id == 0) document.getElementById("button-slideshow").href = "javascript:startSlideshow(1);";
				if (id == 1) document.getElementById("button-slideshow").href = "javascript:startSlideshow(0);";
				if (id == 0) document.getElementById("button-slideshow").className = 'off';
				if (id == 1) document.getElementById("button-slideshow").className = 'on';
				clearTimeout(slideshow);
				if (id == 1) doAutoSlide();
			}

			function doAutoSlide() {
				slideshow = setTimeout("doAutoSlide()", 4000);
				galleryChange(1,next);
				return false;
			}


			// First run gallery builder
			function galleryBuild() {
				firstrun = 0;
				document.getElementById("slidebutton-holder").innerHTML = "<a class='off' href='javascript:startSlideshow(1);' id='button-slideshow'>Start/stop slideshow</a>";
				document.getElementById("captionbutton-holder").innerHTML = "<a href='javascript:galleryCaption(0);' id='icon'>Hide captions</a>";
				document.getElementById("thumbleft-holder").innerHTML = "<a href='javascript:startThumbScroll(1);' id='left' onMouseOver='startThumbScroll(1);' onMouseOut='startThumbScroll(0);'>Scroll thumbnails left | </a>";
				document.getElementById("thumbright-holder").innerHTML = "<a href='javascript:startThumbScroll(2);' id='right' onMouseOver='startThumbScroll(2);' onMouseOut='startThumbScroll(0);'>Scroll thumbnails right</a>";
			}


