/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
 * Inline Gallery Flipper Script, v1.0
 * (c) 2004 timallen.com
 * created by bivia of bivia.com, March 2005
 * $Id: inlineGalleryFlipper.js,v 1.1 2005/03/07 03:12:13 bcurtis Exp $
 *
 *~~~~*/


var bv_GalleryInitialized = false;
var bv_Gallery = new Object();

function bv_setPic(Src, RegDim, BigDim, BigURL) {
	if (!bv_GalleryInitialized) return false;
	bv_Gallery.cursor = Src.parentNode.cursorPointer;
	var Pic = document.getElementById('picViewPic');
	var Div = document.getElementById('picViewCloseup');
	var Ht  = parseInt(RegDim.substring(RegDim.indexOf('x') +1));
	var Wd  = parseInt(RegDim.substring(0,RegDim.indexOf('x')));
	Pic.innerHTML = '<img src="'+ Src.href +'" height="'+ Ht +'" width="'+ Wd +'" />';
	Div.style.width = (Wd +2)+"px";
	if (BigDim) {
		var Pop = document.getElementById('picViewPop');
		Pop.href = BigURL;
		Pop.style.display = 'block';
		Pop.style.top = (Ht -13) +'px';
	} else document.getElementById('picViewPop').style.display = 'none';
	bv_setViewer(Src.title);
	return false;
}


function bv_setViewer(T) {
	document.getElementById('picViewCaption').innerHTML = T;
	document.getElementById('picRows').style.display = 'none';
	document.getElementById('picView').style.display = 'block';
}
function bv_setGalleryRows() {
	if (!bv_GalleryInitialized) return false;
	document.getElementById('picRows').style.display = 'block';
	document.getElementById('picView').style.display = 'none';
}


function bv_setNextPic() {
	bv_Gallery.cursor++;
	if (bv_Gallery.cursor >= bv_Gallery.pix.length || ! bv_Gallery.pix[bv_Gallery.cursor])
		bv_Gallery.cursor = 0;
	bv_Gallery.pix[bv_Gallery.cursor].firstChild.onclick();
}
function bv_setPrevPic() {
	bv_Gallery.cursor--;
	if (bv_Gallery.cursor < 0 || ! bv_Gallery.pix[bv_Gallery.cursor])
		bv_Gallery.cursor = bv_Gallery.pix.length -1;
	bv_Gallery.pix[bv_Gallery.cursor].firstChild.onclick();
}



function bv_makeGallery() {
	var AllGalleries  = document.getElementsByClassName('ul,ol','thumbDisplay');
	bv_Gallery.pix    = new Array();
	for (var xx=0; xx<AllGalleries.length; xx++) {
		var ThisGalleryPix = AllGalleries[xx].getElementsByTagName('li');
		for (var yy=0; yy<ThisGalleryPix.length; yy++) {
			var End = bv_Gallery.pix.length;
			bv_Gallery.pix[End] = ThisGalleryPix[yy];
			bv_Gallery.pix[End].cursorPointer = End;
		}
	}
	bv_Gallery.cursor = 0;
	bv_Gallery.next   = bv_setNextPic;
	bv_Gallery.prev   = bv_setPrevPic;
	bv_Gallery.show   = bv_setGalleryRows;

	document.getElementById('picViewControls').firstChild.onclick  = bv_Gallery.prev;
	document.getElementById('picViewControls').lastChild.onclick   = bv_Gallery.next;
	document.getElementById('picViewBackClicker').onclick          = bv_Gallery.show;
	
	bv_GalleryInitialized = true;
	if (window.bv_GalleryStartsAt)
		bv_Gallery.pix[window.bv_GalleryStartsAt].firstChild.onclick();
}
bv_addListener(window, 'docload', bv_makeGallery);

