/* ================================================================ This copyright notice must be untouched at all times. The original version of this short url script is available at http://www.nuff-respec.com/technology/slide-puzzle-javascript-mootools Copyright (c) 2005-2007 Daniel Bulli. All rights reserved. This code may be modified in any way to fit your requirements. author : daniel bulli license: MIT-style license history: 04/26/2007 dbulli : Initial version =================================================================== */ /* removed all alert("Sorry no DIV with id #puzzle, OR it does not have an img tag."); */ var Puzzle = { /* -- ----------------------------------------------- | PUBLIC FUNCTIONS | ----------------------------------------------- */ //CONFIGURABLE 'BORDER_WIDTH' : 5, //BORDER WIDTH 'BORDER_COLOR' : '#000', //BORDER COLOR 'SPEED' : 200, //TRANSITION SPEED //---------------------------------------------- // MAKE PUZZLE // :: sets up puzzle from image // :: one parameter for number of rows/cols //---------------------------------------------- /** * Example (4x4) : * Puzzle.make(4); * * Probably better to call on load event * window.addEvent('load', Puzzle.make.pass(4)); **/ make: function(how_many) { if (!$('puzzle') || !$E('img','puzzle')) { //NO PUZZLE /*alert("Sorry no DIV with id #puzzle, OR it does not have an img tag.");*/ return false; } //MINIMAL ERROR CHECKING if(Puzzle.initialized) { alert('Puzzle ALREADY initialized.'); return false; } //STORE HOW MANY COLS/ROWS how_many = parseInt(how_many); Puzzle.how_many = parseInt(how_many); //SET INITIAL EMPTY SQUARE Puzzle.empty_x = Puzzle.how_many-1; Puzzle.empty_y = Puzzle.how_many-1; //GRAB IMAGE FROM PUZZLE DIV var puzzle_image = $E('img','puzzle'); //MAKE PUZZLE DIV SAME HEIGHT+WIDTH $('puzzle').setStyles({ width: puzzle_image.width + 'px', height: puzzle_image.height + 'px', overflow: 'hidden' }); //CALCULATE HEIGHT/WIDTH of puzzle pieces Puzzle.width = Math.round((puzzle_image.width - ((Puzzle.how_many+1) * Puzzle.BORDER_WIDTH)) / how_many); Puzzle.height = Math.round((puzzle_image.height - ((Puzzle.how_many+1) * Puzzle.BORDER_WIDTH)) / how_many); //RESET SOLUTION STRING Puzzle.solution = ''; Puzzle.counter = 0; //LET's CREATE var p_num = 0; Puzzle.piece_arr = new Array(); for(var x=0; x