window.addEvent('domready',function(){
	SqueezeBox.assign($$('a.sube_archivo'), {
		parse: 'rel'
	});
	
	if ($('uploads_form')){
		var swiffy = new FancyUpload2($('uploads_status'), $('uploads_list'), {
			instantStart: false,
			url: $('uploads_form').action,
			fieldName: 'file',
			path: '/commons/swf/Swiff.Uploader.swf',
			limitSize: 2 * 1024 * 1024, // 2Mb
			onLoad: function() {
				$('uploads_status').removeClass('hide');
				if ($('uploads_fallback')) $('uploads_fallback').destroy();
			},
			// The changed parts!
			debug: true, // enable logs, uses console.log
			target: 'uploads_browse' // the element for the overlay (Flash 10 only)
		});
	 
		/**
		 * Various interactions
		 */
	 
		$('uploads_browse').addEvent('click', function() {
			/**
			 * Doesn't work anymore with Flash 10: swiffy.browse();
			 * FancyUpload moves the Flash movie as overlay over the link.
			 * (see opeion "target" above)
			 */
			swiffy.browse();
			return false;
		});
	 
		/**
		 * The *NEW* way to set the typeFilter, since Flash 10 does not call
		 * swiffy.browse(), we need to change the type manually before the browse-click.
		 */
		$('uploads_filter').addEvent('change', function() {
			var filter = null;
			if (this.checked) {
				switch (this.get('class')){
					case 'video':
						filter = {'Videos (*.mp4, *.flv, *.avi, *.mpg)': '*.mp4; *.flv; *.avi; *.mpg'};
					break;
					case 'imagen':
						filter = {'Imagenes (*.jpg, *.jpeg, *.gif, *.png)': '*.jpg; *.jpeg; *.gif; *.png'};
					break;
				}
				
			}
			swiffy.options.typeFilter = filter;
		});
	 
		$('uploads_clear').addEvent('click', function() {
			swiffy.removeFile();
			return false;
		});
	 
		$('uploads_go').addEvent('click', function() {
			swiffy.upload();
			return false;
		});
	}

});