var puzzlemobile = false;

function puzzleOnSuccess()
{
    if (!puzzlemobile)
    {
        $('#puzzleimage').html('<img src="/media/3356/twitter_500x500px_succes.jpg" alt="Xuntos" id="jqpuzzle"/>');
    }
    else
    {
        $('#puzzleimage').html('<img src="/media/3351/twitter_240x240px_succes.jpg" alt="Xuntos" id="jqpuzzle"/>');
    }
    $("#puzzlehomelink").show();
    $('#puzzleimage').click(function(){
        location.href = "/";
    });
    $('#puzzleimage').css("cursor", "pointer");
}

var settings =
{
    //rows: 5,                    // number of rows [3 ... 9]
    //cols: 5,                    // number of columns [3 ... 9]
    //hole: 9,                   // initial hole position [1 ... rows*columns]
    rows: 4,                    // number of rows [3 ... 9]
    cols: 4,                    // number of columns [3 ... 9]
    hole: 25,                   // initial hole position [1 ... rows*columns]
    shuffle: true,             // initially show shuffled pieces [true|false]
    numbers: false,              // initially show numbers on pieces [true|false]
    language: 'nl',             // language for gui elements [language code]

    // display additional gui controls
    control:
    {
        shufflePieces: false,    // display 'Shuffle' button [true|false]
        confirmShuffle: false,   // ask before shuffling [true|false]
        toggleOriginal: false,   // display 'Original' button [true|false]
        toggleNumbers: false,    // display 'Numbers' button [true|false]
        counter: true,          // display moves counter [true|false]
        timer: true,            // display timer (seconds) [true|false]
        pauseTimer: true        // pause timer if 'Original' button is activated
                                // [true|false]
    },

    // perform actions when the puzzle is solved sucessfully
    success:
    {
        fadeOriginal: true,    // cross-fade original image [true|false]
        callback: function ()
            {
                puzzleOnSuccess()
            },                  // callback a user-defined function [function]
                                // the function is passed an object as its argument
                                // which includes the fields 'moves' and 'seconds'
        callbackTimeout: 1500    // time in ms after which the callback is called
    },

    // animation speeds and settings
    animation: {
        shuffleRounds: 4,       // number of shuffle rounds [1 ... ]
        shuffleSpeed: 500,      // time in ms to perform a shuffle round
        slidingSpeed: 200,      // time in ms for a single move
        fadeOriginalSpeed: 600  // time in ms to cross-fade original image
    },

    // additional style information not specified via css
    style: {
        gridSize: 1,            // space between two pieces in px
        overlap: true,          // if true, adjacent piece borders will overlap
                                // applies only if gridSize is set to 0
        backgroundOpacity: 0  // opacity of the original image behind the pieces
                                // [0 ... 1] (0 means no display)
    }
}

var texts = {
    shuffleLabel:           'Reshuffle',
    toggleOriginalLabel:    'Origineel',
    toggleNumbersLabel:     'Tegelnummers',
    confirmShuffleMessage:  'Wil je echt opnieuw shuffelen?',
    movesLabel:             'zetten',
    secondsLabel:           'seconden'
}

$(document).ready(function()
{
    if ($(window).height() > 480 && $(window).width() > 480)
    {
        puzzlemobile = false;
    }
    else
    {
        puzzlemobile = true;
    }
    if (!puzzlemobile)
    {
        $('#puzzleimage').html('<img src="/media/3346/penguins_500x500px_start.jpg" alt="Xuntos" id="jqpuzzle"/>');
    }
    else
    {
        $('#puzzleimage').html('<img src="/media/3268/penguins_240x240px_start.jpg" alt="Xuntos" id="jqpuzzle"/>');
    }
    $('#jqpuzzle').jqPuzzle(settings, texts);
    setTimeout('$("#jqpuzzle a:contains(jqPuzzle)").hide()', 1000);
});

