// impostazioni delle animazioni delle domande// start è il punto di partenza// answerX è il punto di arrivo dell'animazionevar questionCss = {	"container_start"	: {marginTop : "200px",	marginLeft: "10px"},	"container_after"	: {marginTop : "0px",	marginLeft: "10px"},	"start_1"			: {left: "0px",	display: "block"},	"start_2"			: {left: "245px",	display: "block"}};// nome della variabile domanda in//var startQuestion = "q1"; // già impostatovar backupId	= "";var backupCode	= "";var benefitList = new Array();$(window).unload(function() {	//alert('il documento è stato chiuso.');});$(document).ready(function() {	function isset(varName) {		return (eval("typeof " + varName)!="undefined");	};	function build(step) {		jQuery.each(step, function(a, domanda) { // cicla una volta sola.			//gestione domanda			if(domanda["id"]==startQuestion && statsState) {				statistic_startEvent();			}			$(".cr-answer").unbind("click").hide();			$("#cr-fakebox").show();			//imposto lo stile della domanda			var styling = "cr-text";			if(domanda["css"]!="") { // applico inline style				styling = domanda["css"];			}			$("#cr-question").html("<div class=\"" + styling + " cr-question_" + domanda["id"] + "\">" + domanda["testo"] + "</div><div id=\"cr-puff\">&nbsp;</div>").show();			// svuota e nasconde la domanda finale			$(".cr-end").empty().hide();			// ripristino il contenuto spostato se esiste.			if(backupId!="") {				$(backupId).html(backupCode);				backupId = backupCode = "";			}			// imposto gli stili iniziali del contenitore			$("#cr-answer_container").css(questionCss["container_start"]);			// ciclo tra le risposte inserendo l'html			jQuery.each(domanda["risposte"], function(b, risposte) {				var answerId = "#cr-answer" + b;				// attacco il dato della risposta				$(answerId).data("risp", risposte);				// imposto lo stile di partenza di ogni domanda				$(answerId).css(questionCss["start" + b]);				// aggiungo una classe css per la risposta.				var styling = "cr-text";				if(risposte["cssR"]!="") { // applico inline style					styling = risposte["cssR"];				}				// carico l'html				$(answerId).html("<div class=\"" + styling + " cr-answer_" + risposte["id"] + "\">" + risposte["testo"] + "</div>");			});			// faccio partire l'animazione sull' oggetto prescelto e alla fine rimuovo l'identificatore			$("#cr-answer_container").animate(questionCss["container_after"], 1000, function () {				// ciclo tra i figli del contenitore, ovvero le due domande				if(domanda["id"]==startQuestion) {					$(".cr-htitle").hide();					$("#cr-explaination").fadeIn('slow');				}				$(this).children(".cr-answer").each(function() {					// associo l'evento click a ciascuna domanda					$(this).one("click", function() {						var risposta = $(this).data("risp");						$(this).removeData("risp");						// nascondo spiegazione e mostro titolo						$("#cr-explaination").hide();						$(".cr-htitle").show();						//if(typeof risposta['benefit']!="undefined") alert("BENEFIT NODO " + risposta['benefit'].toString());						// rimuovo il click dai pulsanti indietro e inizia e li faccio scomparire						$(".cr-button img").unbind("click").fadeOut('slow');						if($(risposta["dest"]).length>0) { // siamo arrivati alla fine, la risposta contiene l'id di un elemento							var actual = risposta["dest"];						}						else if(isset(risposta["dest"])) { // è una domanda da analizzare, esiste la variabile.							eval("var actual = " + risposta["dest"]);						}						else { // manca la domanda							alert(languageLabel["question_default"] + " (" + risposta["dest"] + ")");							return;						}						var clicked = $(this).attr("id");						// creo l'effetto esplosione per la domanda non cliccata.						jQuery.each(domanda["risposte"], function(b, risposte) {							if(clicked != "cr-answer" + b) {								var options = { };								$("#cr-answer" + b).effect("explode", options, 500);							}						});						var options = { to: "#cr-fakebox", className: "ui-effects-transfer" };						// effetto transfer del box a lato e alla fine associo il link						$(this).effect("transfer", options, 500, function() {							// aggiungo una classe css per la domanda da mettere nell'history.							var styling = "cr-dtext";							if(risposta["cssD"]!="") { // applico inline style								styling = risposte["cssD"];							}							var domandaTesto = (typeof domanda["testo_alt"]!="undefined") ? domanda["testo_alt"] : domanda["testo"];							var domandaHTML = "<div class=\"" + styling + " cr-hquestion_" + domanda["id"] + "\">" + domandaTesto + "</div>";							// aggiungo una classe css per la risposta da mettere nell'history.							styling = "cr-rtext";							if(risposta["cssS"]!="") { // applico inline style								styling = risposta["cssS"];							}							var rispostaTesto = (typeof risposta["testo_alt"]!="undefined") ? risposta["testo_alt"] : risposta["testo"];							var rispostaHTML = "<div class=\"" + styling + " cr-hanswer_" + risposta["id"] + "\">" + rispostaTesto + "</div>";							// attacco nell'history la domanda scelta							$("#cr-fakebox").before("<div id=\"cr-" + risposta["id"] + "\" class=\"cr-hanswer\"><div class=\"cr-close\" title=\""+ languageLabel["back_link_attr_title"]+ "\"></div><div class=\"cr-dr\" title=\""+ languageLabel["history_summary_title"]+"\">" + domandaHTML + rispostaHTML + "</div><br clear=\"all\">");							// attacco l'evento click all'oggetto.							$("#cr-" + risposta["id"] + " div.cr-close").data("quest", domanda).one("click", function() {								deleteHistory("#cr-history #"+$(this).parent("div.cr-hanswer").attr("id"));							});							// siamo alla fine, o esito finale o domanda							if(typeof actual=="string") {								$("#cr-question").empty().hide();								// recupero elenco domande da passare alle chiamate delle statistiche								var wizardFullList = new Array();								$("#cr-history div.cr-hanswer").each(function() {									wizardFullList[wizardFullList.length] = $(this).attr('id').replace('cr-', '');								});								//alert();								if(statsState) {									statistic_endEvent(wizardFullList.join(","), actual);								}								backupId = actual;								backupCode = $(actual).html();								benefitList = new Array();								/*recupero i benefit nel codice*/								$("#cr-history div.cr-hanswer div.cr-close").each(function() {									var domanda = $(this).data("quest");									var risposta = $(this).parent("div").attr("id");									// raccolgo tutti i key benefit accumulati dalle domande									jQuery.each(domanda["risposte"], function(a, rispostaObj) {										if(risposta == ("cr-" + rispostaObj["id"])) {											if(typeof(rispostaObj["benefit"]!="undefined")) {												jQuery.merge(benefitList, jQuery.makeArray(rispostaObj["benefit"]));											}										}									});								});								var benefitFinal = new Array();								//prepara un array di 300 dimensione								var totSize=300;								for(c=0;c<totSize;c++) {									benefitFinal[c] = 0;								}								// ciclo tra i benefit raccolti								var count = 0;								jQuery.each(benefitList, function(i,v) {									// è tra i benefit validi del risultato,  non è già presente (evita i doppioni)									if(jQuery.inArray(v, benefitAllowed[actual])!=-1 && jQuery.inArray(v, benefitFinal)==-1) {										var count = 0;										var idx = benefit[v][1] * 10;										if(benefitFinal[idx]==0 || typeof benefitFinal[idx]=="undefined") {											benefitFinal[idx] = v;										} else {											while(benefitFinal[idx]!=0 && typeof benefitFinal[idx]!="undefined") {												idx = benefit[v][1] * 10 + count++;											}											benefitFinal[idx] = v;										}										//var c = benefit[v][1];									}								});								var elencoBenefit = "<ul>";								var benefitOk = 0;								jQuery.each(benefitFinal, function(i, v) {									if(benefitOk<benefitLimit[actual] && v>0) {										benefitOk ++;										elencoBenefit += "<li class=\"pageSpunta\">" + benefit[v][0] + "</li>\n";									}								});								elencoBenefit += "</ul>";								//alert("BENEFIT LIST " +benefitList.toString());								//alert("BENEFIT FINAL " +benefitFinal.toString());								// sostituisco i benefit.								var replacedCode = backupCode.replace(string2Replace, elencoBenefit);								$(actual).empty();								$("#cr-fakebox").hide();								$(".cr-start, .cr-back").clone(true).css({"opacity" : "1.0"}).appendTo("#cr-history");								$("#cr-history .cr-start").one("click", function() {									deleteHistory("#cr-history .cr-hanswer:first");									$(this).fadeOut('slow', function() {										$(this).remove();									});								});								$("#cr-history .cr-back").one("click", function() {									deleteHistory("#cr-history .cr-hanswer:last");									$(this).fadeOut('slow', function() {										$(this).remove();									});								});								$(".cr-end").html(replacedCode).show();								$(".cr-answer").unbind("click").hide();								replacedCode = "";							} else if(typeof actual=="object") {								// richiamo la domanda cliccata.								setTimeout(function(){build(actual)}, 250);							}						});					});				});				// mostro i bottoni se non siamo alla domanda iniziale.				if(domanda["id"]!=startQuestion) {					$(".cr-button img").fadeIn('fast');					// assegno il click al pulsante indietro					$(".cr-button img.cr-back").one('click', function() {						deleteHistory("#cr-history .cr-hanswer:last");					});					// assegno il click al pulsante inizia					$(".cr-button img.cr-start").one('click', function() {						deleteHistory("#cr-history .cr-hanswer:first");					});				}			});		});	};	function sortObject(o) {		var sorted = {},		key, a = [];		for (key in o) {			if (o.hasOwnProperty(key)) {					a.push(key);			}		}		a.sort();		for (key = 0; key < a.length; key++) {			sorted[a[key]] = o[a[key]];		}		return sorted;	};	function deleteHistory(selector) {		var $last = $(selector);		var deleteThis = false;		var deleteFrom = $last.attr("id");		var domanda = $last.children(".cr-close").data("quest");		eval("var actual = " + domanda["id"]);		// elimino quelli vecchi		$("#cr-history div.cr-hanswer").each(function (i) {			if($(this).attr("id") == deleteFrom) deleteThis = true;			if(deleteThis) {				$(this).fadeOut(1500, function () {					$(this).remove();				});			}		});		// se è presente il pulsante inizio sotto la history		if($("#cr-history .cr-start").length>0) {			$("#cr-history .cr-start").fadeOut('slow', function() {				$(this).remove();			});		}		// se è presente il pulsante indietro sotto la history		if($("#cr-history .cr-back").length>0) {			$("#cr-history .cr-back").fadeOut('slow', function() {				$(this).remove();			});		}		$(".cr-button img").fadeOut('fast');		// ritorna al parent		setTimeout(function(){build(actual)}, 250);	};	$("#cr-loader").remove();	$("#cr-wrapper").show();	var step = eval(startQuestion);	build(step);	// chiamata iniziale alle statistiche;	function statistic_startEvent() {		if(typeof(s_gi)=="function") {			var s=s_gi('unicreditallprod');			s.linkTrackVars="eVar12,events";			s.linkTrackEvents="event5";			s.events="event5";			s.eVar12 = statsCodes['bank'][0];			s.tl(true,'o','Trova il tuo conto:inizio');		}	}	function statistic_endEvent(answerList, result) {		if(typeof(s_gi)=="function") {			var s=s_gi('unicreditallprod');			s.linkTrackVars="eVar15,eVar30,eVar32,events";			s.linkTrackEvents="event6,prodView,event11";			s.events="event6,prodView,event11";			s.products=statsCodes[result][0]; // codice del prodotto uscito (genius card etc)			s.eVar15=statsCodes[result][1];			s.eVar30=answerList; //elenco domande			s.eVar32=statsCodes[result][0].replace(";", "") + statsCodes['bank'][1];			s.tl(true,'o','Trova il tuo conto:fine');		}	}});
