// Pop-up text boxes

$( 'head' ).append ( '<link rel="stylesheet" type="text/css" href="css/pop.css" media="screen" />' );

var pop_done = false;

$( document ).ready ( function ()
	{
		$( ".pop" ).click ( function ()
			{
				if ( pop_done ) {
					pop_hide ();
				} else {
					pop_show ( $( this ).attr ( 'src' ) );
				}
			}
		);
	}
);

function pop_show ( url ) {
	url = url.substr ( 0, 6 ) + ".jpg";
	$( document.body ).append( "<div id='pop_window'><img src='" + url + "' alt='' /><p>Click picture to hide it</p></div>" );
	$( "#pop_window img" ).click ( pop_hide );
	$( window ).resize ( pop_position ).scroll ( pop_position );
	pop_done = true;
	pop_position();
}

function pop_hide() {
	$( '#pop_window' ).slideUp ( "fast");
	pop_done = false;
}

function pop_position() {
	if ( pop_done ) {
		$( "#pop_window" ).css (
			{
				left: (( $( window ).width() - 444 ) / 2 ) + "px",
				top: ((( $( window ).height() - 360 ) / 2 ) + $( window ).scrollTop() ) + "px",
				display: "none"
			}
		);
		$( "#pop_window" ).slideDown ( "fast" );
	}
}

