// JavaScript Document
var global_h3stats = Array();
function toggle_halo3stats(image)
{
	var display_state = $(image).parent().next().css("display");
	switch (display_state)
	{
		case 'block':
			$(image).parent().next().hide("blind", '', "slow", function(){$(image).attr("src", phpbb_root_path + "/images/bungiestats_show.gif");});
			
		break;
		case 'none':
			var gamertag = $(image).attr("gamertag");
			if (typeof global_h3stats[gamertag] == "undefined")
			{
				var loading_image = '<center><br/><img src="' + t_imageset_path + '/ajax_loaderb.gif" border="0" title="Cargando..." alt="Cargando..." /><br/><br />Cargando...</center>';
				$(image).parent().next().html(loading_image).show("blind", "slow");
				haloapi(gamertag, '', 'json', function(response){
					$(image).parent().next().hide("blind", "slow", function(){
						var html_response = '<table class="tablebg" width="100%"><tr><td align="center" class="row1"><img src="' + response.emblem+ '" />&nbsp;<img src="' + response.global_rank.image + '" title="' + response.global_rank.name + '" alt="' + response.global_rank.name + '" /></td></tr><tr><td class="row1">' + response.playlist_ratings + '</td></tr><tr><td align="center" class="row1"><a href="#" onclick="javascript:detailed_halo3stats(\'' + gamertag + '\'); return false;">Estadisticas completas</a></td></tr></table>'
						$(image).parent().next().html(html_response).show("blind", "slow", function(){$(image).attr("src", phpbb_root_path + "/images/bungiestats_hide.gif");});
						global_h3stats[gamertag] = html_response;
					});
				});
			}
			else
			{
				$(image).parent().next().html(global_h3stats[gamertag]);
				$(image).parent().next().show("blind","slow", function(){$(image).attr("src", phpbb_root_path + "/images/bungiestats_hide.gif");});
			}
			
		break;
	}
}

function detailed_halo3stats(gamertag)
{
	if (!gamertag)
	{
		return;
	}
	window.open("http://www.bungie.net/Stats/Halo3/Default.aspx?player=" + gamertag);
}
