/** http://kilianvalkhof.com/2008/javascript/building-your-own-lightbox-part-1/ **/
//$(document).ready(function(){
// add a click event
//	$(".lightbox").click(function(){
//		overlayLink = $(this).attr("href");
//		window.startOverlay(overlayLink);
//		return false;
//	});
//});

function startOverlay(overlayLink) {
//add the elements to the dom
	$("body")
		.append('<div class="overlay"></div><div class="overlay_container"></div>')
		.css({"overflow-y":"hidden"});

//animate the semitransparant layer
	$(".overlay").animate({"opacity":"0.6"}, 400, "linear");

//add the lightbox image to the DOM
	$(".overlay_container").html('<img src="'+overlayLink+'" alt="" />');

//position it correctly after downloading
	$(".overlay_container img").load(function() {
		var imgWidth = $(".overlay_container img").width();
		var imgHeight = $(".overlay_container img").height();
		$(".overlay_container")
			.css({
				"top":        "50%",
				"left":       "50%",				
				"width":      imgWidth,
				"height":     imgHeight,
				"margin-top": -(imgHeight/2),
				"margin-left":-(imgWidth/2) //to position it in the middle
				
			})
			.animate({"opacity":"1"}, 400, "linear");

// you need to initiate the removeoverlay function here, otherwise it will not execute.
		window.removeOverlay();

		$("#recoverpasssave").click(function() {
			$.post("/users/forgot", {'data[User][email]':$("#UsersEmail").val()} );
		});
		//duplicates the removeOverlay click function
		$("#recoverpasscancel").click(function() {
			$(".overlay_container, .overlay").animate({"opacity":"0"}, 200, "linear", function(){
				$("body").css({"overflow-y":"visible"});
				$(".overlay_container, .overlay").remove();
			});
		});		
	});
}
function removeOverlay() {
// allow users to be able to close the lightbox
	$(".overlay").click(function(){
		$(".overlay_container, .overlay").animate({"opacity":"0"}, 200, "linear", function(){
			$("body").css({"overflow-y":"visible"});
			$(".overlay_container, .overlay").remove();			
		});
	});
}
/* fin. */

