﻿function creation_lien(m,r,c1,c2,e)
{
	$("#adresse .embleme").val("http://www.draeli.com/daoc/programme-creation-embleme_" + m + "-" + r + "-" + c1 + "-" + c2 + "-" + e + ".html");
}

$(function()
{
	function init_valeur()
	{
		motif = $("#choix_m").val();
		noir = $("#choix_c1").val();
		blanc = $("#choix_c2").val();
		royaume = $("#choix_r").val();
		embleme = $("#choix_e").val();
	}

	// les valeurs ne sont plus initialises ici mais par les champs hiddens
	var motif;
	var noir;
	var blanc;
	var royaume;
	var embleme;
	var embleme_max = 65;
	var dir_script = 'scripts/creation_embleme/';

	// initialisation
	init_valeur();
	mise_a_jour_resultat();
	$("#choix_roy div").filter(".roy_" + royaume).addClass("roy_" + royaume + "_col");
	$(".no_js").addClass("bloque_invisible");

	function mise_a_jour_resultat()
	{
		// partie nettoyage
		$("#resultat").removeClass();
		$("#emb_precedent").removeClass();
		$("#emb_suivant").removeClass();
		$("#resultat").html("");
		$("#embleme").html("");

		// pour prevenir un eventuel bug du au bourrinage de clique
		if(embleme < 1)
			embleme = 1;
		else if(embleme > embleme_max)
			embleme = embleme_max;

		// partie mise a jour/ajout
		$("#resultat").addClass(blanc);
		$("#resultat").html("<img src=\"" + dir_script + "fonds/" + motif + "-" + noir + ".png\" alt=\"R&eacute;sultat\" title=\"R&eacute;sultat\" style=\"position:absolute;z-index:1;width:80px;height:100px;\" /><img src=\"" + dir_script + "emblemes/" + royaume + "-" + embleme + ".gif\" style=\"position:absolute;z-index:2;margin-left:8px;\" />");
		$("#embleme").html("<img src=\"" + dir_script +"emblemes/" + royaume + "-" + embleme + ".gif\" />");

		if(embleme == 1)
			$("#emb_precedent").addClass("bloque_invisible");
		else if(embleme == embleme_max)
			$("#emb_suivant").addClass("bloque_invisible");

		creation_lien(motif, royaume, noir, blanc, embleme);
	}

	$("#choix_motif img").click
	(
		function()
		{
			var a = $(this).attr("class");
			motif = a.substring(1, a.length);
			mise_a_jour_resultat();
		}
	);

	$("#partie_noir div").click
	(
		function()
		{
			var a = $(this).attr("class");
			noir = a.substring(1, a.length);
			mise_a_jour_resultat();
		}
	);

	$("#partie_blanche div").click
	(
		function()
		{
			blanc = $(this).attr("class");
			mise_a_jour_resultat();
		}
	);

	$("#choix_roy div").click
	(
		function()
		{
			$("#choix_roy div").removeClass("roy_" + royaume + "_col");
			var a = $(this).attr("class");
			royaume = a.substring(4, a.length);
			$(this).addClass("roy_" + royaume + "_col");
			mise_a_jour_resultat();
		}
	);

	$("#emb_precedent").click
	(
		function()
		{
			embleme--;
			mise_a_jour_resultat();
		}
	);

	$("#emb_suivant").click
	(
		function()
		{
			embleme++;
			mise_a_jour_resultat();
		}
	);
});
