
	var timerT = false;

	function imgCancel(img) {
		clearTimeout(timerT);
	}

	function imgHover(img) {

		//clear prvious timers
		if(timerT) {
			clearTimeout(timerT);
		}

		var box = document.getElementById('imgbox' + img.id);
		if (! box) return;

		var pop = document.getElementById('popup');
		if (! pop) return;

		var popshadow = document.getElementById('popupshadow');
		var popimage = document.getElementById('popupimage');
		var poplink = document.getElementById('popuplink');

		// reset any previous stuff that was set.
		pop.style.display = 'none';
		popimage.src = '/images/spacer.gif';

		var href = document.getElementById('href' + img.id);
		poplink.href = href.href;
		poplink.target = href.target;

		var smallH = parseFloat(img.style.height);
		var smallW = parseFloat(img.style.width);

		// Adjust height and width based on current image
		if(smallH > smallW) {
			var medH = '270'
			var medW = parseInt((270/110) * smallW);
			var adjW = 50;

			// center the image + 20 for shading and padding
			var adjP = parseInt( (medW + 10) );
			var adjW = parseInt( (270 - adjP - 10) / 2 ) - 30;

			//alert(smallW);
			//alert(adjP);

		} else {
			var medW = '270'
			var medH = parseInt((270/110) * smallH);
			var adjP = 280;
			var adjW = 30;
		}
		var contain = document.getElementById('popupcontain');
		pop.style.width = adjP + 'px';

		// and position the box
		var top = objGetRealTop(box);
		pop.style.top = (top - (smallH/2) + 5) + 'px';

		var left = objGetRealLeft(box);
		pop.style.left = (left - (smallW/2) - adjW) + 'px';

		popshadow.style.width  = medW + 'px';
		popshadow.style.height = medH + 'px';

		popimage.style.width  = medW + 'px';
		popimage.style.height = medH + 'px';

		// set some information in the box
		var titleF = document.getElementById('title' + img.id);
		var titleT = document.getElementById('popuptitle');
		titleT.innerHTML = titleF.innerHTML;

		// Not used right now.. 
		//var descT = document.getElementById('popupdesc');
		//descT.innerHTML = img.alt;

		//popimage.src = '/thumb/medium/' + img.id + '.jpg';
		popimage.src = path_from_id(img.id, 'medium');

		// delay to prevent the user gettting popups while moving the mouse
		//var cmd = "delayShow('/thumb/medium/" + img.id + ".jpg')";
		var cmd = "delayShow('"+path_from_id(img.id, 'medium')+"')";
		timerT = setTimeout(cmd, 600);

	}

	function delayShow(imgsrc) {

		// clear the timer
		clearTimeout(timerT);

		// set the image
		//var popimage = document.getElementById('popupimage');
		//popimage.src = imgsrc;

		// and show the area.
		var pop = document.getElementById('popup');
		pop.style.display = 'block';
	}

	function path_from_id(id, size) {
		var path = '/thumbs/';

		var a = new String(parseInt(id)).split('');
		if(a.length > 3 ) {
			for(var i=a.length; i>3; i--) a.pop();
			a.reverse();
			path +=  a.join('/')  + '/';
		}

		return  path +  size + '/' + id + '.jpg' ;
	}
