Sudomake = {
    fireworkDisplay: function() {
        for(var i=0; i<20; i++) {
            setTimeout(
                function() {
                    createFirework(11 + parseInt(Math.random()*10) ,30,3,4,null,null,null,null,false,true);
                },
                i * 500
            );
        }
    }
};

(function($) {
    $(document).ready(function(){

        /* auto populate */

        $('.populate').each(function() {
            if ($(this).val() == '' ) {
                $(this).val( $(this).attr('title') );
            }
            $(this).focus(function() {
                    if ( $(this).val() == $(this).attr('title') ) {
                        $(this).val('');
                    }
                })
                .blur(function() {
                    if ( $(this).val() == '' ) {
                        $(this).val( $(this).attr('title') );
                    }
                });
            $('label[@for='+$(this).attr('id')+']').addClass('structural');
        });

        $('#request_doer_name').focus(function() {
            $('#request input[type="radio"]').val(["known"]);
        });
        $('#request_herotype_known').click(function() {
            $('#request_doer_name').focus();
        });
        
        /* keystroke */
        var run = function(cmd) {
            if (cmd.match(/% sudo make profit$/)) {
                window.location = "/page/500";
                return;
            }
            if (cmd.match(/% sudo make firework$/)) {
                Sudomake.fireworkDisplay();
                return;
            }
        };

        var str = "";
        $("body").bind("keypress", function(e) {
            if (e.which == 13) {
                run(str);
                str = "";
            }
            else {
                str += String.fromCharCode(e.charCode);
                if (str.length > 100) {
                    str = ""
                }
            }
            return true;
        });
    });
})(jQuery);

if (!$.cookie("tzoffset")) {
    $.cookie("tzoffset", (new Date()).getTimezoneOffset(), { expires: 7 });
}

