this.imagePreview=function(){
	function getDims(e){
		p=new RegExp('(Item #\\d+-\\d+).*?\\((\\d+)x(\\d+)\\)');
		m=p.exec( e.target.alt );
		dims=new Array();
		dims['width']=300;
		dims['height']=410;
		return dims;
	}

	jQuery.fn.setPos=function(e){
		dims=getDims(e);
		return this.css("top",(e.pageY-(dims['height']>>1)+50)+"px")
			.css("left",((e.pageX-dims['width']>>1)+200)+"px");
	};

	$("img.preview").hover(function(e){
		name=this.src;
		dims=getDims(e);
		body='<img width="'+dims['width']+'" height="'+dims['height']+'" src="'+name+'" alt="'+this.alt+'" />';
		$("body").append('<p id="preview">'+body+'</p>');
		$("#preview").setPos(e);
		$("#preview").show();
	},
	function(){
		$("#preview").remove();
	});

	$("img.preview").mousemove(function(e){
		$("#preview").setPos(e);
	});
};

// starting the script on page load
$(document).ready(function(){
	imagePreview();

	$('A[rel="popup"]').click( function(){
		window.open( $(this).attr('href'),'Image popup','width=300,height=420' );
		return false;
	});
});
