
            $(document).ready(function() {
            
                //default settings
                var settings1 =  {
                    categories : ["good", "bad"],             /** categories to sort target words to */
                    targets: [ ["lovely", 0],                 /** target words to categorize */
                               ["nice", 0],
                               ["friendly", 0],
                               ["ugly", 1],
                               ["evil", 1],
                               ["terrible", 1] ],
                    keys: ["space", "e", "i"],                            /** keybord keys */
                    sequence: 'random',                                   /** display targets in 'fixed' or 'random' sequence */  
                    runs: 1,                                              /** number of times to display targets */
                    frmid: "iatresult1",                                   /** id of hidden form element to save data to */
                    separator: [":", ";"],                                /** value separators in hidden form field (0: in target, 1: between targets) */
                    delay: 800,                                           /** time delay between two target words (in ms) */
                    popup: 0,                                             /** display in popup */
                    dispfalse: 1,                                         /** display feedback for incorrect categorizations */
                    disptrue: 0,                                          /** display feedback for correct categorizations */
                    report: 1,                                            /** report iat results on last page */
                    onload: function()  {},                               /** function to run before loading the script */
                    onstart: function() {},                               /** function to run on test start */
                    onend: function() {}                                  /** function to run on test end */
                };
                
                //clone objects
                //Object.prototype.clone = function() { return eval(uneval(this)); }
                function clone(obj) {
                    if(obj == null || typeof(obj) != 'object') return obj;
                    var temp = new obj.constructor();
                    for(var key in obj) temp[key] = clone(obj[key]);
                    return temp;
                }
                var settings2 = clone(settings1);
                var settings3 = clone(settings1);
                var settings4 = clone(settings1);
                //var settings2 = settings1.clone();
                //var settings3 = settings1.clone();
                //var settings4 = settings1.clone();
                settings2.frmid = 'iatresult2';
                settings2.categories = new Array("heaven", "hell");
                settings2.targets = new Array( ["god", 0], ["angel", 0], ["saint", 0],
                                               ["devil", 1], ["satan", 1], ["demon", 1]);
                settings3.frmid = 'iatresult3';
                settings3.categories = new Array("heaven<br/>good", "hell<br/>bad");
                settings3.targets = new Array( ["god", 0], ["angel", 0], ["saint", 0], ["lovely", 0], ["nice", 0], ["friendly", 0],
                                               ["devil", 1], ["satan", 1], ["demon", 1], ["ugly", 1], ["evil", 1], ["terrible", 1] );
                settings4.frmid = 'iatresult4';
                settings4.categories = new Array("heaven<br/>bad", "hell<br/>good");
                settings4.targets = new Array( ["god", 0], ["angel", 0], ["saint", 0], ["ugly", 0], ["evil", 0], ["terrible", 0],
                                               ["devil", 1], ["satan", 1], ["demon", 1], ["lovely", 1], ["nice", 1], ["friendly", 1] );
                                               
                //display results
                settings1.onend = function() {
                    $.hotkeys.add(settings1.keys[0], function() {
                        $.hotkeys.remove(settings1.keys[0]);
                        messages.instruction = "<p>The categories have changed. Try again categorizing the words as fast as possible by pressing the letters <strong>E</strong> or <strong>I</strong>.</p><p style=\"text-align:center;color:red;font-weight: 600;\">Press SPACE to begin.</p>";
                        $("#iat").iat(settings2, messages);
                     });
                };
                settings2.onend = function() {
                    $.hotkeys.add(settings2.keys[0], function() { 
                        $.hotkeys.remove(settings2.keys[0]);
                        messages.instruction = "<p>Now the two categories are combined. Categorize the words into one of the categories at the top by pressing the letters <strong>E</strong>, if the item belongs to one of the left categories, or <strong>I</strong>, if the item belongs to one of the right categories, on your keyboard.</p><p style=\"text-align:center;color:red;font-weight: 600;\">Press SPACE to begin.</p>";
                        $("#iat").iat(settings3, messages);
                     });
                };
                settings3.onend = function() {
                    $.hotkeys.add(settings3.keys[0], function() { 
                        $.hotkeys.remove(settings3.keys[0]);
                        messages.instruction = "<p>Note that for this last block the categories have changed. Categorize the words again into one of the categories at the top by pressing the letters <strong>E</strong> or <strong>I</strong>.</p><p style=\"text-align:center;color:red;font-weight: 600;\">Press SPACE to begin.</p>";
                        $("#iat").iat(settings4, messages);
                     });
                };
                settings4.onend = function() {
                    $.hotkeys.add(settings4.keys[0], function() { 
                        $.hotkeys.remove(settings4.keys[0]);
                        var res = ($("#iatresult3").val()).split(";");
                        var time1 = 0;
                        var cnt = 0;
                        if(res.length) {
                            for(var i = 0; i < res.length; i++) {
                                if(res[i].length) {
                                    cnt++;
                                    var t = res[i].split(":");
                                    time1 = time1 + parseInt(t[4], 10);
                                }
                            }
                            time1 = time1 / cnt;
                        }
                        res = ($("#iatresult4").val()).split(";");
                        var time2 = 0;
                        cnt = 0;
                        if(res.length) {
                            for(var i = 0; i < res.length; i++) {
                                if(res[i].length) {
                                    cnt++;
                                    var t = res[i].split(":");
                                    time2 = time2 + parseInt(t[4], 10);
                                }
                            }
                            time2 = time2 / cnt;
                        }
                        var diff = (time1 - time2);
                        $("#iat").html("<p><b>Ergebnis</b></p><p class=\"iatInstruction\" style=\"text-align:center;\">Mean time difference: " + (Math.round((time1-time2)/10)/100) + "<br/><br/>You seem to have a slight preference for<br/>" + (((time1-time2)<0) ? "<b>heaven</b> over hell" : "<b>hell</b> over heaven") + ".</p>");

                     });
                };
                
                //default messages
                var messages = {
                    instruction: "<p>Put your middle index fingers on the <b>E</b> and <b>I</b> keys of your keyboard. Try categorizing the words, which will be appearing in the middle of the screen, as fast as possible into one of the categories at the top by pressing the letters <b>E</b>, if the item belongs to the left category, or <b>I</b>, if the item belongs to the right category, on your keyboard.</p><p style=\"text-align:center;color:red;font-weight: 600;\">Press SPACE to begin.</p>",
                    wrong: "X",
                    report: "<p>Your results:</p><ul><li class=\".iatTrue\">Correct: %true%</li><li class=\".iatFalse\">Errors: %false%</li><li>Mean Reaction Time: %mean% sec</li><li>Longest Reaction Time: %long% sec</li><li>Fastest reaction time: %short% sec</li></ul><p style=\"text-align:center;color:red;font-weight: 600;\">Press SPACE to proceed.</p>"
                };

                //load iat
                $("#iat").iat(settings1, messages);

            });

