jQuery.fn.dropload = function(theurl){
  //i = randomid;
  
  return this.each(function(){
	 //this.loc = theurl;
    /* Display uploaded files. */
    $(this)
        .get(0)
        .addEventListener('drop', upload, false);
    $(this)
        .get(0)
        .addEventListener('dragenter', function(event) {
                $(this).css("background-color", "#ffc");
            }, false);
    $(this)
        .get(0)
        .addEventListener('dragexit', function(event) {
                $(this).css("background-color", "");
            }, false);
    $(this)
        .get(0)
        .addEventListener('dragover', function(event) {
                event.preventDefault();
            }, false);
    //myid = $(this).arrt('id');
	 //var othervar = 'got one';
	 //alert(myid);
    function upload(event) {
        //alert($(this).arrt('id'));
        var data = event.dataTransfer;

        /* Show spinner for each dropped file. */
        for (var i = 0; i < data.files.length; i++) {
            //$(this).append('uploaded');
        }
        
        var boundary = '------multipartformboundary' + (new Date).getTime();
        var dashdash = '--';
        var crlf = '\r\n';

        /* Build RFC2388 string. */
        var builder = '';

        builder += dashdash;
        builder += boundary;
        builder += crlf;
        
        var xhr = new XMLHttpRequest()
        
        for (var i = 0; i < data.files.length; i++) {
            var file = data.files[i];

            /* Generate headers. */
            builder += 'Content-Disposition: form-data; name="user_file[]"';
            if (file.fileName) {
              builder += '; filename="' + file.fileName + '"';
            }
            builder += crlf;

            builder += 'Content-Type: application/octet-stream';
            builder += crlf;
            builder += crlf;

            /* Append binary data. */
            builder += file.getAsBinary();
            builder += crlf;

            /* Write boundary. */
            builder += dashdash;
            builder += boundary;
            builder += crlf;
        }
        
        /* Mark end of the request. */
        builder += dashdash;
        builder += boundary;
        builder += dashdash;
        builder += crlf;
			//alert(theurl);
        xhr.open("POST", theurl, true);
        xhr.setRequestHeader('content-type', 'multipart/form-data; boundary=' + boundary);
        xhr.sendAsBinary(builder);
        
        xhr.onload = function(event) {
            /* If we got an error display it. */
            if (xhr.responseText) {
                //alert(xhr.responseText);
					 //$(this).append(xhr.responseText);
					 //alert('did it');
					 $("#dropzone").append(xhr.responseText);
					 //alert(othervar);
            }
				//$("#dropzone").append("yeah");
            //$("#dropzone").load("list.php?random=" + (new Date).getTime());
        };
        
        /* Prevent FireFox opening the dragged file. */
        event.stopPropagation();
        
    }

  });
};
