/*! BEGIN: jquery.typewatch.js */
(function(jQuery) {
    jQuery.fn.typeWatch = function(o) {
        var options = jQuery.extend({
            wait: 750,
            callback: function() { },
            highlight: true,
            captureLength: 2
        }, o);

        function checkElement(timer, override) {
            var elTxt = jQuery(timer.el).val();

            if ((elTxt.length > options.captureLength && elTxt.toUpperCase() != timer.text)
			|| (override && elTxt.length > options.captureLength)) {
                timer.text = elTxt.toUpperCase();
                timer.cb(elTxt);
            }
        };

        function watchElement(elem) {
            if (elem.type.toUpperCase() == "TEXT" || elem.nodeName.toUpperCase() == "TEXTAREA") {
                var timer = {
                    timer: null,
                    text: jQuery(elem).val().toUpperCase(),
                    cb: options.callback,
                    el: elem,
                    wait: options.wait
                };

                if (options.highlight) {
                    jQuery(elem).focus(
						function() {
						    this.select();
						});
                }

                var startWatch = function(evt) {
                    var timerWait = timer.wait;
                    var overrideBool = false;

                    if (evt.keyCode == 13 && this.type.toUpperCase() == "TEXT") {
                        timerWait = 1;
                        overrideBool = true;
                    }

                    var timerCallbackFx = function() {
                        checkElement(timer, overrideBool)
                    }

                    clearTimeout(timer.timer);
                    timer.timer = setTimeout(timerCallbackFx, timerWait);

                };

                jQuery(elem).keydown(startWatch);
            }
        };

        return this.each(function(index) {
            watchElement(this);
        });

    };

})(jQuery);
/* END: jquery.typewatch.js */


function styleCode() {
var hascode = false;
$("pre code").parent().each(function() {
 if (!$(this).hasClass('prettyprint')) {
   $(this).addClass('prettyprint');
   hascode = true;
 }
});

if (hascode) { prettyPrint(); }
};



function initStyleCode() {
    $("#comment").typeWatch( { highlight:false, wait:5000, captureLength: 5, callback:styleCode } );
}
