
function gallery() {
	this.showTime = 5000;
	this.base = 'http://www.lauranidra.com/';
	this.nextFn = function() {myGallery.playNext()};
	this.galleries = {};
	this.newGallery('lauranidra','LauraNidra');
}

gallery.prototype.set = function(idx) {
	var el,wd;
	var elVert = document.getElementById('photoVert');
	var elHorz = document.getElementById('photoHorz');
	if (this.arr[idx].indexOf('400')!=-1) {
		wd = '400';
		el = document.getElementById('photoVertImg');
		elVert.style.display = 'block';
		elHorz.style.display = 'none';
	} else {
		wd = 675;
		el = document.getElementById('photoHorzImg');
		elVert.style.display = 'none';
		elHorz.style.display = 'block';
	}
	el.width = wd;
	el.src = this.base+'gallery/'+this.photos.dirpath+'/'+this.arr[idx];
	this.idx = idx;

	// Set the photo title
	var el = document.getElementById('photoTitle');
	if (el) el.innerHTML = this.photoTitle(this.arr[idx]);

	// Preload the next image
	el = document.getElementById('preloadImg');
	var i = this.idx + 1;
	if (i >= this.arr.length) i = 0;
	if (el) el.src = this.base+'gallery/'+this.photos.dirpath+'/'+this.arr[i];
}

gallery.prototype.photoTitle = function(nm) {
	if (nm.substr(0,2) == 'xx') return '';
	nm = nm.replace(/\d*/g,'');
	nm = nm.replace(/\.jpg/g,'');
	nm = nm.replace(/^\s+|\s+$/g,'');
	return nm;
}

gallery.prototype.newGallery = function(nm,title) {
	if (this.playing && this.timer) clearTimeout(this.timer);
	this.playing = false;
	this.gallery = nm;
	var gg = this.galleries;
	var el = document.getElementById('galleryTitle');
	if (el) el.innerHTML = title || nm;
	this.idx = 0;
	if (!gg[nm]) return this.doScript('gallery/lcl.photolist.php?callbackName=myGallery.play&path='+nm);
	this.play();
}

gallery.prototype.play = function(json) {
	if (this.playing && this.timer) clearTimeout(this.timer);
	var gg = this.galleries;
	if (json) gg[this.gallery] = eval('('+json+')');
	var el = document.getElementById('playBtn');
	if (el) {
		el.src = this.base + 'img/gallerynav_pause.gif';
		el.title = 'Pause';
	}
	this.photos = gg[this.gallery];
	this.photo = this.photos.files[0];
	this.arr = this.photos.files;
	this.set(this.idx);
	this.playing = true;
	this.timer = setTimeout(this.nextFn,this.showTime);
}

gallery.prototype.pause = function() {
	var el = document.getElementById('playBtn');
	if (el) {
		el.src = this.base + 'img/gallerynav_play.gif';
		el.title = 'Play';
	}
	if (!this.playing) return this.playNext();
	if (this.timer) clearTimeout(this.timer);
	this.playing = false;
}

gallery.prototype.next = function() {
	var max = this.arr.length;
	var nxt = this.idx + 1;
	if (nxt >= max) nxt = 0;
	this.idx = nxt;
	if (this.playing) return this.play();
	this.set(nxt);
}

gallery.prototype.previous = function() {
	var max = this.arr.length;
	var nxt = this.idx - 1;
	if (nxt < 0) nxt = max-1;
	this.idx = nxt;
	if (this.playing) return this.play();
	this.set(nxt);
}

gallery.prototype.playNext = function() {
	this.next();
	this.play();
}

gallery.prototype.close = function() {
	window.close();
	this.next();
	this.play();
}

gallery.prototype.doScript = function(u,tg) {
	var scp = document.createElement('script');
	scp.setAttribute('language',"JavaScript");
	document.getElementsByTagName(tg||'body')[0].appendChild(scp);
	scp.setAttribute('src',u);
}


window.myGallery = new gallery();

//document.write('<xmp>'+myGallery.photos.files+'</xmp>');

