var removeWebsite = {
	init : function() {
		$("a.minus").click(function(){
			if (1 <= $(this).parent().siblings().length) { // don't remove last one
				$(this).parent().remove();
			} else { // just clear the last one
				$(this).prev("input.text").attr("value","");
			}
			return false;
		});
	}
}


$(document).ready(function(){
	$("a.plus").click(function(){
		// grab pattern and count of previous input
		var fieldName = $(this).parent().prev().find("li:last-child input").attr("name");
		var parts = fieldName.split("_");
		var newFieldName = parts[0] + "_" + (parseInt(parts[1])+1);
		$(this).parent().prev().append("<li><input type='text' class='text' name='"+newFieldName+"' id='"+newFieldName+"' /> <a href='#TDB' class='gl minus' title='remove'>remove<span></span></a></li>");
		removeWebsite.init();
		this.blur();
		return false;
	});

	removeWebsite.init();
});

