﻿/*
* name: freestyle.form.ui.js
* author: RAJF
* notes: global form ui functions
*/

jQuery.fn.setHelp = function(options) {
    var defaults = {
        showText: 'show',
        hideText: 'hide',
        showImage: "",
        hideImage: ""
    };
    var settings = $.extend({}, defaults, options);
    return this.each(function() {
        var $this = jQuery(this);
        $this.hide();
        if (settings.showImage == "") {
            //debug($this.parent().find('label'))
            $this.parent().find('label').append(jQuery(document.createElement('a'))
            .addClass('info-link')
            .attr('href', '#')
            .text(settings.showText)
            .toggle(function() {
                $this.show();
                $(this).text(settings.hideText);
                return false;
            }, function() {
                $this.hide();
                $(this).text(settings.showText);
                return false;
            })
            );
        } else {
            $this.prev().append(jQuery(document.createElement('img'))
            .addClass('info-link')
            .attr('src', settings.showImage)
            .attr('alt', '')
            .toggle(function() {
                $this.show();
                $(this).attr('src', settings.hideImage);
                return false;
            }, function() {
                $this.hide();
                $(this).attr('src', settings.showImage);
                return false;
            })
            );
        }
    });
};
