﻿(function($) {
    $.fn.faq = function(options) {
        var defaults = {
            question: 'question',
            answer: 'answer'
        };
        var opts = $.extend({}, defaults, options);

        return this.each(function() {
            element = $(this).find(':first-child').get(0).tagName;
            $(element + '[id^="' + opts.answer + '"]').toggle();
            $(element + '[id^="' + opts.question + '"]').each(function() {
                $(this).click(function() {
                    id = $(this).attr('id').substr(opts.question.length + 1);
                    $('#' + opts.answer + '-' + id).toggle();
                });
            });
        });
    };
})(jQuery);
