var showing_popup = false;
var current_popup = '';
var current_id = '';
var photo_bottom = 500;

function $( id ) {
	return document.getElementById( id );
}

function show_bubble() {
	if( showing_popup ) return;
	$('bubble').style.visibility = 'visible';
}

function hide_bubble() {
	$('bubble').style.visibility = 'hidden';
}

function show_popup( id ) {
	
	//hide any other popups first
	if( current_popup != '' ) hide_popup( current_popup );
	
	//ensure popup isn't below the photo
	while( ( parseInt( $(id).style.top, 10 ) + $(id).offsetHeight ) > photo_bottom )
		$(id).style.top = ( parseInt( $(id).style.top, 10 ) - 10 ) + "px";
	
	$(id).style.visibility = 'visible';
	showing_popup = true;
	current_popup = id;
}

function hide_popup( id ) {
	current_popup = '';
	$(id).style.visibility = 'hidden';
	showing_popup = false;
}

function set_opacity( elm, val ) {

	elm.style.opacity = val;
	elm.style.MozOpacity = val;
	elm.style.KhtmlOpacity = val;
	elm.style.filter = 'alpha(opacity=' + ( val * 100 ) + ')';

}

function show_person( id ) {

	//start the page fader (should take 350ms)
	set_opacity( $('our_people_fadeout'), 0 );
	$('our_people_fadeout').style.display = 'block';
	setTimeout( function() { fade_cover_in( 0.1 ); }, 50 );
	
	//then show the container, large photo and text
	setTimeout( function() {
		// return;
		$('our_people_full_container').style.visibility = 'visible';
		$('people' + id ).style.display = 'block';
	}, 400 );

	//remember the current ID
	current_id = id;

}

function hide_person() {
	
	//hide the page fader and container
	$('our_people_fadeout').style.display = 'none';
	$('our_people_full_container').style.visibility = 'hidden';
	if( current_id != '' ) {
		$('people' + current_id ).style.display = 'none';
		current_id != '';
	}
	
}

function fade_cover_in( opacity ) {
	
	if( opacity >= 0.7 ) return;
	
	set_opacity( $('our_people_fadeout'), opacity );
	
	setTimeout( function() { fade_cover_in( opacity + 0.1 ); }, 50 );
	
}
