﻿(function($) {
    $.fn.question = function(options) {

        var 
		  defaults = {
		      background: '#e3e3e3',
		      color: 'black',
		      rounded: false,
		      className: "question",
		      questionClass: 'text',
		      answerClass: 'answer'
		  },
		  settings = $.extend({}, defaults, options);

        this.each(function() {
            var title = this.title;
            var width = '';
            var style = '';

            if ($(this).is('div') && $(this).attr('title') != '') {
                $(this).attr('title', '');

                if (settings.width)
                    style += "width:" + settings.width + ";";

                if (settings.margin)
                    style += "margin:" + settings.margin + ";";

                $(this).attr('style', style);

                $(this).addClass(settings.className);

                var titleHtml = "<div class='" + settings.questionClass + "'>" + title + "</div>";

                $(this).prepend(titleHtml);

                $(this).children().each(function() {
                    if ($(this).attr('class') == '' && $(this).is('div')) {
                        $(this).addClass(settings.answerClass);
                    }
                });
            }
        });
        return this;
    }
})(jQuery);
