if (typeof jQuery != 'undefined') {
    jQuery(function ($) {
        $.fn.extend({
            labelOver: function (options) {
                var settings = $.extend({}, $.fn.labelOver.defaults, options);
                return this.each(function () {
                    var l = jQuery(this);
                    var t = l.text();
                    var f = l.attr('for');
                    if (f) {
                        var input = jQuery('#' + f);

                        // Change the colour (if relevant)
                        input.focus(function () {
                            if (input.val() == '' || input.val() == t) {
                                input.val('');
                                if (settings.focusColour != '') {
                                    input.css('color', settings.focusColour);
                                }
                            }
                        });

                        input.blur(function () {
                            if (input.val() == '' || input.val() == t) {
                                input.val(t);
                                if (settings.blurColour != '') {
                                    input.css('color', settings.blurColour)
                                }
                            }
                        });

                        if (settings.assignTitle && input.attr('title') == '') {
                            input.attr('title', t);
                        }

                        l.remove();

                        if (input.val() == '')
                            input.val(t);

                        //Find the parent form and wire up a on submit
                        $("#search .btn").click(function (e) {
                            if ((input.val() == '' || input.val() == t) && settings.allowBlankSubmit) {
                                input.val('');
                            } else if ((input.val() == '' || input.val() == t) && !settings.allowBlankSubmit) {
                                stopEvent(e);
                                return false;
                            }
                        });
                    };
                });
            }
        });

        $.fn.labelOver.defaults = {
            assignTitle: true,
            focusColour: '',
            blurColour: '',
            allowBlankSubmit: true
        };
    });
}
function stopEvent(e) {
    if (e.stopPropagation) e.stopPropagation();
    else e.cancelBubble = true;

    if (e.preventDefault) e.preventDefault();
    else e.returnValue = false;
}
