Gallery = function (w,h,preload) {
	// init member vars
	this.defaultWidth = w;
	this.defaultHeight = h;
	this.preload = preload;
	this.current = 0;
	this.progressCounter = "";
	this.progressFilesStr = "files";
	this.progressOfStr = "of";
	this.files = new Array();
	this.mediabox = document.getElementById("mediabox");
	if (!this.mediabox) alert("no mediabox");//return;
	this.captionbox = document.getElementById("captionbox");	
	if (!this.captionbox) alert("no captionbox");//return;
	var medialist = document.getElementById("medialist");
	if (!medialist) alert("no medialist");//return;
	medialist.style.display = "none";	
	var items = medialist.getElementsByTagName("li");	
	for (var i=0;i<items.length;i++) {
		var a = items[i].getElementsByTagName("a")[0];
		var e = a.href.split(".");
		var extension = e[e.length - 1];		
		var file = new GalleryFile(this,this.defaultWidth,this.defaultHeight,a.href,a.innerHTML,extension,preload);
		this.files[this.files.length] = file;		
	}
	this.files[this.current].show();
}
Gallery.prototype.setProgressDisplay = function(progressId, files, of) {
	this.progressCounter = document.getElementById(progressId);
	this.progressFilesStr = files;
	this.progressOfStr = of;
	this.showProgress();
}
Gallery.prototype.showProgress = function(progressId) {
	this.progressCounter.innerHTML = this.progressFilesStr + " " + (this.getCurrent() + 1) + " " + this.progressOfStr + " " + this.getTotal();		
}
Gallery.prototype.showPrev = function() {
	this.current--;
	if(this.current<0) this.current = this.files.length-1;
	this.files[this.current].show();
	this.showProgress();
}
Gallery.prototype.showNext = function() {
	this.current++;
	if(this.current>=this.files.length) this.current=0;
	this.files[this.current].show();
	this.showProgress();
}
Gallery.prototype.getCurrent = function() {
	return this.current;
}
Gallery.prototype.getTotal = function() {
	return this.files.length;
}


GalleryFile = function(gallery,w,h,src,txt,type,preload) {
	this.gallery = gallery;
	this.width = w;
	this.height = h;
	this.source = src;
	this.caption = txt;
	this.type = type;
	if (preload && (this.type.toLowerCase() != "mov") ) {
		var img = new Image(this.width,this.height); 
		img.src = this.source;
	}
}
GalleryFile.prototype.show = function() {
	this.gallery.mediabox.innerHTML = "";
	if (this.type.toLowerCase() == "mov") {
		var qt = new QTObject(this.source, "movie", this.width, this.height);
		qt.altTxt = "Upgrade your Quicktime Player!";
		qt.addParam("bgcolor", "#ede9db");
		qt.write(this.gallery.mediabox.id);
	} else {
		var img = new ImageObject(this.source, "image", 0, 0);
		img.write(this.gallery.mediabox.id);		
	}
	this.gallery.captionbox.innerHTML = "";
	this.gallery.captionbox.innerHTML = this.caption;
}