(function($) {

$.widget("ui.ajaxForm",
{  
// PUBLIC
	_init: function() {
	var self = this; var id = getUID(); var o = this.options;
	
		$(this.element).attr('target', id);
		$(this.element).bind('submit', function() {
			//alert('TEST');
			//o.onSubmit(_file, _ext);
			return false;
		});
		var _holder = $(this.element).parent();
		
	
		// CREATE FRAME
		var _frame = $('<iframe name="' + id + '" id="' + id + '" src="javascript:false;"></iframe>').css('display', 'none');
			_holder.append(_frame);
		/*	
	// INPUT
		var _input = $('<input type="file" name="upload[file]"/>');
		_input.change(function() {
			var _file = this.value.replace(/.*(\/|\\)/, "");
				_file = _file.toLowerCase();
			var _ext = (-1 !== _file.indexOf('.')) ? _file.replace(/.*[.]/, '') : '';			
		// CHANGE ALERT
			o.onChange(_file, _ext);
			
		// AUTO SUBMIT
            
		});
		_input.appendTo($(this.element));
		*/
	}
});
/*
$.extend($.ui.ajaxForm, {
	version: "1.0.0",
	getter: "value",
	defaults: {
		url: "", // radio|select
		form: '',
		onSubmit: function () {}
	}
});
*/
})(jQuery);

/*
(function($) {
	$.fn.ajaxForm = function (options) {
		$.fn.ajaxForm.defaults = {
			action: '',
			autoSubmit: false,
			onChange: function (_element, _file, _extension) {
				
			}
		};
		var opts = $.extend($.fn.ajaxForm.defaults, options);

		return this.each(function () {
			var id = getUID();
			
			var _div = $("<div></div>");
			
		// CREATE FRAME
			var _frame = $('<iframe name="' + id + '" id="' + id + '" src="javascript:false;"></iframe>').css('display', 'none');
				_frame.appendTo($(this));
				
		// CREATE FORM
			var _form = $('<form action="' + opts.action + '" target="' + id + '" method="post" enctype="multipart/form-data"></form>').css('display', 'none');
				_form.appendTo($(this));
			
			for (var prop in opts.data) {
                if (settings.data.hasOwnProperty(prop)){
                    var el = document.createElement("input");
                    el.setAttribute('type', 'hidden');
                    el.setAttribute('name', prop);
                    el.setAttribute('value', settings.data[prop]);
                    form.appendChild(el);
                }
            }
			
		// CREATE INPUT
			var _input = $('<input type="file" name="upload[file]"/>');
				_input.change(function() {
					var _file = this.value.replace(/.*(\/|\\)/, "");
						_file = _file.toLowerCase();
					var _ext = (-1 !== _file.indexOf('.')) ? _file.replace(/.*[.]/, '') : '';
					// CHANGE ALERT
					if (false === opts.onChange(this, file, getExt(file))){
	                    //self._clearInput();
	                    return;
	                }
					// AUTO SUBMIT
	                if (opts.autoSubmit) {
	                    //self.submit();
	                }
				});
			_input.appendTo($(this));
		});
	};
})(jQuery);
*/
