// PICTURE BOX
function pictureBox(image, swap) {
	$("."+swap).click(function(event) {
		event.preventDefault();
		$("#"+image).attr("src", $(this).attr("href"));
		$("#"+image).attr("rel", $(this).attr("rel"));
	});
}

$(document).ready(function() {
//function stuff() {
	// initialize
	$("#subsection_container").prepend('<div id="lightbox">   <div id="lightbox_bg"></div> <div id="lightbox_img"><img src="" alt=""/></div>   </div>');
	
	// functions
	$(".picture_box_pic").click(function() {
		var swapImage = $(this).attr("rel");
		var scrollXY = getScrollXY();
		var picture_topMargin = scrollXY[1];
		//var picture_topMargin = 300;
		
		//set the lightbox size and margins
		$("#lightbox_img").css("margin-top", picture_topMargin + 25 );
		switchLightboxImg(swapImage);
		$("#lightbox").fadeIn();
	});
	
	$("#lightbox").click(function (){
		$(this).fadeOut(function() {
			$("#lightbox_img").children("img").attr("src", "");
		});
	});
//}
});// document ready

function switchLightboxImg(path) {
	var newImg = new Image();
	var imageWidth;
	var imageHeight;

	newImg.onload = function() {
		//$("#lightbox_img").css({ width: this.width+"px", height: this.height+"px" });
		
		$("#lightbox_img").animate({ 
        	width: this.width,
			height: this.height
      		}, function() {
				$("#lightbox_img").children("img").attr("src", path);
			});

		imageWidth = this.width;
		imageHeight = this.height;
	};
	newImg.src = path;
}


function getScrollXY() {
    var x = 0, y = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape
        x = window.pageXOffset;
        y = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        // DOM
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        // IE6 standards compliant mode
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    }
    return [x, y];
}