/**
Textarea input
@class textarea
@extends abstract
@final
@example
**/
(function ($) {
    var Textarea = function (options) {
        this.init('textarea', options, Textarea.defaults);
    };
    $.fn.editableutils.inherit(Textarea, $.fn.editabletypes.abstract);
    $.extend(Textarea.prototype, {
        render: function () {
            Textarea.superclass.render.call(this);
            //ctrl + enter
            this.$input.keydown(function (e) {
                if (e.ctrlKey && e.which === 13) {
                    $(this).closest('form').submit();
                }
            });
        },
        value2html: function(value, element) {
            var html = '', lines;
            if(value) {
                lines = value.split("\n");
                for (var i = 0; i < lines.length; i++) {
                    lines[i] = $('
').text(lines[i]).html();
                }
                html = lines.join('
');
            }
            $(element).html(html);
        },
        html2value: function(html) {
            if(!html) {
                return '';
            }
            var lines = html.split(/
/i);
            for (var i = 0; i < lines.length; i++) {
                lines[i] = $('
').html(lines[i]).text();
            }
            return lines.join("\n"); 
        },        
        activate: function() {
            if(this.$input.is(':visible')) {
                $.fn.editableutils.setCursorPosition(this.$input.get(0), this.$input.val().length);
                this.$input.focus();
            }
        }         
    });
    Textarea.defaults = $.extend({}, $.fn.editabletypes.abstract.defaults, {
        /**
        @property tpl 
        @default 
        **/          
        tpl:'',
        /**
        @property inputclass 
        @default input-large
        **/          
        inputclass: 'input-large',
        /**
        Placeholder attribute of input. Shown when input is empty.
        @property placeholder 
        @type string
        @default null
        **/             
        placeholder: null        
    });
    $.fn.editabletypes.textarea = Textarea;    
}(window.jQuery));