var swfu;
swfuploadInit = function() {
		var settings = {
			flash_url : "form/swf/swfupload.swf",
			upload_url: "upload.php",
			file_post_name: "attachment",			
			post_params: {"SID" : sid},
			file_size_limit : "100 MB",
			file_types : "*.*",
			file_types_description : "All Files",
			file_upload_limit : 100,
			file_queue_limit : 0,
			custom_settings : {
				progressTarget : "form-kontakt-uploadProgress"
			},
			debug: false,

			// Button settings
			button_width: "43",
			button_height: "18",
			button_image_url : "lay-gfx/bg-dodaj.jpg",
			button_placeholder_id: "spanButtonPlaceHolder",
			button_text_left_padding: 12,
			button_text_top_padding: 3,
			
			// The event handler functions are defined in handlers.js
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			upload_complete_handler : uploadComplete,
			queue_complete_handler : queueComplete	// Queue plugin event
		};

		swfu = new SWFUpload(settings);
		$( '#form-kontakt-submit' ).click( function(){
			submitAndStartUpload();
			return false;
		} );
};	
	
/**
 * Rozpoczęcie wysyłania
 */
submitAndStartUpload = function(){
	//pokazanie statusu
	if( swfu.getStats().files_queued > 0 ){
		$('#form-kontakt-submit').attr( 'disabled' , true );	
		swfu.startUpload();
	}else{
		$('#form-kontakt').submit();
	}
};
/**
 * Akcje wykonywane po wysłaniu plików 
 */
submitAndAfterUpload = function( success ){
	$('#form-kontakt-uploadProgress_container' ).removeClass( 'extended' );
	if( success ){
		$('#form-kontakt-uploadProgress_message' ).html( 'Wszystkie pliki zostały poprawnie wysłane. Za chwilę nastąpi wysłanie wiadomości. Dziękujemy za cierpliwość.' );
		setTimeout( function(){
			
			$('#form-kontakt-uploadProgress_message' ).fadeOut( 'slow' , function(){$('#form-kontakt').submit();} );
		} , 1500 );	
		
	}else{
		$('#form-kontakt-uploadProgress_message' ).html( 'Podczas wysyłania plików wystąpił błąd. Prosimy spróbować ponownie.' );
	}
	$('#form-kontakt-uploadProgress_message' ).slideDown();
	
};

updateProgressInfo = function( uploaded , queueSize ){
	if( uploaded == queueSize ){
		$( '#form-kontakt-uploadProgress_info' ).html( '<h1>Wysłano wszystkie pliki</h1>' );
	}else{
		$( '#form-kontakt-uploadProgress_info' ).html( '<h1>Wysłano ' + uploaded + ' z ' + queueSize + ' plików</h1>' );
	}
};
