$(document).ready(function() {
	// Pokemon function
    var pokemon = function (data) {
        for (var i in data)
        {
            data[i] = "Pi ";
            for (var j = Math.random() * 3; j >= 0; j--)
                data[i] += (((Math.random() * 2) > 1) ? ("cheww ") : ("pika "));
        }
        return data;
    }

    // Tests
    // Without params
	$(".one").james("script.php", {});
	$(".five").james("script_json.php", {});
	// minlength: 1, method: post, keydelay 1000
    $(".two").james("script.php", {
        minlength: 1,
        method: "post",
        keydelay: 1000
    });
    $(".six").james("script_json.php", {
        minlength: 1,
        method: "post",
        keydelay: 1000
    });
    // onKeystroke: pikachuuu!
    $(".three").james("script.php", {
        onKeystroke: function (data) {
            return pokemon(data);
        }
    });
    $(".seven").james("script_json.php", {
        onKeystroke: function (data) {
            return pokemon(data);
        }
    });
    // On select Alert
    $(".four").james("script.php", {
        onSelect: function (text) {
            alert(text);
            return ("42");
        }
    });
    $(".height").james("script_json.php", {
        onSelect: function (text, obj) {
            alert(text);
            return ("Name of JSON Object: " + obj.name);
        }
    });
});

