var ThumbNailViewer = {
	enableTitle: false,
	enableTransition: false,
	hideimgmouseout: true,
	targetID: "div_Picture",
	imgWidth: "640px",
	imgHeight: "415px",
	imgBorder: "0px",

	preloadedimages:[],
	targetlinks:[],
	alreadyrunflag: false,
	originalHTML: "",
	
	loadimage:function(linkobj) {
		var imagepath=linkobj.getAttribute("href");
		var showcontainer=document.getElementById(linkobj.getAttribute("rev").split("::")[0]);
		var dest=linkobj.getAttribute("rev").split("::")[1];
		var description=(ThumbNailViewer.enableTitle && linkobj.getAttribute("title"))? linkobj.getAttribute("title") : "";
		var imageHTML='<img src="'+imagepath+'" width="' + this.imgWidth + '" height="' + this.imgHeight + '" border="' + this.imgBorder + '"/>';
		if (typeof dest!="undefined")
			imageHTML='<a href="'+dest+'">'+imageHTML+'</a>';
		if (description!="")
			imageHTML+='<br />'+description;
		showcontainer.innerHTML=imageHTML;
		this.featureImage=showcontainer.getElementsByTagName("img")[0];
	},
	
	hideimage:function(linkobj) {
		var showcontainer=document.getElementById(linkobj.getAttribute("rev").split("::")[0]);
		showcontainer.innerHTML=this.originalHTML;
	},
	
	setimage:function(linkobj) {
		var imagepath=linkobj.getAttribute("href");
		var imageHTML='<img src="'+imagepath+'" width="' + this.imgWidth + '" height="' + this.imgHeight + '" border="' + this.imgBorder + '"/>';
		this.originalHTML = imageHTML;
		var showcontainer=document.getElementById(linkobj.getAttribute("rev").split("::")[0]);
		showcontainer.innerHTML = this.originalHTML;
	},
	
	cleanup:function() {
		if (this.featureImage) {
			this.featureImage.onload=null; 
			this.featureImage.onerror=null; 
			this.featureImage=null;
		}
		this.showcontainer=null;
		for (var i=0; i<this.targetlinks.length; i++) {
			this.targetlinks[i].onclick=null;
			this.targetlinks[i].onmouseover=null;
			this.targetlinks[i].onmouseout=null;
		}
	},
	
	addEvent:function(target, functionref, tasktype) {
		var tasktype=(window.addEventListener)? tasktype : "on"+tasktype;
		if (target.addEventListener)
			target.addEventListener(tasktype, functionref, false);
		else if (target.attachEvent)
			target.attachEvent(tasktype, functionref);
	},
	
	init:function() {
		this.originalHTML = document.getElementById(this.targetID).innerHTML;
		var pagelinks=document.getElementsByTagName("a");
		for (var i=0; i<pagelinks.length; i++) {
			if (pagelinks[i].getAttribute("rel") && /enlargeimage:/i.test(pagelinks[i].getAttribute("rel"))) {
				var initType=pagelinks[i].getAttribute("rel").split("::")[1];
				if (initType=="mouseover") {
					this.preloadedimages[this.preloadedimages.length]=new Image();
					this.preloadedimages[this.preloadedimages.length-1].src=pagelinks[i].href;
					pagelinks[i]["onclick"]=function() {
						ThumbNailViewer.setimage(this);
						return false;
					}
				}
				pagelinks[i]["on"+initType]=function() {
					ThumbNailViewer.loadimage(this);
					return false;
				}
				if (this.hideimgmouseout)
					pagelinks[i]["onmouseout"]=function() {
						ThumbNailViewer.hideimage(this);
					}
				this.targetlinks[this.targetlinks.length]=pagelinks[i];
			}
		}
	}
}

if (document.addEventListener)
	ThumbNailViewer.addEvent(document, function() {ThumbNailViewer.alreadyrunflag=1; ThumbNailViewer.init()}, "DOMContentLoaded")
else if (document.all && document.getElementsByTagName("a").length>0) {
	ThumbNailViewer.alreadyrunflag=1
	ThumbNailViewer.init()
}
ThumbNailViewer.addEvent(window, function(){if (!ThumbNailViewer.alreadyrunflag) ThumbNailViewer.init()}, "load")
ThumbNailViewer.addEvent(window, function(){ThumbNailViewer.cleanup()}, "unload")
