(function(window, document, $, undefined) { console.info('CAREFREE SLOT MACHINE: jquery version:' + $.fn.jquery); console.info('CAREFREE SLOT MACHINE: INITIALIZING'); console.info('----------------------------------------------'); $(document).ready(function() { rolling = false; //Fake machine 1 window.machine1 = $("#machineFake1").slotMachine({ active: 0, delay: 200 }); //Fake machine 2 window.machine2 = $("#machineFake2").slotMachine({ active: 0, delay: 200 }); //Fake machine 3 window.machine3 = $("#machineFake3").slotMachine({ active: 0, delay: 200 }); randomSet(); $("#slotMachineButtonFake img").mousedown(function() { $(this).attr('src', 'https://www.jnjcolombia.com/sites/default/files/content-images/marca_carefree/apps/slot-machine/img/btn-roll-on.png'); setTimeout(function() { $('#slotMachineButtonFake img').attr('src', 'https://www.jnjcolombia.com/sites/default/files/content-images/marca_carefree/apps/slot-machine/img/btn-roll.png'); }, 330); }); $("#slotMachineButtonFake").click(function() { if (!rolling) { roll(); audioStart.play(); if (typeof _gaq != 'undefined') { _gaq.push(['_trackEvent', 'button', 'click', 'Carefree_SlotMachine']); } } }); audioStart = document.createElement('audio'); audioStart.setAttribute('src', 'https://www.jnjcolombia.com/sites/default/files/content-images/marca_carefree/apps/slot-machine/sound/roll.mp3'); audioWinOne = document.createElement('audio'); audioWinOne.setAttribute('src', 'https://www.jnjcolombia.com/sites/default/files/content-images/marca_carefree/apps/slot-machine/sound/win_1.mp3'); audioWinTwo = document.createElement('audio'); audioWinTwo.setAttribute('src', 'https://www.jnjcolombia.com/sites/default/files/content-images/marca_carefree/apps/slot-machine/sound/win_1.mp3'); audioWinThree = document.createElement('audio'); audioWinThree.setAttribute('src', 'https://www.jnjcolombia.com/sites/default/files/content-images/marca_carefree/apps/slot-machine/sound/win_2.mp3'); }); function roll() { rolling = true; machine1.shuffle(10, function() { audioWinOne.play(); }); setTimeout(function() { machine2.shuffle(11, function() { audioWinTwo.play(); }); }, 200); setTimeout(function() { machine3.shuffle(12, function() { audioWinThree.play(); //Set copy setCopy(theCopy); //Set next randomSet(); $('#slot-machine .copy').slideDown(function() { $('#slot-machine .copy li:last-child').css('opacity', 1); setTimeout(function() { $('#slot-machine .final').fadeIn().delay(3000).fadeOut(); rolling = false; }, 2000); }); }); }, 400); } function setMachine(one, two, three) { machine1.setRandomize(function() { return one; }); machine2.setRandomize(function() { return two; }); machine3.setRandomize(function() { return three; }); } function setCopy(string) { $this = $('#slot-machine .copy .state'); $this.slideUp('fast', function() { $('#slot-machine .copy .state').html(string); $this.slideDown(); }) } function randomSet() { var option = Math.floor((Math.random() * 5) + 1); switch (option) { case 1: //Set siempre activa setMachine(1, 2, 5); theCopy = 'Activa'; break; case 2: //Set siempre motivada setMachine(3, 4, 12); theCopy = 'Motivada'; break; case 3: //Set siempre autentica setMachine(7, 8, 6); theCopy = 'Auténtica'; break; case 4: //Set siempre creativa setMachine(9, 10, 11); theCopy = 'Creativa'; break; case 5: //Set siempre alegre setMachine(0, 0, 0); theCopy = 'Alegre'; break; } } })(window, document, window.SlotMachine.jQuery);