$(document).ready(function(){
	
	$("#container").corner("bottom round 10px").parent().css('padding', '2px').corner("bottom round 10px");
	$("#container").corner("top round 1px").parent().corner("top cc:#fff round 10px");
	$(".info").hide();
	$(".more").show();

	$(".more").click(function () { 
		$(this).siblings(".info").slideToggle(); 
		if ($(this).text() == "More Info") {
			$(this).text("Less Info");
			$(this).css("background-image", "url('images/up.gif')");
		} else {
			$(this).text("More Info");
			$(this).css("background-image", "url('images/down.gif')");
		}
	});
	$(".more").hover(function () {
		 $(this).addClass("bold");
		}, function () {
		 $(this).removeClass("bold");
	});
	$(".meet").hover(function() {
		$(this).css("background", "#F0F0F0");
	}, function() {
		$(this).css("background", "");
	});
	

	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.8, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
	
	$("#closeBio").click(function() {
		$("#bio").hide();
	});

	$(".date").hover(function(e) {
		if ($(this).attr('name')) {
			var el = $(this);
			var offset = 0;
			if ($(this).children().size() > 0) {
				offset = $(this).children(".tooltip").innerWidth();
				$(this).children().remove();
			}
			var tooltip = $("<div></div>").text($(el).attr('name')).addClass('tooltip');
			el.append($(tooltip).css({'left' : ($(el).innerWidth() + 5) + 'px'}));
			var tempWidth = $(tooltip).innerWidth();
			$(tooltip).css('width', offset + 'px').show().animate({width: tempWidth + 'px'}, 750);
			tooltip = null; el = null;
		}
	}, function() {
		if ($(this).attr('name')) {
			$(this).children().animate({width: 0, opacity: 0}, 750, function() {$(this).remove();});
		}
	});
		
	$("#Female tr, #Male tr").hover(function() {
 		 $(this).addClass("hover");
		}, function() {
		 $(this).removeClass("hover");
	});
	$(".swimmer").click(function(e) {
		var x = e.pageX - this.offsetLeft + 10;
		var y = e.pageY - this.offsetTop - 10;
		$("#loading").css({"left" : x + "px", "top" : y + "px"});
		$("#loading").show();
		getSwimmer($(this).attr("id"));
		$("#loading").hide();
		return false;
	});


});

function loadMeets() {
	$().mousemove(function(e) { 
		if ($("#tooltip").css("display") != "none") { return; }
			//$("#tooltip").css("top" , (e.pageY- 20) + "px");
	});
}

function getRoster() {

	$().mousemove(function(e) { 
		if ($("#loading").css("display") != "none") 
			$("#loading").css({"left" : (e.pageX + 10) + "px", "top" : (e.pageY - 10) + "px"});
	});
}
	
function getSwimmer(swimmerID) {
	$.ajax({
		type: "GET",
		url: "files/athletes.xml",
		dataType: 'xml',
		success: function(xml) {
			var years = ["Senior", "Senior", "Junior", "Sophomore", "Freshmen"];
			var items = ["major", "home", "highSchool", "height", "preCU", "freshmen", "sophomore", "junior", "senior", "personal", "interests"]
			var swimmer = $(xml).find("#" + swimmerID);
			var bio = $(swimmer).find("bio"); 
			var field;
			$("#swimmerName").text($(swimmer).find("firstName").text() + " " + $(swimmer).find("lastName").text());
			$("#year .item").text(years[$(swimmer).find("year").text() - 2009]); 
			$("#events .item").text($(swimmer).find("events").text());
				$(items).each(function() {
				field = this; 
				if ($(bio).find(""+field).text()) {
					$("#" + field + " .item").text($(bio).find(""+field).text());
					$("#" + field).show();
				}
				else 
					$("#" + field).hide();
			});
				$("#bio").show();
		}
	});
}
