﻿
(function($) {

    // plugin definition
    $.fn.overlabel = function(options) {

        // build main options before element iteration
        var opts = $.extend({}, $.fn.overlabel.defaults, options);

        var selection = this.filter('input').map(function() {

            //var label = $(this);
            var field = $(this);

            //var id = label.attr('for');
            //var field = document.getElementById(id);



            if (!field) return;

            // build element specific options
            var o = $.meta ? $.extend({}, opts, label.data()) : opts;

            var label = $('<label for="' + field.attr('id') + '">' + o.text + '</label>');
            $("#existing_cust").append(label);

            label.addClass(o.label_class);

            label.css({ top: field.position().top + 2 + 'px',
                left: field.position().left + 2 + 'px',
                position: 'absolute',
                width: field.width() - 2 + 'px',
                height: field.height() - 2 + 'px'
            });

            var hide_label = function() { /*label.css(o.hide_css)*/label.hide(); };
            var show_label = function() { this.value || /*label.css(o.show_css)*/label.show(); };

            $(field)
            //.parent().addClass(o.wrapper_class).end()
                 .focus(hide_label).blur(show_label).each(hide_label).each(show_label);

            $(window).resize(function() {
            label.css({ top: field.position().top + 2 + 'px',
                left: field.position().left + 2 + 'px',
                position: 'absolute',
                width: field.width() - 2 + 'px',
                height: field.height() - 2 + 'px'
            });
            });


            return this;

        });

        return opts.filter ? selection : selection.end();
    };

    // publicly accessible defaults
    $.fn.overlabel.defaults = {

        label_class: 'overlabel-apply',
        wrapper_class: 'overlabel-wrapper',
        hide_css: { 'text-indent': '-10000px' },
        show_css: { 'text-indent': '0px', 'cursor': 'text' },
        filter: false,
        text: 'Enter Details'

    };

})(jQuery);
