
	var timerT = false;

	function imgCancel(img) {
		clearTimeout(timerT);
	}
	
	
	function imgHover(img, accountId) {
		//clear prvious timers

		if(timerT) {
			clearTimeout(timerT);
		}
		var currentImageStr =  document.getElementById(img.id).src;
		var isCustomImage = false;

		//now if the image has something like .com in it, then it's a default image, otherwise, it's overriden
		if (currentImageStr.indexOf('_com__') < 0){
			isCustomImage = true;
		}
		
		var currentImageArr = currentImageStr.split("/");
		var currentImageLen = currentImageArr.length;
		currentImageLen  = currentImageLen - 1;
		var currentImage = currentImageArr[currentImageLen];
		
		var box = document.getElementById('template_display' + 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/common/spacer.gif';

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

		var smallH = parseFloat(img.style.height);
		var smallW = parseFloat(img.style.width);
		
		//To make sure then img have a size
		if (isNaN(smallH)) smallH= 300;
		if (isNaN(smallW)) smallW= 225;
		
		// 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;

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

		// and position the box

		var top = objGetRealTop(box);
		pop.style.top = (top - box.offsetHeight) + 'px';
  
		var left = objGetRealLeft(box);
		pop.style.left = (left - box.offsetWidth + 70) + 'px';

		popimage.style.width  = '300px';
		popimage.style.height = '225px';

		// 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;

		if (accountId != null && accountId != '' && isCustomImage == true)
			popimage.src = '/images/designs/popupimages/' + accountId  + '/' + currentImage;
		else
			popimage.src = '/images/designs/popupimages/' + currentImage;
			 
		//popimage.src = path_from_id(img.id, 'medium');

		// delay to prevent the user gettting popups while moving the mouse
		//var cmd = "delayShow('/images/designs/popupimages/' + img.id + '.gif')";
		//var cmd = "delayShow('"+path_from_id(img.id, 'medium')+"')";
		timerT = setTimeout("delayShow()", 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' ;
	}
