// script for the my candystand widget
var firstId;
var trophyJsonString;
var trophyDetail;

function showTrophyInfo(element) {
	$(currentId).className = "unselected_trophy_module";
	
	var e = element;
	if (!e.id) return;

	currentId = e.id;

	$(currentId).className = "selected_trophy_module";
	
	//updateTrophyDetail();

}


function trophyOver(element) {

	var e = element;
	if (!e.id) return;

	currentId = e.id;

	updateTrophyDetail();

}

function updateTrophyDetail() {

	for (var i = 0; i < trophyDetail.length; i++) {
        
		var jo = trophyDetail[i];

        var joid = jo.gId + "-" + jo.glvl;

		if (joid == currentId) {

            // build thumb url

             //"#", "/assets/images/trophies/membership/gold.gif"
            var thumb;
			var trophyStyle;

            if (jo.gId == -1) {
				thumb = "/assets/images/trophies/membership/gold.gif";
				trophyStyle = "trophy_member_copy"
            } else if (jo.gId == -2) {
				thumb = "/assets/images/trophies/facebook/gold.gif";
				trophyStyle = "trophy_member_copy"
            } else if (jo.type == 'tournament') {
                   trophyStyle = "trophy_copy"
                   thumb = '/assets/images/trophies/'+jo.gId+'/tournament.gif';
               } else {
				trophyStyle = "trophy_copy"

                switch (jo.tlvl) {
                    case 30:
                        thumb = '/assets/images/trophies/'+jo.gId+'/gold.gif';
                        break;
                    case 20:
                        thumb = '/assets/images/trophies/'+jo.gId+'/silver.gif';
                        break;
                    case 10:
                        thumb = '/assets/images/trophies/'+jo.gId+'/bronze.gif';
                        break;
                    default:
                        thumb = '/assets/images/trophies/'+jo.gId+'/overlay.gif';
                }
            }

			$("trophyHolder").className = trophyStyle;						
			$("detail_thumb").src = thumb;
			$("game_name").update(jo.name.replace("&39;", "'"));
			$("score").update(jo.score);
			$("dateWon").update(jo.dateWon);

            // build play link
            if (jo.gId < 0) {
                $("play_link").href = "#";
            } else {
                $("play_link").href = '/play.do?id='+jo.gId;
            }

			break;

		}
	}
}

function OpenMyCsCallback() {}
OpenMyCsCallback.prototype.callback = function() {
	// one call does not work for some reason
	myCSTab('favorites_module_buffer','favorites_module');
	myCSTab('favorites_module_buffer','favorites_module');
}

function removeLocalFavorite(favorite) {

    var id = favorite.split("_")[1];
    removeGameFavorite(id, new ChangeFavoriteCallback(new OpenMyCsCallback()));
    $(favorite).remove();

}