$(document).ready(function(){
	// move overlay to body
	//div_overlay = $('#DivOverlaySuperbox');
	//overlay_background = $('.DivOverlayBackground');
	//if(div_overlay != null){
		
		//$('body').first().append(div_overlay).append(overlay_background);
		// set triggers
		$('.div_overlay_trigger').click(function(){
			show_overlay(this);
		});
		$('.DivOverlayBackground').click(hide_overlays);
		$('.DivOverlayCloseButton').click(hide_overlays);
		$('body').keydown(function(event){
			if(event.keyCode == 27){
				hide_overlays();
			}
		});
	//}
});

function hide_overlays(){
	$('.DivOverlay').fadeOut(200);
	$('.DivOverlayBackground').fadeOut(200);
}

function show_overlay(element){
	id = $(element).attr('rel');
	overlay = $(id);
	body = $('body').first();
	
	scroll_top = body.scrollTop();
	overlay_left = (body.outerWidth() - overlay.outerWidth()) / 2;
	background_height = Math.max(body.outerHeight(true), overlay.outerHeight(true) + scroll_top);
	
	$('.DivOverlayBackground').css('height', background_height).fadeIn(200);
	overlay.css('left', overlay_left).css('top', scroll_top + 20).fadeIn(500);
}

