


$(function() {
	try {
		pJeux.init();
	} catch (e) {
//		console.log(e);
	}
	
	return false;
}); 



var pJeux = function() {

	function _showHasClass(className) {
				// On cache tout le monde
			$("#Complete_List ul:not(#Complete_List_hidden)").children("li").remove();

			var nbGames = $("#Complete_List_hidden li"+(className ? "."+className : "")).length;
			var nbPerCol = Math.ceil(nbGames/2);
			
			var index = 0;
			$("#Complete_List_hidden li"+(className ? "."+className : "")).each(function() {
				var currentColId = "Complete_List_col_"+(index < nbPerCol ? 1 : 2);
				$(this).clone().appendTo($("#Complete_List #"+currentColId));
				index++;
			});				
			
			$("#Complete_List li"+(className ? "."+className : "")).show();
	}
	
	function _init() {
		
		// On conserve touts les éléments dans un coin
		$("#Complete_List li").each(function() {
			$(this).clone().appendTo($("#Complete_List_hidden"));
		});

		
		 $(".Select_All").click(function() {
			_showHasClass();
			$("#Nom_Tri img").remove();
//			$("#Complete_List").css("height","1000px");
			// initialise gras et couleur des catégories
			$("ul.Liste_Tri > li").css("fontWeight", "normal");
			$("ul.Liste_Tri > li").css("color", "#8080FF");			
		});
		
		$(".sort_editor").click(function() {
			_showHasClass($(this).attr("rel"));
			// initialise gras et couleur des catégories
			$("ul.Liste_Tri > li").css("fontWeight", "normal");
			$("ul.Liste_Tri > li").css("color", "#8080FF");
			// met en gras et rouge la catégorie sélectionnée
			$(this).css("fontWeight", "bold");
			$(this).css("color", "red");
			// Affichage de l'image
			$("#Nom_Tri").html('<img alt="" src="http://www.wordsofmagic.com/images/logos/'+$(this).attr("image")+'">');
//			$("#Complete_List").css("height","800px");
		});
		
		$(".sort_genre").click(function() {
			_showHasClass($(this).attr("rel"));
			$("ul.Liste_Tri > li").css("fontWeight", "normal");
			$("ul.Liste_Tri > li").css("color", "#8080FF");
			$(this).css("fontWeight", "bold");
			$(this).css("color", "red");
			// Supression de l'image
			$("#Nom_Tri img").remove();
		});		


		$(".mainTitle").click(function() {
			$("#title_popup").remove();
		});
		
		$(".mainTitle").mouseover(function() {
			$(this).parent(":first").prepend('<div id="title_popup"></div>');
			
			var element = $("#title_popup", $(this).parent());
		
			element.html($(this).attr("rel"));
			var position = $("img", this).position();
			var posLeft = position.left + $(this).width() - 10;
			var posTop = position.top - 5;
			
			element.css("left", posLeft);
			element.css("top", posTop);

			$(this).parents("li:first").css("zIndex", "20");
			
			element.show();

		});
		
		$(".mainTitle").mouseout(function() {
			$(this).parents("li:first").css("zIndex", "10");
			$("#title_popup", $(this).parent()).remove();
		});
		
//		$(".mainTitle").each(function() {
//console.log($(this));
//		});
	}
	
	return {init:_init};
}();



