$(document).ready(function () {
    /* submenus */
    $("#topnav_games").hover(
        function () { $(this).children(".topnav-subcategories").show(); },
        function () { $(this).children(".topnav-subcategories").hide(); }
    );
    $("#topnav_apps").hover(
        function () { $(this).children(".topnav-subcategories").show(); },
        function () { $(this).children(".topnav-subcategories").hide(); }
    );
    $("#search_query").focus(
    	function () {
			if ($(this).attr("value") == "Search:" && $(this).css("color") == "rgb(127, 127, 127)") {
				$(this).css("color", "rgb(0, 0, 0)");
				$(this).attr("value", "");
			}
    	}
    );
    $("#search_query").blur(
    	function () {
    		if ($(this).attr("value") == "") {
				$(this).css("color", "rgb(127, 127, 127)");
				$(this).attr("value", "Search:");
			}
    	}
    );
});
function show_featured_game(id, name) {
	jQuery.each($("#featured_radio").children("div"), function() {
		if (this.id != "show_featured_game_"+id) {
			$(this).css("background", "url('../design/img/featured_game_button.png') no-repeat");
		} else {
			$(this).css("background", "url('../design/img/featured_game_button_active.png') no-repeat");
		}
	});
	jQuery.each($("#featured_games").children("div"), function() {
		if (this.id != "featured_game_"+id) {
			$("#" + this.id).hide();
		} else {
			$("#" + this.id).show();
		}
	});
	$("#featured_game_name").text(name);
}
function fbFetch(fb_user_id, successfunction) {
	var url = "http://graph.facebook.com/" + fb_user_id;
	$.getJSON(url, function(data) {
		var items = [];
		$.each(data, function(key, val) {
			items.push('<li id="' + key + '">'+ key + ": " + val + '</li>');
		});
		successfunction(data);
	});
};
function fbFetchApp(app_id, successfunction) {
	var url = "http://graph.facebook.com/" + fb_user_id;
	$.getJSON(url, function(data) {
		var items = [];
		$.each(data, function(key, val) {
			items.push('<li id="' + key + '">'+ key + ": " + val + '</li>');
		});
		successfunction(data);
	});
};
function languageClick(lang_id) {
	var url = window.location.toString();
	if (url.indexOf("?") != -1) {
		if (url.indexOf("language_id") != -1) {
			if (url.charAt(url.indexOf("language_id") - 1) == '?') {
				window.location = url.substr(0, url.indexOf("language_id") - 1) + "?language_id=" + lang_id;
			} else {
				window.location = url.substr(0, url.indexOf("language_id") - 1) + "&language_id=" + lang_id;
			}
		} else {
			window.location = url + "&language_id=" + lang_id;
		}
	} else {
		window.location = url + "?language_id=" + lang_id;
	}
};
