$(function () {

        $.fn.delay = function(time, callback){
                jQuery.fx.step.delay = function(){};
                return this.animate({delay:1}, time, callback);
        }

        // Increase Font Size
        $(".increaseFont").click(function(){
                var currentFontSize = $('html').css('font-size');
                var currentFontSizeNum = parseFloat(currentFontSize, 1);
                var newFontSize = currentFontSizeNum+2;
                $('html').css('font-size', newFontSize);
                $.cookie('fbgFontSize', newFontSize, { expires: 365, path: '/' });
                return false;
        });
        // Decrease Font Size
        $(".decreaseFont").click(function(){
                var currentFontSize = $('html').css('font-size');
                var currentFontSizeNum = parseFloat(currentFontSize, 1);
                var newFontSize = currentFontSizeNum-2;
                $('html').css('font-size', newFontSize);
                $.cookie('fbgFontSize', newFontSize, { expires: 365, path: '/' });
                return false;
        });
        // Schriftgroesse speichern
        if ($.cookie('fbgFontSize') !== null) {
                var fs = $.cookie('fbgFontSize');
                $('html').css('font-size', fs + 'px');
        }

        $(".handleAjaxForm").submit(function () {
                var $form = $(this);
                $form.find(".success").remove();
                $.post(this.action, $(this).serialize(), function (data) {
                        if (data.errors != undefined) {
                                $form.append('<div class="showErrors success">' + data.errors + '</div>').find('.success').trigger('fade');
                        }
                        else {
                                handleResponse(data);
                        }
                }, 'json');
                return false;
        });

        function handleResponse(data) {
                if (data.redirect != undefined) {
                        location.href = data.redirect;
                }
                else if (data.success != undefined) {
                        $form.append('<div class="success">' + data.success + '</div>').find('.success').trigger('fading');
                }
        }

        $('.success').live('fade', function () {
                $(this).fadeIn();
        });

        $('.success').live('fading', function () {
                $(this).fadeIn().delay(3000, function () {
                        $(this).fadeOut('normal', function () {
                                $(this).remove();
                        });
                });
        });

});

