arrowup_over = new Image;
arrowup_over.src = "/jpls/images/landscape-photo-up-o.jpg";
arrowup_off = new Image;
arrowup_off.src = "/jpls/images/landscape-photo-up.jpg";
arrowdn_over = new Image;
arrowdn_over.src = "/jpls/images/landscape-photo-dwn-o.jpg";
arrowdn_off = new Image;
arrowdn_off.src = "/jpls/images/landscape-photo-dwn.jpg";
var uparrow, dnarrow;
scroller = new Object;

function initGallery() {
	scroller.tnboxobj = document.getElementById('gallerytnbox');
	scroller.tnpicsobj = document.getElementById('gallerytnpics');
	scroller.scrollup = scrollUp;
	scroller.scrolldown = scrollDown;
	scroller.xpos = 0;
	scroller.ypos = 0;

	uparrow = document.getElementById('arrowup');
	uparrow.onmouseover = startScroll;
	uparrow.onmouseout = stopScroll;
	uparrow.upward = 0;
	uparrow.overimg = arrowup_over.src;
	uparrow.offimg = arrowup_off.src;
	uparrow.scroller = scroller;

	dnarrow = document.getElementById('arrowdown');
	dnarrow.onmouseover = startScroll;
	dnarrow.onmouseout = stopScroll;
	dnarrow.upward = 1;
	dnarrow.overimg = arrowdn_over.src;
	dnarrow.offimg = arrowdn_off.src;
	dnarrow.scroller = scroller;
}

function scrollUp() {
	var minheight = this.tnpicsobj.offsetHeight - this.tnboxobj.offsetHeight;

	if (this.ypos > -minheight) {
		this.ypos -= 10;
		this.tnpicsobj.style.left = this.xpos + 'px';
		this.tnpicsobj.style.top = this.ypos + 'px';
	} else {
		clearInterval(this.intervalID);
	}
}

function scrollDown() {
	if (this.ypos < 0) {
		this.ypos += 10;
		this.tnpicsobj.style.left = this.xpos + 'px';
		this.tnpicsobj.style.top = this.ypos + 'px';
	} else {
		clearInterval(this.intervalID);
	}
}

function startScroll() {
	this.src = this.overimg;
	if (this.upward) {
		this.intervalID = setInterval("uparrow.scroller.scrollup()", 40);
	} else {
		this.intervalID = setInterval("dnarrow.scroller.scrolldown()", 40);
	}
}

function stopScroll() {
	this.src = this.offimg;
	clearInterval(this.intervalID);
}

var gallerybusy;
function doGallery (code) {
	if (gallerybusy) {
		return;
	}
	document.getElementById('gallerypicture').style.visibility = 'hidden';
	makeRequest('/cgi-bin/jpls/gallery_pic.html?mv_arg=' + code);
}

function doShowcase (code, num) {
	if (gallerybusy) {
		return;
	}
	document.getElementById('gallerypicture').style.visibility = 'hidden';
	makeRequest('/cgi-bin/jpls/showcasepic.html?mv_arg=' + code + '&imgnum=' + num);
}

function clearGalleryBusy() {
	gallerybusy = 0;
}

function makeRequest(url) {
	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Trouble with XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = function() { changeContents(http_request); };
	http_request.open('GET', url, true);
	http_request.send(null);
}

function changeContents(http_request) {
	try {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				var nextphoto = document.getElementById('gallerypicture');
				nextphoto.innerHTML = http_request.responseText;
				nextphoto.style.visibility = 'visible';
				var nextpic = document.getElementById('galleryimage');
				nextpic.style.visibility = 'hidden';
				setOpacity(nextpic, 0);
				nextpic.onload = function() { displayPhotos(); };
			} else {
				alert(http_request.status + ': Sorry, there was a problem with your request. Please try again.');
			}
		}
	}
	catch( e ) {
		alert('Caught Exception: ' + e.description);
	}
}

var sitepic;
function displayPhotos() {
	sitepic = document.getElementById('galleryimage');
	setOpacity(sitepic, 0);
	sitepic.style.visibility = 'visible';
	doFadeIn();
}

function doFadeIn() {
	for (var i = 0; i < 21; i++) {
		setTimeout('setOpacity(sitepic, ' + i + ')', (40 * i));
	}
	setTimeout('clearGalleryBusy()', (40 * i));
}

function setOpacity(obj, alpha) {
	var ostyle = obj.style;
	if( ostyle.MozOpacity != undefined ) { //Moz and older
		ostyle.MozOpacity = alpha/20;
	}
	else if( ostyle.filter != undefined ) { //IE
		ostyle.filter = "alpha(opacity=' + alpha * 5 + ')";
		obj.filters.alpha.opacity = ( alpha * 5 );
	}
	else if( ostyle.opacity != undefined ) { //Opera
		ostyle.opacity = alpha/20;
	}
}

