function ImagePreview() {
	
	ImagePreview.TIMEOUT = 1000;
	
	this.show = function(type, db_id, width, url) {
		me.type = type;
		me.db_id = db_id;
		if(width) me.width = width;
		me.imageUrl = null;
		if(url) me.imageUrl = url;
		
		if(me.timer) {
			window.clearTimeout(me.timer);
			me.timer = null;
		};
		me.timer = window.setTimeout(me.imagePreview, ImagePreview.TIMEOUT);
	};
	
	this.hide = function() {
		if(me.timer) {
			clearTimeout(me.timer);
			me.timer = null;
		}
		me.timer = window.setTimeout(me.hidePreview, ImagePreview.TIMEOUT);
	};
	
	this.hidePreview = function() {
		if(me.imageDiv)
			me.imageDiv.style.display = "none";
	};
	
	this.imagePreview = function() {
		if(!me.imageDiv) {
			me.imageDiv = document.createElement("div");
			me.imageDiv.style.border = "1px solid #000000";
			me.imageDiv.style.backgroundColor = "#FFFFFF";
			me.imageDiv.style.padding = "5px";
			me.imageDiv.style.position = "absolute";
		} else {
			me.imageDiv.style.display = "block";
		};
		
		if(me.imageDiv.firstChild) {
			me.imageDiv.removeChild(me.imageDiv.firstChild);
		};
		
		var img = document.createElement("img");
		var options = "t="+me.type+"&id="+me.db_id;
		if(me.type == 'raw' && me.imageUrl)
			options = "raw_url="+me.imageUrl;
		if(me.width)
			options += "&w="+me.width;
		
		img.src = "/lib/scripts/image.html?"+options;
		
		me.imageDiv.appendChild(img);		
		
		document.body.appendChild(me.imageDiv);
		var top = mouseY;
		if(parseInt(mouseY+me.imageDiv.offsetHeight,10) > viewportheight) {
			if(parseInt(mouseY-(me.imageDiv.offsetHeight),10) > 0) {
				top = mouseY-(parseInt(me.imageDiv.offsetHeight+20,10));
			}
		};		
		me.imageDiv.style.top = top+"px";
		
		var left = mouseX;
		var offsetWidth = me.imageDiv.offsetWidth;
		if(img.offsetWidth == 0) offsetWidth += me.width;
		if(parseInt(mouseX+offsetWidth+10,10) > viewportwidth) {
			left = mouseX-(parseInt(offsetWidth+10,10));
		} else if(parseInt(left-(offsetWidth+10),10) < 0) {
			left = mouseX+(parseInt(offsetWidth+10,10));
		} else {
			left += 10;
		};
		me.imageDiv.style.left = left+"px";

	};
	
	this.setRawUrl = function(boolean) {
		me.isRawUrl = boolean;
	};
	
	this.setImageUrl = function(img_url) {
		me.imageUrl = img_url;
	};
	
	this.init = function() {
		
	};
	
	var me = this;
	this.imageDiv = null;
	this.timer = null;
	this.type = null;
	this.db_id = 0;
	this.width = 0;
	this.isRawUrl = null;
	this.imageUrl = null;
	this.init();
}