var thumbs = new Array();
var thumbdivs = new Array();
function initGallery() {
	thumbs = document.getElementsByClassName('gallerytnimg');
	thumbdivs = document.getElementsByClassName('gallerytndiv');
	var leftoff = 0;
	var topoff = 0;

	for (var i = 0; i < thumbs.length; i++) {
		thumbs[i].onclick = doGallery;
		thumbs[i].intid = 0;
		thumbs[i].image = document.getElementById(thumbs[i].id);
		thumbs[i].origheight = thumbs[i].image.offsetHeight;
		thumbs[i].finalheight = thumbs[i].origheight + 14;
		thumbs[i].origwidth = thumbs[i].image.offsetWidth;
		thumbs[i].finalwidth = thumbs[i].origwidth + 14;
		thumbs[i].index = i;
		thumbs[i].request = thumbs[i].name;

		thumbdivs[i].style.left = leftoff + 'px';
		thumbdivs[i].style.top = topoff + 'px';
		thumbdivs[i].style.zIndex = 1000 - i;
		if (i & 0x01) {
			topoff = topoff + thumbs[i].image.offsetHeight + 10;
			leftoff = 0;
		} else {
			leftoff = leftoff + thumbs[i].image.offsetWidth + 10;
		}
	}

	document.getElementById('gallerytnpics').style.height = topoff + 'px';
}

var gallerybusy;
function doGallery () {
	if (gallerybusy) {
		return;
	}
	document.getElementById('gallerypicture').style.visibility = 'hidden';
	makeRequest('/cgi-bin/oeye/gallery/picture.html?mv_arg=' + this.request);
}

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 nextclient = document.getElementById('gallerypicture');
				nextclient.innerHTML = http_request.responseText;
				nextclient.style.visibility = 'visible';
				var nextpic = document.getElementById('screenshot');
				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('screenshot');
	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;
	}
}


