/*
var shade = $('<div />', {
    id: 'lightbox-shade'
}).css({
	width: $(document).width(),
	height: $(document).height(),
	position: 'fixed',
	top: 0,
	left: 0,
	background: 'rgba(0, 0, 0, 0.8)',
	opacity: 0
});

var lightbox = $('<div />', {
    id: 'lightbox-inner'
}).css({
    backgroundColor:"#FFFFFF",
    overflow:"auto",
	width: '400px',
	height: '300px',
	position: 'fixed',
	top: '50%',
	left: '50%',
	marginLeft: '-200px',
	marginTop: '-150px',
	opacity: 0
}).appendTo(shade);

shade.appendTo('body').animate({
	opacity: 1
}, function(){
	$(this).find('> :first-child').load("overlay.html", function(){
		$(this).animate({
			opacity: 1
		});
	});
});
*/

function closeLightbox( el ) {
	
	$( el.content ).animate({
		opacity: 0
	}, function() {
		$( el.wrapper ).css({
			height: '0',
			width: '0',
			overflow: 'hidden'
		}).animate({
			opacity: 0
		});
	});
	
	$( 'object, embed, iframe, select' ).css({
		visibility: 'visible'
	});
	
	var s;
	if ( s = document.documentElement.getAttribute( 'savedScrollY' ) ) {
		window.scrollTo( 0, s );
	}
	return false;
	
}



function openLightbox( el ) {

	document.documentElement.setAttribute( 'savedScrollY', window.pageYOffset );

	$( el.wrapper + ' a.close' ).click( function() {
		closeLightbox( el );
		return false;
	});
	
	// $( 'object, embed, iframe, select' ).css({
	$( 'object, embed, iframe' ).css({
		visibility: 'hidden'
	});
	
	$( el.wrapper ).css({
		width: '100%',
		height: $(document).height(),
		overflow: 'visible'
	}).animate({
		opacity: 1
	}, function() {
		$( el.content ).animate({
			opacity: 1
		});
	});

	var iOffset = 0;
	var oElement = document.getElementById( el.wrapper.substring(1) );
	var divs = oElement.getElementsByTagName( 'div' );

	if ( divs ) {
		oElement = divs[0];
	}

	while( oElement != null ) {
		iOffset += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}

	window.scrollTo( 0, iOffset );

	if ( el.callback ) {
		eval(el.callback + '()');
	}
}

$( document ).ready( function() {

	$( 'a.lightbox' ).click( function() {
		
		var lightbox = {
			wrapper : $(this).attr('href'),
			content : $( $(this).attr('href') + ' .lightbox-content' ),
			callback : $(this).attr('callback'),
		}
		
		openLightbox( lightbox );
		return false;
	});

});

