addLoadEvent(registerGalleryEvents);

var leftb;
var rightb;

function registerGalleryEvents(e) {

	curpos = 0;
	
	leftb = $('leftb');

	leftb.onclick = galleryMoveLeft;

	rightb = $('rightb');

	rightb.onclick = galleryMoveRight;

	hideimg = new Array();
	
	n = $('galimages');

	var imgLinks = getElementsByClassName("navlink",'a',$('gallerynav'));
	for (li in imgLinks)
	{
		imgLinks[li].onclick = doAsyncLoad;
	}

	/*for(var i = 1; i <= n.childNodes.length; i++) {
		cur = n.childNodes[i-1];
		hideimg[i] = new fx.Opacity(cur, {duration: 120});
	}*/

}

function doAsyncLoad(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;

	efx = new fx.Opacity('gallerymain', {duration: 150,fps: 30, 
		onComplete: 
			function() {
			aj = new ajax ('/members/gallery_loadmain.php', 
				{
				postBody: 'q=' + targ.id, 
				update: $('gallerymain'),
				onComplete: function() { efx.show(); }
				});
			}
	
	});
	efx.toggle();

	return false;
}


function galleryMoveLeft() {
	if(curpos > 0) {
		rightb.className = 'rightb';
		curpos--;
		galleryVisible();
		if((curpos) <= 0) {
			leftb.className = 'leftbdisabled';
		}
	} else {
		leftb.className = 'leftbdisabled';
	}
	return false;
}

function galleryMoveRight() {

	if((curpos + galppp) < galimages) {
		leftb.className = 'leftb';
		curpos++;
		galleryVisible();
		if((curpos+galppp) >= galimages) {
			rightb.className = 'rightbdisabled';
		}
	} else {
		rightb.className = 'rightbdisabled';
	}
	return false;
}

function galleryVisible() {
	var x = 0;
	for(var i = 1; i <= n.childNodes.length; i++) {
		cur = n.childNodes[i-1];
	
		if(cur.className == 'navimgs' && x >= curpos && x < curpos+galppp) {
			//alert('Displaying ' + x);
			cur.style.display = '';
			x++;
		} else if(cur.className == 'navimgs') {
			//alert('Hiding ' + x);
			cur.style.display = 'none';
			x++;
		}
	}
}




