
/** JQuery must be loaded... */

(function($) {
	var thumbWidth = 120;
	var thumbHeight = 120;
	var crop = true;
	
	
	
	var theDiv = false;
	var baseHref = false;
	
	var sizeAndCrop = thumbWidth + '/' + thumbHeight + '/' + (crop?1:0) + '/';

	function linkMouseOver(e, lnk) {
		if(!e) e = window.event;
		if(!e) return;
		if(!theDiv) {
			//create
			var id = 'dvThumbId' + Math.round(Math.random() * 10000);
			$("body").append("<div id='"+id+"'></div>");
			theDiv = $("#" + id).get(0); 
			theDiv.style.display = 'none';
			theDiv.style.position = 'absolute';
			theDiv.style.top = '0px'; 
			theDiv.style.left = '0px'; 
			theDiv.style.border = 'solid 1px #000000';
		} 
			theDiv.style.top =  (e.pageY + 25) + 'px'; 
			theDiv.style.left = (e.pageX + 25) + 'px'; 
			
			
		theDiv.innerHTML = "<img src='http://thumbs.vdburgh.net/v1/get/"+sizeAndCrop+"?url=" + escape(lnk) + "' />";
		//theDiv.innerHTML = "<img src='http://thumbs.vdburgh.net/v1/get/"+sizeAndCrop+ lnk + "' />";
		theDiv.style.display = 'block';
	}
	function linkMouseOut(e) {
		if(theDiv) theDiv.style.display = 'none';
		return; 
	}
	
	$(function() {
		//var baseHref = false;
		var baseEl = $("base");
		if(baseEl.size() > 0) {
			baseEl = baseEl.get(0);
			if (baseEl.href) {
				baseHref = baseEl.href;
			} 
		}
		
		$("a").hover(function(e) {
			var l = this.href;
			if(!l) return;
			var s = new String('' + l);
			var isAbsolute = false;
			if(s.indexOf('http://') == 0) {
				//ok
				isAbsolute = true;
			} else if(s.indexOf('https://') == 0 || s.indexOf('ftp://') == 0 || s.indexOf("://")!=-1) { 
				return;
			} else if(!baseHref){
				//error
				return;
			}
			if(!isAbsolute)  
				s = baseHref + s;
			//add queue
			linkMouseOver(e,s);   
			
		}, function(e) {
			linkMouseOut(e);
		});
		
	});
})(jQuery);


