MultiFileWidget = function (name) {
	this.name   = name;
	this.parent = $(".widget-files-" + this.name);
	this.init();
}

MultiFileWidget.prototype.init = function () {
	this.addEvents();
	this.setDefaultLabel();
}

MultiFileWidget.prototype.addEvents = function () {
	var controller = this;
	
	$(".add-file", this.parent).click(function () { controller.onAddFile(); });
	$(".default", this.parent).click(function () { controller.setDefaultLabel(); });
	$(".js-delete", this.parent).click(function () { $(this).parent().remove() });
}

MultiFileWidget.prototype.onAddFile = function () {
	var html = '<div class="file-c"><input type="file" name="' + this.name + '" class="file" /><span class="js-link js-delete">Удалить</span></div>';
	
	$(".new", this.parent).append(html);
	$(".js-delete", this.parent).click(function () { $(this).parent().remove() });
}

MultiFileWidget.prototype.setDefaultLabel = function () {
	$(".default", this.parent).next().text('');
	$(".default[checked]", this.parent).next().text('По умолчанию');
}
