$(document).ready(function() {
	var gallery_boxes =$(".gallery_box");
	$(gallery_boxes).each(function() {
		$(this).click(function() {
			var image_name		=$(this).children("h2").text();
			var image_title		=$(this).children("h3").text();
			var image_description	=$(this).children(".fullsize_image_description").text();
			var image_url		=$(this).children(".fullsize_image_url").text();
			if (typeof(image_url) != 'undefined') {
				show_fullsize(image_name,image_title,image_description,image_url);
			}
		});
	});
	$("#gallery_fullsize").click(function() {
		$("#grey_box").hide();
		$("#gallery_fullsize").hide();
	});
	$("#grey_box").click(function() {
		$("#grey_box").hide();
		$("#gallery_fullsize").hide();
	});
});

function show_fullsize(image_name,image_title,image_description,image_url) {

	var grey_box_id		="grey_box";
	var display_id		="gallery_fullsize";

	var windowState	=(function() {
		var readScroll	={ scrollLeft:0, scrollTop:0 };
		var readSize	={ clientWidth:0, clientHeight:0 };
		var readScrollX	='scrollLeft';
		var readScrollY	='scrollTop';
		var readWidth	='clientWidth';
		var readHeight	='clientHeight';
		function otherWindowTest(obj) {
			if ((document.compatMode) && (document.compatMode == 'CSS1Compat') && (document.documentElement)) {
				return (document.documentElement);
			} else if (document.body) {
				return (document.body);
			} else {
				return (obj);
			}
		};
		if ((typeof this.innerHeight == 'number') && (typeof this.innerWidth == 'number')) {
			readSize = this;
			readWidth = 'innerWidth';
			readHeight = 'innerHeight';
		} else {
			readSize = otherWindowTest(readSize);
		}
		if ((typeof this.pageYOffset == 'number') && (typeof this.pageXOffset == 'number')) {
			readScroll = this;
			readScrollY = 'pageYOffset';
			readScrollX = 'pageXOffset';
		} else {
			readScroll = otherWindowTest(readScroll);
		} return {
			getScrollX:function() {
				return (readScroll[readScrollX]||0);
			}, getScrollY:function() {
				return (readScroll[readScrollY]||0);
			}, getWidth:function() {
				return (readSize[readWidth]||0);
			}, getHeight:function() {
				return (readSize[readHeight]||0);
			}
		};
	})();

	$("#" + grey_box_id).toggle();
	$("#" + display_id).html("<img src='" + image_url + "' alt='' class='bordered' /><h2 class='bordered'>" + image_name + "<br />" + image_title + "</h2><div class='description bordered'>" + image_description + "</div>");

	$("#" + display_id + "> IMG").load(function () {
		var display_height =$("#" + display_id).height();
		var display_width =$("#" + display_id).width();

		top_offset =Math.round(windowState.getScrollY()+((windowState.getHeight()-display_height)/2));
		if (top_offset < 10) {
			top_offset =10;
		}
		left_offset =Math.round(windowState.getScrollX()+((windowState.getWidth()-display_width)/2));
		if (left_offset < 10) {
			left_offset =10;
		}

		$("#" + display_id).css("top", top_offset + "px");
		$("#" + display_id).css("left", left_offset + "px");

		$("#" + grey_box_id).height(jQuery(document).height());
		$("#" + grey_box_id).width(jQuery(document).width());

		$("#" + display_id).toggle();
	});


	return;
};

































