//WAIT FOR THE PAGE TO BE READY
$(document).ready(function(){

	if($('body').attr('id') == 'welcome'){
		$('h1#logo a').removeAttr('href').removeAttr('title').removeAttr('class');
	}
	
	$('.tooltip').hover(function(){
		$('#tooltip').stop([]).remove();
		tipText = $(this).attr('title');
		$(this).attr('title', '');
		$('body').append('<div id="tooltip"><span class="text">'+tipText+'</span><span class="arrow"></span></div>');
		$('#tooltip').show().css({opacity:0}).stop([]).animate({opacity:1}, 200);
		$().mousemove(function(e){
			$('#tooltip').css({left:e.pageX - 64, top:e.pageY + 38});
		});
	},function(){
		$(this).attr('title', tipText);
		$('#tooltip').remove();
	});

	firstTime = true;
	noClick = false;
	currentStudent = 'none';

	$('#profile_links li a').click(function(){
		theStudent = $(this).attr('href');
		if(theStudent == currentStudent){
			$('#profiles_wrapper div.current').stop([])
				.animate({top:5},50)
				.animate({top:0},50)
				.animate({top:5},50)
				.animate({top:0},50)
				.animate({top:5},50)
				.animate({top:0},50);
		}
		if(noClick==false && theStudent != currentStudent){
			noClick = true;
			currentStudent = theStudent;
			$(this).addClass('active');
			if(firstTime){
				$('#profiles_wrapper div'+theStudent).show().css({left:200, top:0}).stop([]).animate({left:0}, 800, 'easeInOutExpo', function(){
					noClick = false;
				}).addClass('current');
				firstTime = false;
			}else{
				$('#profiles_wrapper div.current').removeClass('current').stop([]).animate({left:-200}, 800, 'easeInOutExpo', function(){
					$(this).hide();
					noClick = false;
				});
				$('#profiles_wrapper div'+theStudent).show().css({left:200, top:0}).stop([]).animate({left:0, top:0}, 800, 'easeInOutExpo').addClass('current');
			}
		}
		return false;
	});
	
	$('#profiles_wrapper a.read_more').click(function(){
		theContent = $(this).next('div.more').html();
		$('body').append('<div id="popup"><div>'+theContent+'</div><a href="#" class="close">Close</a></div><div id="popup_overlay"></div>');
		$('#popup_overlay').css({opacity:0.8});
	});
	
	$('div#popup_overlay, a.close').live('click', function(){
		$('div#popup_overlay').remove();
		$('div#popup').remove();
	});
	
	$('dl.question').each(function(){
		theHeight = $(this).children('dd').outerHeight();
		$(this).attr('id', theHeight);
		$(this).children('dd').css({height:0});
	});
	
	$('dl.question dt a').click(function(){
		newHeight = $(this).parent('dt').parent('dl').attr('id');
		if($(this).attr('class')=='open'){
			$(this).parent('dt').siblings('dd').stop([]).animate({height:0}, 400, 'easeInOutExpo');
			$(this).removeClass('open');
		}else{
			$(this).parent('dt').siblings('dd').stop([]).animate({height:newHeight}, 400, 'easeInOutExpo');
			$(this).addClass('open');
			$(this).parent('dt').parent('dl').siblings('dl').children('dd').stop([]).animate({height:0}, 400, 'easeInOutExpo');
			$(this).parent('dt').parent('dl').siblings('dl').children('dt').children('a').removeClass('open');
		}
		return false;
	});


// End jQuery goodness
});


// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
});

