﻿(function ($) {
    $.fn.initTextbox = function (opts) {
        var options = {
            text: "",
            initColour: "#000", //Initial colour of text
            changeColour: "#000" //Colour when text changes
        };

        $.extend(options, opts);

        return this.each(function () {
            var $box = $(this);

            //initialise textbox and setup events
            $box
                .css("color", options.initColour)
                .focus(function () {
                    if ($box.val().toLowerCase() == options.text.toLowerCase()) {
                        $box.val("");
                    }
                })
                .blur(function () {
                    if (!$box.val()) { //Nothing in the box ("", undefined, null)
                        $box.val(options.text);
                        $box.css("color", options.initColour);
                    }
                })
                .keyup(function () {
                    $box.css("color", $box.val().toLowerCase() == options.text.toLowerCase() ? options.initColour : options.changeColour);
                });
        });
    }
})(jQuery);
