
/* ================================================================ 
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:'#fff', zIndex:'600'});
$('#imageHolder').css({position:'absolute', left:0, top:0, display:'none', textAlign:'left', zIndex:'600'});
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()

if (height<totalY) { height=totalY; }

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

	$('#imageBacking').css({opacity:0.95, display:'block'});
	$('#imageHolder').css({display:'block', visibility:'hidden'});
	imgWidth = $('#largeImage').innerWidth() - 80;
	imgHeight = $('#largeImage').innerHeight() - 80;
	$('#largeImage').css({display:'none', height:imgHeight, width:0, margin:'0 auto'});
	$('#imageHolder').css({visibility:'visible'});

	$('#largeImage').animate({"width": imgWidth}, 500);

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

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

});

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

/* find browser window size */
function browserWindow () {
 width = 0
 height = 0;
 if (document.documentElement) {
  width = document.body.offsetWidth;
  height = document.body.scrollHeight+document.body.offsetHeight;
 }
 width=width-30;
 height=height-20;
 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;
}

