$(document).ready(function() 
{
	loadUserDetail();
});

function loadUserDetail()
{
   	var url_http = ('https:' == document.location.protocol ? 'https://' : 'http://');//alex modified
		//url = "http://";
	var url = url_http + location.hostname + '/accounts/ajax/detail';
	$.ajax({
		url: url,
		type: "GET",
		beforeSend: function()
		{ 
			$("#comet_score").html("loading...");
			$("#comet_title").html("loading...");
			$("#comet_tag").html("loading..."); 
		},
		cache: true,
		error: function ( XMLHttpRequest, textStatus, errorThrown )
		{
			//alert("error");
			$("#comet_score").html("--");
			$("#comet_title").html("--");
			$("#comet_tag").html("--"); 
		},
		success: function(json)
		{
			var jsonObj = eval("("+json+")");
			var error_type = jsonObj.result;
			if (error_type == 'OK') 
			{
				var current_score = jsonObj.data.level_current_score;
				var pre_score     = jsonObj.data.level_pre_score;
				var minus 		  = current_score - pre_score;
				var current_minus = jsonObj.data.score - pre_score;
				var s 			  = "<br />["+pre_score+"/"+ current_score+"("+jsonObj.data.level+")]";
				var level_num 	  = jsonObj.data.level_num;
				var level_img 	  = "<img src='../../../images/levels/"+level_num+".gif' />";
				$("#level_img").html(level_img);
				$("#comet_score").html(jsonObj.data.score);
				$("#comet_title").html(jsonObj.data.level);
				$("#comet_tag").html(jsonObj.data.rank);
				$("#user_score").html(jsonObj.data.score);
				$("#speed_img").width((100*current_minus/minus)+'%');
				$("#current_score").html(s);
			}
			else
			{
				$("#comet_score").html("--");
				$("#comet_title").html("--");
				$("#comet_tag").html("--");
				$("#speed_img").width(0);
			}
		}
	});
}

