$.extend({ofelia: {
    form: {
        selector: 'textarea, input[type="text"]',

        helper_text: function (el) {
            var helper;

            if (helper = el.attr('alt')) { return helper; }
            else { return el.attr('title'); }
        },

        clear_helper:   function (el) { if ($.ofelia.form.helper_text(el) == el.val()) el.val(''); },
        restore_helper: function (el) { if (el.val() == '') el.val($.ofelia.form.helper_text(el)); },

        clear_helpers: function (el) {
            $($.ofelia.form.selector, el).each(function () { $.ofelia.form.clear_helper($(this)); });
        },

        register_field: function (el) {
            el.val(this.helper_text(el));
            el.addClass('input-text');

            el.focus(function () { $.ofelia.form.clear_helper($(this)); })
               .blur(function () { $.ofelia.form.restore_helper($(this)); });
        },

        register_forms: function () {
            $('form').each(function () {
                var el = $(this);

                $($.ofelia.form.selector, el).each(function () { $.ofelia.form.register_field($(this)); });
                el.submit(function () { $.ofelia.form.clear_helpers($(this)); });
            });
        }
    }
}});

$(function () {
    $(function () {
        $('a[href^="mailto:"]').each(function (n) {
            var href = $(this).attr('href').replace(/\(at\)/, '@').replace(/\(punkt\)/, '.');
            var text = $(this).text().replace(/\(at\)/, '@').replace(/\(punkt\)/, '.');
            $(this).attr('href', href).text(text);
        });
    });
    
    $('#page-press label').hide();
    $(function () { $.ofelia.form.register_forms(); });
    
    $('#product-interaction button').hide();
    $('#product-interaction select').change(function () {
        $('#product-interaction select').not(this).val("");
        $(this).parents('form').get(0).submit();
    });
});