var flag = 0; //open window flag
	
function closeBio(id){
	$('bio_container').empty();
	$('bio_container').setStyle('visibility', 'hidden');
	$('bio_container').setStyle('top', '0');
	flag=0;
}


window.addEvent('domready', function(){
//creates fake radio buttons and switches them on click									 
$('search_type_www_label').addEvent('click', function(){
	$('search_type_libin_label').removeClass('search_type_libin_on');
	$('search_type_libin').checked=false;
	$('search_type_www_label').addClass('search_type_www_on');
	$('search_type_www').checked=true;
	
});

$('search_type_libin_label').addEvent('click', function(){
	$('search_type_www_label').removeClass('search_type_www_on');
	$('search_type_www').checked=false;
	$('search_type_libin_label').addClass('search_type_libin_on');
	$('search_type_libin').checked=true;
});									 
									 
//will add site:... when search libin is selected.
$('masthead_search').addEvent('submit', function(e) {
	if($('search_type_libin').getValue() =="on"){
		$('q').value='site:'+$('site').getValue()+" "+$('q').getValue();;
	}
});




//Member Popups
//looks for all a's marked with the bio class
var list = $$('.bio');
list.each(function(element) {		
	//for each one found set an event for the link
	element.addEvent('click', function(e) {
		e = new Event(e).stop();	
		//if a window is open, close it and reset the flags
		if(flag) {
			$('bio_container').empty();
			$('bio_container').setStyle('visibility', 'hidden');
			$('bio_container').setStyle('top', '0');
			flag=0;
		}
		
		//find the page for the clicked user	
		element.url = "../bios/"+element.id+".html";
		getPage(element.url, element.id);
	});
});	
	
	
function getPage(url, id) {
	//perform ajax call and dump the aquired file onto the page
	var ajax = new Ajax(url, {
		method: 'get',
		onComplete: function() {
			var el = $('bio_container');	
			el.setHTML(this.response.text)
			var top = el.getPosition().y;	
			var bot = $('layout_footer').getPosition().y;
			var size = 	el.getSize().size.y;
			var offset = ((window.getHeight() - size) / 2)-(top- window.getScrollTop());					
			if((top + offset) < 373) {
				var topCutoff = 374 - (top+offset);
				el.setStyle('top', offset+topCutoff);
			}
			else if((top + offset+size) > bot) {
				var botCutoff = top + offset+size - bot	
				el.setStyle('top', offset-botCutoff);
			}else {				
			el.setStyle('top', offset);
			}
			el.setStyle('visibility', 'visible');
			}
	}).request();	
	
	//set flags
	flag=1;
		
	}
});




// set active page
//DOES NOT WORK WITH LOCAL PATH, USE TEST SERVER
function i_setActivePage() {if((i_menu = document.getElementById('menu_'+location.pathname.substring(location.pathname.lastIndexOf('/')+1, ((location.pathname.lastIndexOf('-') != -1) ? location.pathname.lastIndexOf('-') : location.pathname.lastIndexOf('.'))))) != null) i_menu.className="active"; }
