(function($) {
    
    function balance_rows(sections, per_row) {
        var heights = [];
        
        function index(i) {
            return Math.floor(i / per_row)
        };
        sections.each(function(i) {
            heights[index(i)] = Math.max($(this).height(), heights[index(i)] || 0);
        });
        sections.each(function(i) {
            $(this).css({
                height: heights[index(i)] + 'px'
            });
        });
    };
 
    function homepage_init() {
        if ($('body').hasClass('home')) {
            balance_rows($('body.home #events section'), 3);
        }
    };
     
    function events_init() {
        $('ul.eventlist').each(function() {
            balance_rows($(this).find('li'), 3);
        });
    };
    
    
    
    $(function() {
        
        $('#send-form-link').click(function () {
            var form = $('#send-form');
            if (!form.hasClass('shown')) {
                form.fadeIn(400).addClass('shown');			
            } else {
                form.hide().removeClass('shown');
            }
            return false;
        });
        
        
        if ($("#theslider li img").length > 1) {
            $("#theslider").easySlider({
                auto: true,
                pause: 5000,
                speed: 1100,
                continuous: true,
                controlsShow: false
            });
        }
        
        
        homepage_init();
        events_init();
    
        $('form p').each(function() {
            $(this).css({
                minHeight: $(this).find('label').height() + 'px'
            });
        });
    });
        
})(jQuery);
