
( function( $ ) {
    jQuery.fn.frozTextPreview = function( options ) {
        var opts                            = jQuery.extend( {}, jQuery.fn.frozTextPreview.defaults, options );
        jQuery.fn.frozTextPreview.opts      = opts;
        var $this                           = jQuery( this );
        
        input = new Array();
        output = new Array();
        
        for(element in opts.input){
            input[element] = opts.input[element];
        }
        
        for(element in opts.output){
            output[element] = opts.output[element];
        }
        
        for(element in input){
            jQuery(input[element]).bind( 'click', {el:element}, function(event){
                if ( jQuery(this).attr('id') === 'form-state' || jQuery(this).attr('id') === 'form-country'){
                    jQuery(output[event.data.el]).text(jQuery(':input', this).val());
                }
            });
            jQuery(input[element]).bind( 'keyup', {el:element}, function(event){
                if ( jQuery(this).attr('id') === 'form-phone' ){
                    jQuery(output[event.data.el]).text('Phone: ' + jQuery(':input', this).val());
                } else if ( jQuery(this).attr('id') === 'form-fax' ){
                    jQuery(output[event.data.el]).text('Fax: ' + jQuery(':input', this).val());
                } else {
                    if ( jQuery(this).attr('id') !== 'submit_btn' ){
                        jQuery(output[event.data.el]).text(jQuery(':input', this).val());
                    }
                }
            });
        };
        
        return $this;
    };
    
    jQuery.fn.frozTextPreview.defaults =   {
        defaultDisplay: true,       // if true, initial form values are copied to preview upon loading
        input: null,                // selectors to elements containing each individual form field (array)
        output: null                // selectors to elements containing each preview element (array)
    };
} )(jQuery);

