var captchasuffix=Math.floor(Math.random()*5);
$(document).ready(function(){
    $('.zf_image').each(function() {
    	var field = $(this).next().get(0).name;
        var append = window.location.href.charAt(window.location.href.length - 1) == '/' ? 'field/' : '/field/';
        $(this).append(' &nbsp; &nbsp; <a href="' + window.location.href.replace('modify', 'delete_image') + append + field + '/">удалить</a>');
        
	});
    
    $(':input[type=checkbox].all_checker').click(function () {
        var name = this.id.split('_all')[0] + '[]';
        $(':input[name=' + name + ']').attr('checked', this.checked);
    });
    
    $('img[src^="/captcha"]').captcharefresh();
    
});

jQuery.fn.captcharefresh = function(refresh)
{
	if (typeof refresh !='undefined') {
		jQuery(this).attr('src', jQuery(this).attr('src')+captchasuffix++);
		return;
	}
	jQuery(this).unbind('click').attr('src', jQuery(this).attr('src')+captchasuffix++).bind('load', function() {
		jQuery(this).next().hide();
		jQuery(this).bind('click', function(){
			jQuery(this).next().show();
			jQuery(this).captcharefresh();
		});
	});
};
