var fadeBackVisible = false;

function fadeBackIn() {
	Effect.Appear('fadeBack', {to: 1.0, duration: 0.6});
	fadeBackVisible = true;
}

function fadeBackOut() {
	Effect.Fade('fadeBack', {duration: 0.2});
	fadeBackVisible = false;
	document.stopObserving('click', fadeBackOut);
}

function centerFadeBack() {
	var innerHeight;
	if(document.documentElement && document.documentElement.clientHeight) {
		//IE6
		innerHeight = document.documentElement.clientHeight;
	} else if(document.body && document.body.clientHeight) {
		//IE4+
		innerHeight = document.body.clientHeight;
	} else {
		innerHeight = window.innerHeight;
	}
	
	$('fadeBack').style.top = (document.viewport.getScrollOffsets().top + innerHeight - $('fadeBack').getHeight()) + 'px';
}

Event.observe(window, 'scroll', function () {
	centerFadeBack();
});
 
Event.observe(window, 'resize', function () {
	centerFadeBack();
});

Event.observe(document, 'mousemove', mousePos);

Event.observe(document, 'click', hideThumb);

var activeThumb = new Object();
activeThumb.div = "rolloverThumb";
activeThumb.width = 1;
activeThumb.height = 1;

var thumbOver = false;

function mousePos(theEvent){
	if(thumbOver == true) {
		mouseX = Event.pointerX(theEvent);
		mouseY = Event.pointerY(theEvent);
		$(activeThumb.div).style.top = mouseY - activeThumb.height - 10 + 'px';
		$(activeThumb.div).style.left = mouseX + 10 + 'px';
	}
}

function showThumb(imgSrc, width, height, label) {
	$('theThumb').src = imgSrc;
	$('rolloverThumb').style.width = (width + 10) + 'px';
	$('rolloverThumb').style.height = (height + 26) + 'px';
	$('theThumbLabel').innerHTML = label;
	Effect.Appear('rolloverThumb', {to: 1.0, duration: 0.2});
	activeThumb.width = (width + 10);
	activeThumb.height = (height + 26);
	thumbOver = true;
}

function hideThumb() {
	thumbOver = false;
	$('rolloverThumb').hide();
}

function showEnlarged(imgSrc, width, height) {
	$('enlargedImage').innerHTML = '<img src="' + imgSrc + '" alt="" /><div id="enlargedImageLabel" style="width: ' + width + 'px;">Click anywhere to return.</div>';
	$('enlargedImage').style.width = width;
	$('enlargedImage').style.height = height + 40;
	$('enlargedImage').style.marginLeft = '-' + Math.floor(width / 2) + 'px';
	$('enlargedImage').style.marginTop = '-' + Math.floor(height / 2) + 'px';
	fadeBackIn();
	centerFadeBack();
	setTimeout("Event.observe($('fadeBack'),'click', fadeBackOut);",500);
}

function doNothing() {
	//it's the function that does nothing... and more!
}
