/**
 * @author jordand
 */


if(typeof NICK == "undefined" || !NICK) var NICK = {};
NICK.namespace("topFive");

$(document).ready(function() {
	if ($("#games-top5").length != 0) {
		NICK.topFive.getTopFive();
	}
});

NICK.topFive.getTopFive = function(){
	var nick_url = NICK.utils.getNickDomain();
	var dataURL = "http://"+ nick_url + "/sbcom/data/json/top_5_games.jhtml";
	NICK.utils.doLog("Get Top 5");
	
	NICK.request.doRequest({
		dataType:"jsonp",
		url: dataURL,
		data: {poll:NICK.topFive.poll},
		onSuccess: function(response) {
			NICK.topFive.displayTopFive(response.data);
		},
		onFail: function(errors) {
			for(var error in errors) {
				NICK.utils.doLog("JSON Response: Error: "+error+" - "+errors[error]);
			}
		}				
	});
}
NICK.topFive.displayTopFive = function(data){
	var output = "";
	for (var loopID in data) {
		var game = data[loopID];
		var gameNum = parseInt(loopID) + 1;
		output += '<li class="clearfix"><div><span class="number"><sup>#</sup>'+gameNum+'</span><a href="'+game.url+'"><img src="'+game.image+'?height=39&width=79&format=jpeg" height="39" width="79" border="0" alt="'+game.name+'"/></a><h3><a href="'+game.url+'">'+game.name+'</a></h3></div></li>';
	}
	$("#games-top5").html(output).css({
		height: "auto",
		position: "static"
	});
}
