$(function() {

    $('.load_modal').live('click', function(){
        $.colorbox({href: $(this).attr('href') + '?modal=1', title: $(this).attr('title'), overlayClose: false});
        return false;
    });

    $('.image_link').colorbox();

    $('form.simpleForm').live('submit', function(){
         $.loader.show();
         $button = $(this).find('button');
         $button.attr('disabled', 'disabled');
         $.ajax({type: "POST", cache: false, url: $(this).attr('action'), data: $(this).serializeArray(), success: function(data) {
            $.loader.hide();
            $button.attr('disabled', '');
            if (data.indexOf('success') != -1) {
                if (data.indexOf('refresh') != -1) {
                    $.colorbox.close();
                    location.reload(true);
                    return false;
                } else {
                    $.colorbox({html: "<div class='success'>" + data + "</div>"});
                }
            } else {
                $.jGrowl(data);
                reloadCaptcha();
            }
		}
	    });
        return false;
    });

    $('#login').colorbox({inline: true, href: '#loginform'});

    $('a.request').live('click', function(){
        $.loader.show();
        $.post($(this).attr('href'), {ajax: 1}, function(data){
            $.loader.hide();
            $.jGrowl(data);
        });
        return false;
    });

});
