interval = 400;
effect = 'easeInExpo';

function tryRedirect(span,url){
	if($(span).length > 0 && url != location.href.substring(location.href.lastIndexOf('/'),location.href.length)){
		window.location.href = url;
	}
}

$(window).load(function(){
	$('.subnav_list:not(#subnav_placeholder,.current)').css({opacity:0,display:'none'});
	$('.topnav_link:not(#topnav_home)').click(function(){
		subnav = '#'+$(this).attr('id').replace('top','sub');
		if($(subnav).css('opacity')<1){
			$('.subnav_list:not(#subnav_placeholder)').animate({opacity:0},interval,effect,function(){
				$('.subnav_list:not(#subnav_placeholder)').css({display:'none'});
				$(subnav).css({display:'block'});
				$(subnav).animate({opacity:1},interval,effect,function(){
					correspondingSpan = $('#'+$(this).attr('id').replace('subnav','hidden'));
					destination = '/'+$(this).attr('id').replace('subnav_','');
					tryRedirect(correspondingSpan,destination);
				});
			});
		}else{
			correspondingSpan = $('#'+$(this).attr('id').replace('topnav','hidden'));
			destination = '/'+$(this).attr('id').replace('topnav_','');
			tryRedirect(correspondingSpan,destination);
		}
	});
	if($.browser.msie===true){
		$('.rollaway').css({
			height:0,
			display:'none'
		});
		$('.name').each(function(){
			$(this).attr('href',$(this).attr('href').replace('//',''));
		});
		$('.vertnav-wrapper').css({
			display:'block',
			height:$('.content-left').height()
		});
		$('.leftvertnav').css({display:'inline'});
		$('.content').css({display:'inline'});
		$('.vertnav-left-wrapper').css({
			height:parseInt($('.hr-left').height())+parseInt($('.hr-left').css('padding-top'))
		});
		boxHeight = parseInt($('.hr-left').height()) + parseInt($('.hr-left').css('padding-bottom')) + parseInt($('.hr-left').css('padding-top'));
		$('.hr-left').css({
			'float':'right',
			'margin-top':-1*boxHeight,
			'margin-right':73
		});
		$('.content_wrapper').css({'background-image':'none'});
		$('.subnav_list').css({width:960});
	}else{
		$('.name').click(function(){
			correspondingDiv = '#'+$(this).attr('id').replace('link','name');
			correspondingStaff = '#'+$(this).attr('id').replace('link','staff');
			correspondingParagraph = correspondingDiv+'>p';
			correspondingHiddenSpan = '#'+$(this).attr('id').replace('link','hidden');
			if($(correspondingDiv).height() != 0){
				$(correspondingHiddenSpan).html($(correspondingParagraph).height());
				$(correspondingDiv).animate({height:0,opacity:0},interval,effect,function(){
					$(correspondingDiv).css({display:'none'});
					$(correspondingStaff).css({'padding-bottom':20});
				});
			}else{
				$(correspondingDiv).css({display:'block'});
				if($(correspondingHiddenSpan).attr('class') != 'hasBeenOpened'){
					$(correspondingHiddenSpan).attr('class','hasBeenOpened');
				}
				$(correspondingDiv).animate({height:parseInt($(correspondingHiddenSpan).html()),opacity:1},interval,effect,function(){
					$('.content-wrapper .content').css({'padding-bottom':40});
					$(correspondingStaff).css({'padding-bottom':20});
				});
			}
		});
		$('.rollaway').each(function(){
			correspondingHiddenSpan = '#'+$(this).attr('id').replace('name','hidden');
			correspondingParagraph = '#'+$(this).attr('id')+' p';
			correspondingPhoto = '#'+$(this).attr('id').replace('name','photo');
			$(correspondingParagraph).css({width:$(this).width()});
			$(correspondingHiddenSpan).html($(correspondingParagraph).height());
		});
		$('.rollaway').css({
			height:0,
			display:'none'
		});
		if($.browser.opera===true){
			$('.rollaway').css({
				height:'100%',
				display:'block',
				opacity:1
			});
		}
	}
	$('.staff_member').css({visibility:'visible'});
});