$(document).ready(function(){
   $('.map a').lightBox();
   $('a.pitch').lightBox();
   $('#venue a').lightBox();
   
   //My team login
   $("a#myteamlogin").click(function(e){
		e.preventDefault();
		div = $("div#myteambox");
		if(div.is(":visible")){
			div.slideUp('slow');
		} else {
			div.slideDown('slow');
		}
	});
   
   $("a.logout").live("click", function(e){
		e.preventDefault();
		$("<img style='float: right; margin-top: 2px' src='/ref/images/ajax-loader-small.gif' id='loader'>").insertAfter(this);
		$.get('/logout_global.php', function(data){
			$("#myteambox").html(data);
		});
	});
	
	$("a.myteamanim").click(function(e){
		e.preventDefault();
		$("#myteambox").slideDown('slow');
	});
   
   $("form#login").live("submit", function(e){
		e.preventDefault();
		$("<img id='loader' src='/ref/images/ajax-loader-small.gif' style='margin-left: 10px'>").insertAfter("input#submit");
		if($("p.fail").length != 0){
			$("p.fail").remove();
		}
		target = $(this).attr("action");
		data = $(this).serialize();
		$.ajax({
			type: 'POST',
			url: target,
			data: data,
			success: function(data){
				if(data.indexOf("<p class='loggedin'>") >= 0){
					$("form#login").fadeOut('slow', function(){
						$("#myteambox").html(data);
					});
				} else {
					$(data).insertAfter("form#login");
					$("img#loader").remove();
				}
			},
			failure: function(){
				$("<p class='fail'>Hmmm... Something went wrong. Please try again.</p>").insertAfter("form#login");
				$("img#loader").remove();
			},
			dataType: 'html'
		});
	});
});
