function init() {
  // set random image for 'persona'
  var index = Math.floor(Math.random()*4);
  var positions = ['0px', '-130px', '-260px', '-400px'];
  var persona = document.getElementById('persona');
  persona.style.visibility = 'visible';
  persona.style.backgroundPosition = '0px '+positions[index];
  
  // code for the 'JS Interpreter and Execution' post
	if (!!document.getElementById('snippet1')) {
		addListener(document.getElementById('snippet1'), 'click', function (){
			// Snippet 1
			x = 4;
			function s1() {
			 alert(x);
			 var x = x;
			 alert(x);
			}
			s1();
		});
		addListener(document.getElementById('snippet2'), 'click', function (){
			// Snippet 1
			x = 4;
			function s2() {
			 alert(x);
			 // var x = x;
			 alert(x);
			}
			s2();
		});
	}
	
	// code for the 'Benchmark on the Floor' post
	if (!!document.getElementById('cvb')) {
    var bof = (function() {
      var floorpost = {}
      var colors = ['#8170aa', '#ba6d6b', '#87aa72', '#dcab5d']
      var ctx = document.getElementById('cvb').getContext('2d');
      var labels = document.getElementById('labels');
      renderAxis();
      var fnnum = 0
        floorpost.test = function(fn) {
          // Just go through the test once per each case
        	// to don't bore the user too much waiting for
        	// very long.
          setTimeout(function(){
            var start = new Date();
            for (var n = 0, t = 0; t < 1000; n++) {
              fn();
              t = new Date() - start;
            }
            ctx.save();
            ctx.translate(0,5);
            render(t * 1000/n, fnnum);
            if ( fnnum < fns.length - 1) {
              setTimeout( function() { floorpost.test(fns[++fnnum]) }, 0 );

            }
            ctx.restore();
          }, 0);
        };

        var fns = [mathfloor, doubletilda, pipe, umpersand] 
        document.getElementById('startb').onclick = function() {
          ctx.clearRect(90, 0, 200, 65);
          renderAxis();
          fnnum = 0;
          floorpost.test(fns[0])
        }
      
        function renderAxis() {
          ctx.drawImage(labels, 0, 0, 82, 60, 0, 0, 82, 60);
          ctx.drawImage(labels, 50, 60, 10, 15, 155, 50, 10, 15);
          ctx.drawImage(labels, 67, 60, 11, 15, 235, 50, 11, 15);        
          ctx.strokeStyle = '#ccc';
          ctx.moveTo(90, 0);
          ctx.lineTo(90, 65);
          ctx.stroke();
          ctx.strokeStyle = '#dedede';
          ctx.moveTo(170, 0);
          ctx.lineTo(170, 65);
          ctx.moveTo(250, 0);
          ctx.lineTo(250, 65);
          ctx.stroke();
        }

        function render(result, order) {
          ctx.fillStyle = colors[order];
          ctx.fillRect(90, 15*order, result*8, 10)
          // console.log(result+":"+order)
        }

        function mathfloor() {
          Math.floor(0.12341234);
          Math.floor(0.2);
          Math.floor(-3.1234);
          Math.floor(100000.23);
          Math.floor(2.12341234123412341324);
          Math.floor(100.0000000000000000001);    
        }

        function doubletilda() {
          ~~0.12341234;
          ~~0.2;
          ~~-3.1234;
          ~~100000.23;
          ~~2.12341234123412341324;
          ~~100.0000000000000000001;    
        }

        function pipe() {
          0.12341234|0.12341234;
          0.2|0.2;
          -3.1234|-3.1234;
          100000.23|100000.23;
          2.12341234123412341324|2.12341234123412341324;
          100.0000000000000000001|100.0000000000000000001;    
        }

        function umpersand() {
          0.12341234&0.12341234;
          0.2&0.2;
          -3.1234&-3.1234;
          100000.23&100000.23;
          2.12341234123412341324&2.12341234123412341324;
          100.0000000000000000001&100.0000000000000000001;    
        }          
      })();  
    }
}

function addListener(el, sType, fn, capture) {
	if (window.addEventListener) {
		el.addEventListener(sType, fn, (capture));
	} 
	else if (window.attachEvent) {
		el.attachEvent("on" + sType, fn);
	}
}


