// JavaScript Document
$(function() {
	function presentation(event) {
		//alert('test');
		event.preventDefault();
		//event.stopPropagation();
		//alert('test');
		var set_frame_width = 680;
		var set_frame_height = 585;
		get_filename = $(this).attr('id');
		body_width = $(window).width();
		monitor_height = $(window).height();
		presen_left = Math.round((body_width - set_frame_width) * 0.5);
		presen_top = Math.round((monitor_height - set_frame_height) * 0.5 + $(window).scrollTop());
		$('#earth_round').show();
		$('#earth_round').css(
			{
				'position':'absolute',
				'top': Math.round((monitor_height - 30) * 0.5 + $(window).scrollTop()) + 'px',
				'left': Math.round((body_width - 30) / 2) + 'px'
			}
		);
		//alert(popup_left);
		//alert(popup_button_close);
		$('#presen_frame')
		.css(
			{
				'position' : 'relative',
				'top' : presen_top + 'px',
				'left' : presen_left + 'px',
				'width' : '680px',
				'height' : '585px',
				'background':'#fff',
				'z-index' : '3'
			}
		);
		$('#top_bar')
		.css(
			{
				'background':'url(../images/presentations/' + get_filename + '/' + get_filename + '_title.gif)  #969180',
				'windth':'680px',
				'height':'30px'
				//'padding':'3px 5px'
			}
		);
		$('#top_bar p')
		.css(
			{
				'text-align':'right',
				'padding':'3px 5px'
			}
		);
		$('#top_bar img')
		.css({'cursor':'pointer'})
		.bind('click', function() {
			//$('#presen_iframe').hide();
			$('#presen_iframe').attr('src','');
			$('#presen_window').hide();
			
		});
		$('#presen_bg')
		.css(
			{
				'background':'#000',
				'position' : 'absolute',
				'top' : '0',
				'left' : '0',
				'width' : body_width + 'px',
				'height' : $(document).height() + 'px',
				'z-index' : '2',
				'opacity' : '0.3'
			}		
		);
		$('#presen_window').show();
		$.ajax({
			type:"GET",
			//url:"http://www.harlemunited.org/images/presentations/" + get_filename + "/" + get_filename + ".gif",
			//url: 'http://www.harlemunited.org/presentation.php?date=' + get_filename,
			url: 'http://www.harlemunited.org/' + get_filename + '.php?date=' + get_filename,
			cache:"false",
			complete: function(XHR) {
				//alert(get_filename);
				//$('#presen_iframe').attr('src', 'http://www.harlemunited.org/presentation.php?date=' + get_filename);
				$('#presen_iframe').attr('src', 'http://www.harlemunited.org/' + get_filename + '.php?date=' + get_filename);
				//$('#presen_iframe').show();
				$('#earth_round').hide();
			}
		});
	}
	$('body')
	.append($('<div>')
		.attr('id', 'presen_window')
		.append($('<div>')
			.attr('id', 'presen_frame')
			.append($('<div>')
				.attr('id', 'top_bar')
				.append($('<p>')
					.append($('<img>')
						.attr('src', 'http://www.harlemunited.org/images/button_close_popup.png')					
					)					
				)
			)
			.append($('<iframe id="presen_iframe" width="680" height="630" scrolling="no" frameborder="0">'))
		)
		.append($('<div>')
			.attr('id', 'presen_bg')					
		)
	);
	$('#presen_window')
	.css(
		{
			'position':'absolute',
			'top' : '0',
			'left' : '0'
		}
	);
	$('#presen_window').hide();
	$('#presentation a')
	.bind('click', presentation);
	
	
	// Begin Earth
	$('body')
	.append($('<div>').attr('id', 'earth_round')
		.append($('<img>').attr('src', 'http://www.harlemunited.org/images/earth_round.gif'))
	);
	$('#earth_round')
	.css(
		{
			'position':'absolute',
			'top':'0',
			'left':'0',
			'width':'30px',
			'height':'30px',
			'z-index':'90'
		}
	);
	$('#earth_round img')
	.css(
		{
			'width':'30px',
			'height':'30px'
		}
	);
	$('#earth_round').hide();
	// End Earth
	
});
// ＠。