var ximage = {
	max_upload:5,
	act_upload:1,

	load:function() {
		if($('#add_more').length) {
			$('#add_more').show();
		}
	},

	add_upload:function() {
		if(this.max_upload > this.act_upload) {
			$('#upload').append('<div id="upload_'+this.act_upload+'" class="upload_form" style="display:none;"><input name="image[]" size="30" type="file" /> <a href="javascript:;" onclick="javascript:ximage.remove_upload(\''+this.act_upload+'\');"><img src="./img/delete.png" border="0" /></a></div>\n');
			$('#upload_'+this.act_upload).fadeIn();
			this.act_upload++;
			$('#max_filesize').val(this.act_upload*3*1024*1024);
		} else {
			alert('Du kannst nur '+this.max_upload+' Bilder gleichzeitig hochladen!');
		}
	},

	remove_upload:function(id) {
		this.act_upload--;
		$('#max_filesize').val(this.act_upload*3*1024*1024);
		$('#upload_'+id).hide().remove();
	}
};

$(document).ready(function() {
	// $('#content').hide().fadeIn('normal');
	ximage.load();
	$('#add_more').click(function() { ximage.add_upload(); });
	$('#form').submit(function() {
		if($('#input_agb:checked').val() != 1) {
			alert('Du musst noch die AGBs akzeptieren!');
			return false;
		} else {
			$('#submit').attr("disabled", "disabled");
			$('#error').hide();

			var file_inputs = $('input[type=file]');
			if(file_inputs.length >= 1) {
				for(i = 0; i <= file_inputs.length; i++) {
					if(typeof file_inputs[i] != 'undefined' && file_inputs[i].value == '') {
						$('#upload_'+i).remove();
						this.act_upload--;
					}
				}
			} else {
				alert('ooops....');
				return false;
			}

			$('#upload_form').fadeOut('fast', function() {
				$('#please_wait').fadeIn();
			});
		}
	});
});
