
// wait for the DOM to be loaded
$(document).ready(function() {

	$("#uploadify").uploadify({
				'uploader' : 'scripts/uploadify.swf',
				'script' : 'scripts/upload.php',
				'scriptData' : {
					'title' : 'TITLE',
					'comment' : 'COMMENT',
					'challenge' : 'C',
					'response' : 'R'
				},
				'cancelImg' : 'images/cancel.png',
				'folder' : 'uploads',
				'queueID' : 'fileQueue',
				'auto' : false,
				'multi' : false,
				'method' : 'GET',
				'buttonText' : 'Durchsuchen...',
				'height' : 30,
				'width' : 120,
				'sizeLimit' : 1024 * 1024,
				'fileExt' : '*.jpg;*.jpeg;*.gif;*.png',
				'fileDesc' : 'jpg, gif, png',
				'onAllComplete' : function(event, data) {
					var errors = data['errors'];
					if (errors == 0) {
						$('#divToUpdate').text("Deine Birne ist angekommen.");
						$('#divToUpdate').fadeIn(5);
					} else {
						$('#divToUpdate')
								.text("Es ist ein Fehler aufgetreten.");
					}
				}
			});

	Recaptcha.create("6LetYgkAAAAAALxS292b3Ixa-rT8HUubryzCXnDU",
			'dynamic_recaptcha_1', {
				theme : 'white',
				lang : 'de',
				callback : Recaptcha.focus_response_field
			});

	$('#submit').click(function() {

				var $challenge = Recaptcha.get_challenge();
				var $response = Recaptcha.get_response();

				var value = $('#RightsCheck').fieldValue();
				if (value.length == 0) {
					alert('Please accept the user rights.');
					return false;
				} else {

					var title = $('#commenttitle').fieldValue()[0];
					var comment = $('#comment').fieldValue()[0];	

					$('#uploadify').uploadifySettings('scriptData', {
								'title' : title,
								'comment' : comment,
								'challenge' : $challenge,
								'response' : $response
							});
					$('#divToUpdate').text('');
					$('#uploadify').uploadifyUpload();
				}

			});

});

