
function jqStarted() {

}

function jqLoaded() {
	$("a.fglogo").text("");
	
	$("div#gamebox").width($("div#gamebox div.content").width()+197+16+8);

	$("div#gamebox div.sharepanel").width($("div#gamebox div.content").width());
	

	$("div#gamebox div.inner1").css("background-position", ($("div#gamebox").width()-8-197)+"px -23px");
	$("div#gamebox div.inner2").css("background-position", "-8px "+($("div#gamebox").height()-23)+"px");
	$("div#gamebox div.inner3").css("background-position", ($("div#gamebox").width()-8-197)+"px "+($("div#gamebox").height()-23)+"px");

	$("div#gamebox div.drawer, div#gamebox div.drawer div.dinner1").height($("div#gamebox").height());

	
	$("ul.gamelist li").hover(
      function () {
        $(this).css("background-position", "0px -"+$(this).height()+"px");
        if ($(this).is("ul.gamelisthorz li, ul.gamelisttiny li"))
	        $(this).find("div.desc").hide();
	    if ($(this).is("ul.gamelistvert li, ul.gamelisttiny li"))
	        $(this).find("a").hide();
      }, 
      function () {
        $(this).css("background-position", "0px 0px");
        if ($(this).is("ul.gamelisthorz li, ul.gamelisttiny li"))
	        $(this).find("div.desc").show();
	    if ($(this).is("ul.gamelistvert li, ul.gamelisttiny li"))
	        $(this).find("a").show();
      }
      
    );

    $("ul.gamelist li").click(function () { 
      window.location.href = $(this).find("a").attr("href"); 
    });
    
	if (!MSIE() || MSIE() >= 7) {
		$(window).resize(adjustSizes);
		adjustSizes();
	}

	starHandler();
}

function adjustSizes() {
		$("ul.gamelistvert").filter(".varsize").map(function() {
			var wid = $(this).width();
			
/*			if (MSIE())
				wid -= $(this).css("padding-left")+$(this).css("padding-right");*/
			
			var extra = wid%126;
			var els = Math.floor(wid/126);
			
			if (els > 0) {
				$(this).find("li").css("margin-left", 5+Math.floor(extra/els/2));
				$(this).find("li").css("margin-right", 5+Math.floor(extra/els/2));
			}
		});

		$("ul.gamelisthorz").filter(".varsize").map(function() {
			var wid = $(this).width();

/*			if (MSIE())
				wid -= 20;*/

			var extra = wid%295;
			var els = Math.floor(wid/295);
			
			if (els > 0) {
				$(this).find("li").css("margin-left", 5+Math.floor(extra/els/2));
				$(this).find("li").css("margin-right", 5+Math.floor(extra/els/2));
			}
		});
}

function starHandler() {
	$(".stars").mousemove(function(e) {
		if (!$(this).hasClass("votable"))
			return;
						
		var xPerc = (e.pageX-$(this).offset().left)/$(this).width();
		
//		window.status = ($(this).position().left);
		
		var suffix = '0';
		if (xPerc > 0.8)
			suffix = '5';
		else if (xPerc > 0.6)
			suffix = '4';
		else if (xPerc > 0.4)
			suffix = '3';
		else if (xPerc > 0.2)
			suffix = '2';
		else 
			suffix = '1';
			
		$(this).find("span").attr("class", "stars"+suffix);
	});	
	
	$(".stars").click(function () { 
		if (!$(this).hasClass("votable"))
			return;
		
		// send voting info
		
		$(this).removeClass("votable");
	});	
}

function MSIE() {
	var version = false;
	if (navigator.appVersion.indexOf("MSIE") != -1) {
		temp = navigator.appVersion.split("MSIE");
		version = parseFloat(temp[1]);
	}
	
	return version;
}


jqStarted();