web/static/res/js/incchoice.js
changeset 43 21a791340354
parent 42 01415303372e
child 45 f7bfdc49982b
equal deleted inserted replaced
42:01415303372e 43:21a791340354
     1 var effectSpeed = 8;
     1 var effectSpeed = 8;
     2 
     2 
     3 function IncChoice()
     3 function IncChoice()
     4 {
     4 {
     5 	this.currentWorldIndex = -1;
     5 	this.currentWorldIndex = 0;
     6 	this.lastWorldIndex = -1;
     6 	this.canSelectWord = true;
     7 
     7 
     8 	this.setMosaicEffect = function(images1, images2, nextUrl)
     8 	this.setMosaicEffect = function(images1, images2)
     9 	{
     9 	{
    10 		// Choose 2 image for the effect
    10 		// Choose 2 image for the effect
    11 		var image1 = images1[incMosaic.randomInt(0, images1.length)];
    11 		var image1 = images1[incMosaic.randomInt(0, images1.length)];
    12 		var image2 = images2[incMosaic.randomInt(0, images2.length)];
    12 		var image2 = images2[incMosaic.randomInt(0, images2.length)];
    13         incMosaic.addImageUrl("static/res/img/" + image1);
    13         incMosaic.addImageUrl("static/res/img/" + image1);
    14         incMosaic.addImageUrl("static/res/img/" + image2);
    14         incMosaic.addImageUrl("static/res/img/" + image2);
    15 
    15 
    16         // Start mosaic effect
    16         // Start mosaic effect
    17     	incMosaic.start("mosaic", effectSpeed, 9, 5, false, true, function() { location.href = nextUrl;});        
    17     	incMosaic.start("mosaic", effectSpeed, 9, 5, false, true, function() {incChoice.effectIsDone();});        
    18 	};
    18 	};
    19 
    19 
    20 	this.selectWord = function(word)
    20 	this.setWords = function(choiceIndex)
    21 	{
    21 	{
    22 		if (this.currentWorldIndex == this.lastWorldIndex) {
    22 		if (choiceIndex == 0) {
       
    23 			$("#mot1").html("famille");
       
    24 			$("#mot2").html("amour");
       
    25 			$("#mot3").html("travail");
       
    26 			$("#mot4").html("international");
       
    27 			$("#mot5").html("dieu");
       
    28 			$("#mot6").html("president");
       
    29 
       
    30 		} else if (choiceIndex == 1) {
       
    31 			$("#mot1").html("actif");
       
    32 			$("#mot2").html("passif");
       
    33 			$("#mot3").html("corps");
       
    34 			$("#mot4").html("charité");
       
    35 			$("#mot5").html("patrie");
       
    36 			$("#mot6").html("politique");
       
    37 
       
    38 		} else {
       
    39 			$("#mot1").html("spleen");
       
    40 			$("#mot2").html("ideal");
       
    41 			$("#mot3").html("origines");
       
    42 			$("#mot4").html("peur");
       
    43 			$("#mot5").html("desir");
       
    44 			$("#mot6").html("bonheur");
       
    45 		}
       
    46 	};
       
    47 
       
    48 	this.selectWord = function(wordIndex)
       
    49 	{
       
    50 		if (!this.canSelectWord) {
    23 			// Don't set the word 2 times
    51 			// Don't set the word 2 times
    24 			return;
    52 			return;
    25 		}
    53 		}
       
    54 
       
    55 		this.canSelectWord = false;
    26 
    56 
    27 		// Start the mosaic effect
    57 		// Start the mosaic effect
    28 		incMosaic.goEffect();
    58 		incMosaic.goEffect();
    29 
    59 
    30 		// Fade the text
    60 		// Fade the text
    31 		$('.big_txt').animate({opacity: 0}, 20000 * 1 / effectSpeed);
    61 		$('.big_txt').animate({opacity: 0}, 20000 * 1 / effectSpeed);
    32 
    62 
    33 		// Save the word
    63 		// Save the word
    34 		this.setCookie("niv1_world" + this.currentWorldIndex, word);
    64 		this.setCookie("niv1_world" + this.currentWorldIndex, $("#mot" + wordIndex).html());
    35 		this.lastWorldIndex = this.currentWorldIndex;
       
    36 		//++this.currentWorldIndex;
       
    37 	};
    65 	};
       
    66 
       
    67 	this.effectIsDone = function()
       
    68 	{
       
    69 		this.canSelectWord = true;
       
    70 		++this.currentWorldIndex;
       
    71 
       
    72 		// Change list of words
       
    73 		this.setWords(this.currentWorldIndex);
       
    74 
       
    75 		// Fade the text
       
    76 		$('.big_txt').animate({opacity: 1}, 20000 * 1 / effectSpeed);
       
    77 
       
    78 		if (this.currentWorldIndex == 3) {
       
    79 			// The 3 words get choosen
       
    80 			location.href = "niv1_videoplayer.html";
       
    81 		}
       
    82 	}
    38 
    83 
    39 	this.setCookie = function(name, value)
    84 	this.setCookie = function(name, value)
    40 	{
    85 	{
    41 		$.removeCookie(name);
    86 		$.removeCookie(name);
    42 		$.cookie(name, value, { expires: 7, path: '/' });    	
    87 		$.cookie(name, value, { expires: 7, path: '/' });