//////////////////////////////////////////////////////////////
//  ImageStore object
//
//  This object stores a bunch of images for easy access
//  This code was derived from the Joust Outliner, copyright follows:
//
// Joust Outliner Version 2.4.1
// (c) Copyright 1996-1999, Alchemy Computing Limited. All rights reserved.
// This code may be freely copied and distributed provided that it is accompanied by this header.
//
// ImageStore ctor
function ImageStoreItem(name, src, width, height) {
	this.name = name;
	this.src = src;
	this.width = width;
	this.height = height;

	this.obj = new Image(width, height);
	this.obj.src = src;
}

function ImageStoreObject() {
	this.count = -1;
	this.img = new Array();
	this.find = ImageStoreFind;
	this.add = ImageStoreAdd;
	this.getSrc = ImageStoreGetSrc;
	this.getTag = ImageStoreGetTag;
}

function ImageStoreFind(theName) {
	var foundItem = -1;
	for (var i = 0; i <= this.count; i++) {if (this.img[i].name == theName) {foundItem = i;break;}}
	return foundItem;
}

function ImageStoreAdd(n, s, w, h) {
	var i = this.find(n);
	if (i == -1) {i = ++this.count;}
	this.img[i] = new ImageStoreItem(n, s, parseInt(w, 10), parseInt(h, 10));
}

function ImageStoreGetSrc(theName) {
	var i = this.find(theName);
	var img = this.img[i];
	return (i == -1) ? '' : ((img.obj) ? img.obj.src : img.src);
}

function ImageStoreGetTag(theName, iconID, altText) {
	var i = this.find(theName);
	if (i < 0) {return ''}
	with (this.img[i]) {
		if (src == '') {return ''}
		var w = width ? (' width="' + width + '"') : '';
		var h = height ? (' height="' + height + '"') : '';
		var tag = '<img src="' + src + '"' + w + h + ' border="0" align="left" hspace="0" vspace="0"';
		tag += (iconID != '') ? ' name="' + iconID + '"' : '';
		tag += ' alt="' + ((altText)?altText:'') +  '">';
	}
	return tag;
}
