﻿jQuery.fn.initTextbox = function(options) {
    var defaults = {
        text: "", //initial value in the text box
        colour: "#000", //initial colour of the text
        changeColour: "#000" //colour when the text changes
    };

    var opts = jQuery.extend(defaults, options);
    var $box = this;

    //initialise textbox and setup events
    $box
        .val(opts.text)
        .css("color", opts.colour)
        .focus(function() {
            if ($box.val() == opts.text)
                $box.val("");
        })
        .blur(function() {
            if ($box.val() == "") {
                $box.val(opts.text);
                $box.css("color", opts.colour);
            }
        })
        .keyup(function() {
            $box.css("color", $box.val() == opts.text ? opts.colour : opts.changeColour);
        });
}