

$(function() {

/* index page stuff */


$('.matchLinks').livequery(function(){ 

	$('.matchLinks').find('a').click(function(){

			var obj=$(this);
			$(this).after('<div class="wait"><img src="http://www.11v11.com/api/images/wait.gif"></div>');
			$('.popupEG').remove();

			var id=obj.attr('id');

			$.ajax({
			   type: 'POST',
			   url: $(this).attr('href'),
			   success: function(response){

					var s1=response.split('<body>');	 // just get the body part. Ignore the header.
					var s2=s1[1].split('</body>');

					obj.after('<div class="popupEG">' + s2[0] + '</div>');


					if ($('.popupEG').css('display')=='none'){
											
						$('.wait').remove();
						$('.popupEG').slideDown();
					}
			   }
			})

		return false;	
	});

});

	$('.teamLinks').find('.team').click(function(){

			var obj=$(this);
			$(this).after('<div class="wait"><img src="http://www.11v11.com/api/images/wait.gif"></div>');
			$('.popupList').remove();

			var teamName=$(this).html();
			
			$.ajax({
			   type: 'POST',
			   url: $(this).attr('href'),
			   success: function(response){

					var s1=response.split('<ta' + 'ble');
					var s2=s1[1].split('</ta' + 'ble>');
					obj.after('<div class="popupList"><ta' + 'ble' + s2[0] + '</ta' + 'ble></div>');
					

					if ($('.popupList').css('display')=='none'){
						
						$('.popupList').find('h2').html('Matches :: ' + teamName);
						
						$('.wait').remove();
						$('.popupList').slideDown();
					}

			   }
			})

		return false;	
	});



	$('.matchesForTeamLink').click(function(){

		var target=$('#target');

		target.html('<div class="wait"><img src="http://www.11v11.com/api/images/wait.gif"></div>');


			$.ajax({
			   type: 'POST',
			   url: $(this).attr('href'),
			   success: function(response){

					var s1=response.split('<ta' + 'ble');
					var s2=s1[1].split('</ta' + 'ble>');
					
					target.html('<ta' + 'ble' + s2[0] + '</ta' + 'ble>');
					return false;
			   }
			})

		return false;
	})

});