

function img_onload() {
    var nslider = this.nslider;
    var photo = document.getElementById(nslider.oName + '-photo');
    var isrc = this.src;

    photo.setAttribute("src", isrc);
    if (nslider.showthumb) {
	photo.setAttribute("title", "[click to enlarge]");
	photo.setAttribute("height", nslider.tHeight);
    } else {
	if (this.nothumbs) {
	    photo.setAttribute("title", "[click to reduce]");
	} else {
	    photo.setAttribute("title", "[click for next]");
	}
	photo.setAttribute("height", nslider.iHeight);
    }
}

function nslider_update() {
    var isrc;
    var desc = this.desc[this.imgno];
    var text = document.getElementById(this.oName + '-desc');
    // alert('desc = ' + desc + ' text = ' + text);

    if (this.showthumb) {
	isrc = this.timgs[this.imgno];
	desc = desc + ' (thumb)';
    } else {
	isrc = this.imgs[this.imgno];
	// desc = desc + ' (normal)';
    }

    this.image = new Image();
    this.image.nslider = this;
    this.image.onload = img_onload;
    this.image.src = isrc;

    if (text) {
	if (desc && (desc.length > 0)) {
	    text.innerHTML = (this.imgno+1) + '. ' + desc;
	} else {
	    text.innerHTML = (this.imgno+1) + '. ' + img;
	}
    }
}

function nslider_toggle() {
    if (this.showthumb) {
	this.showthumb = 0;
    } else {
	if (this.nothumbs) {
	    this.next();
	} else {
	    this.showthumb = 1;
	}
    }
    this.update();
}

function nslider_first() {
    this.imgno = 0;
    this.update();
}

function nslider_prev() {
    this.imgno--;
    if (this.imgno < 0)
	this.imgno = this.imgcnt - 1;
    this.update();
}

function nslider_next() {
    this.imgno++;
    if (this.imgno >= this.imgcnt)
	this.imgno = 0;
    this.update();
}

function nslider_addimg(isrc, desc, tsrc)
{
    if (tsrc == null) {
	tsrc = isrc;
    }
    this.imgs.push(isrc);
    this.timgs.push(tsrc);
    this.desc.push(desc);
    this.imgcnt = this.imgs.length;
}

function nslider(name, iheight, theight) {
    this.showthumb = 1;
    this.nothumbs = 0;
    this.imgno = 0;
    this.imgcnt = 0;
    this.oName = name;
    this.iHeight = iheight;
    this.tHeight = theight;
    this.imgs = new Array();
    this.timgs = new Array();
    this.desc = new Array();
    this.update = nslider_update;
    this.toggle = nslider_toggle;
    this.first = nslider_first;
    this.prev = nslider_prev;
    this.next = nslider_next;
    this.addimg = nslider_addimg;
    if (!this.tHeight) {
	this.nothumbs = 1;
    }
    if (this.nothumbs) {
	this.showthumb = 0;
    }
}

