// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


// FLASH

function insertFlashComponent(flashurl,width,height,vars) {
	 var tag = new FlashTag(flashurl, width, height); // last two arguments are height and width
	 tag.setFlashvars(vars);
	 tag.write(document);
}


// SWFUPLOAD

function launch_swfupload(submit_url, a_refresh_url, authenticity_token)
{
	// refresh_url = a_refresh_url;
	// swfu = new SWFUpload({
	// 	upload_script : submit_url,
	// 	target : "SWFUploadTarget",
	// 	flash_path : "/swf/SWFUpload.swf?"+Math.random(),
	// 	allowed_filesize : 30720,	// 30 MB
	// 	allowed_filetypes : "*.*",
	// 	allowed_filetypes_description : "All files...",
	// 	browse_link_innerhtml : "Ajouter... ",
	// 	upload_link_innerhtml : "Upload",
	// 	browse_link_class : "swfuploadbtn browsebtn",
	// 	upload_link_class : "swfuploadbtn uploadbtn",
	// 	flash_loaded_callback : 'swfu.flashLoaded',
	// 	upload_file_queued_callback : "fileQueued",
	// 	upload_file_start_callback : 'uploadFileStart',
	// 	upload_progress_callback : 'uploadProgress',
	// 	upload_file_complete_callback : 'uploadFileComplete',
	// 	upload_file_cancel_callback : 'uploadFileCancelled',
	// 	upload_queue_complete_callback : 'uploadQueueComplete',
	// 	upload_error_callback : 'uploadError',
	// 	upload_cancel_callback : 'uploadCancel',
	// 	auto_upload : false			
	// });
  swfu = new SWFUpload({
		upload_url : submit_url,
		flash_url : "/swf/swfupload.swf?"+Math.random(),
		use_query_string : false,

		// Button settings
		button_image_url: "/images/images_admin/SmallSpyGlassWithTransperancy_17x18.png",  // Relative to the Flash file
		button_width: "300",
		button_height: "18",
		button_placeholder_id: "spanButtonPlaceHolder",
		button_text: '<span class="button">Sélectionner photo(s) <span class="buttonSmall">(1 Mo max chacune)</span></span>',
		button_text_style: ".button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }",
		button_text_left_padding: 18,
		button_text_top_padding: 3,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		
		file_size_limit : '1024',	// 1 MB
		file_types : '*.jpg',
		file_types_description : 'JPG Images',
		file_upload_limit : '0',
		
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		file_dialog_start_handler : fileDialogStart,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		
		// post_params : {
		  // authenticity_token : authenticity_token
		// },
		
		custom_settings : {
		  upload_target : 'divFileProgressContainer',
		  progressTarget : "fsUploadProgress",
			refresh_ajax_url : a_refresh_url
		},
		
		debug: false

		});	
}

var swfu; 
var refresh_url;	


// Function that sets a sibbling field (that has the given class) to value 1.
// It then hides the container of the given element.
function mark_for_destroy(element, destroy_field, parent_class) { 
  $(element).up('.'+parent_class).down('.'+destroy_field).value = 1 
  $(element).up('.'+parent_class).hide(); 
}