 $(document).ready(function(){
      enlarge();
 });

/* ================================================================ 
This copyright notice must be untouched at all times.
Copyright (c) 2008 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */


enlarge = function() {

$('body').append('<div id="imageBacking"></div><div id="imageHolder" class="large"></div>');
$('#imageBacking').css({position:'absolute', left:0, top:0, display:'none', textAlign:'center', background:'#ccc', zIndex:'600'});
$('#imageHolder').css({position:'absolute', left:0, top:0, display:'none', textAlign:'center', zIndex:'700'});
var imageArray = $('.enlarge');
var total = $('.enlarge').length;
/* preload images */
for (q=0; q<total; q++) {
	$(imageArray[q]).css({cursor:'pointer'});
	$('body').append('<img src="' + $(imageArray[q]).attr("alt") + '" style="position:absolute; left:-9999px; top:-9999px;" />');
}

$('.enlarge').click(function(){

	browserWindow()
	getScrollXY()

	$('#imageBacking').css({width: width, height: height, top:'0', left:'0'});
	$('#imageHolder').css({width: width + 'px', height:'0px', top:scrOfY + 'px', left:scrOfX + 'px'});
	source = $(this).attr("alt");
	title = $(this).attr("title");
	$('#imageHolder').html('<img id="largeImage" src="' + source + '" style="padding:2px; margin-top:5px; background:#fff; display:block;" /><p style="font-size:8pt">' + title +'<br /></p>');
	$('#imageHolder p').css({color:'#000', margin:'0 auto', padding:'10px 0'});

	$('#imageBacking').css({opacity:0.9, display:'block'});
	$('#imageHolder').css({display:'block', visibility:'hidden'});
	
	factor = 1;
	if($('#largeImage').innerWidth() > (totalX-50)) factor = (totalX-50)/$('#largeImage').innerWidth();
	if($('#largeImage').innerHeight() > (totalY-50) && (totalY-50)/$('#largeImage').innerHeight() < factor) factor = (totalY-50)/$('#largeImage').innerHeight();
	imgWidth = $('#largeImage').innerWidth()*factor;
	imgHeight = $('#largeImage').innerHeight()*factor;
		
	scrOfY=scrOfY+((totalY-imgHeight)/2-15);
	$('#imageHolder').css({width: width + 'px', height:'0px', top:scrOfY + 'px', left:scrOfX + 'px'});

	$('#largeImage').css({display:'none', height:imgHeight, width:imgWidth, margin:'0 auto', cursor:'pointer'});
	$('#imageHolder').css({visibility:'visible', cursor:'pointer'});

	$('#largeImage').fadeIn('middle');

	$('#imageHolder p').css({width: imgWidth + 'px', display:'none'});

	$('#imageHolder p').slideDown(500);


$('#imageHolder').click(function(){
	$('#imageHolder').fadeOut('middle');
	$('#imageBacking').fadeOut('fast');
});

$('#imageBacking').click(function(){
	$('#imageHolder').fadeOut('middle');
	$('#imageBacking').fadeOut('fast');
});


});

/* find browser window size */
function browserWindow () {
	width = 0
	height = 0;
	if (document.documentElement) {
		width = document.documentElement.offsetWidth;
		height = document.documentElement.offsetHeight;
	} else if (window.innerWidth && window.innerHeight) {
		width = window.innerWidth;
		height = window.innerHeight;
	}
	return [width, height];
}
/* find total page height */
function getScrollXY() {
	scrOfX = 0; 
	scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
		totalY = (window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?       document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null);

		totalX = (window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null);
	return [ scrOfX, scrOfY, totalY, totalX ];
}

return false;
}