var thumbBox, thumbImage, thumbLoading;
var currentopacity, opacitytimer, featureImage;

function centerDiv(divobj) {
var standardbody = (document.compatMode=='CSS1Compat')? document.documentElement : document.body;
var ie = document.all && !window.opera;
var scroll_top =  (ie)? standardbody.scrollTop: window.pageYOffset;
var docwidth =    (ie)? standardbody.clientWidth: window.innerWidth - 16;
var docheight =   (ie)? standardbody.clientHeight: window.innerHeight;
divobj.style.left = Math.floor(docwidth * 0.5 - divobj.offsetWidth * 0.5) + 'px';
var top = ((docheight > divobj.offsetHeight)? Math.floor(scroll_top + docheight * 0.5 - divobj.offsetHeight * 0.5): scroll_top + 10);
divobj.style.top = top + 'px'
divobj.style.visibility = 'visible';
}

function loadimage(alink) {
stopanimation();
if (thumbBox.style.visibility == 'visible') closeit();
centerDiv(thumbLoading); 
thumbImage.innerHTML = '<img src = "' + alink.getAttribute('href') + '" alt = "" />';
featureImage = new Image; //thumbImage.getElementsByTagName('img')[0];
featureImage = thumbImage.getElementsByTagName('img')[0];
featureImage.style.filter = 'progid:DXImageTransform.Microsoft.alpha(opacity=10)';
featureImage.style.opacity = '0.1';

featureImage.onload = function() {
	thumbLoading.style.visibility = 'hidden';
	centerDiv(thumbBox);
	currentopacity = 0.1;
	opacitytimer = setInterval('opacityanimation()', 20);
}

featureImage.src = alink.getAttribute('href');

featureImage.onerror = function() {thumbLoading.style.visibility = 'hidden';}
}

function setimgopacity(value) {
if (featureImage.filters && featureImage.filters[0]) {
	if (typeof featureImage.filters[0].opacity == 'number') featureImage.filters[0].opacity = value * 100;
	else featureImage.style.filter = 'alpha(opacity=' + value * 100 + ')';
}
else if (typeof featureImage.style.MozOpacity != 'undefined') featureImage.style.MozOpacity = value;
else if (typeof featureImage.style.opacity != 'undefined') featureImage.style.opacity = value;
else stopanimation();
}

function opacityanimation() {
	setimgopacity(currentopacity);
	currentopacity += 0.1;
	if (currentopacity > 1) stopanimation();
}

function stopanimation() {if (typeof opacitytimer != 'undefined') clearInterval(opacitytimer);}
function closeit() {stopanimation(); thumbBox.style.visibility = 'hidden'; thumbBox.style.top = '0px'; thumbBox.style.left = '0px';}

window.onresize = function() {if (thumbBox.style.visibility == 'visible') centerDiv(thumbBox);}