function PuzzlePiece(board, i, dim, isEmpty) { this.div = document.createElement("div"); var size = board.cellSize; var current = i; if (!isEmpty) { this.div.innerHTML = i + 1; } this.div.style.position = 'absolute'; this.update = function(i) { current = i; var y = Math.floor(i / dim); var x = i % dim; var pos = findPos(board.div); this.div.style.left = (pos.left + x * size) + "px"; this.div.style.top = (pos.top + y * size) + "px"; } this.update(i); };