jQuery.fn.jqUploader=function(options){return this.each(function(index){var $this=jQuery(this);var $thisForm=$this.parents("form");var $thisInput=$("input[type='file']",$this);var $thisLabel=$("label",$this);var containerId=$this.attr("id")||'jqUploader-'+index;var startMessage=($thisLabel.text()=='')?'Please select a file':$thisLabel.text();var actionURL=$thisForm.attr("action");var prepender=(actionURL.lastIndexOf("?")!=-1)?"&":"?";actionURL=actionURL+prepender+'jqUploader=1';var maxFileSize=$("input[name='MAX_FILE_SIZE']",$(this.form)).val();var opts=jQuery.extend({width:320,height:85,version:8,background:'FFFFFF',src:'jqUploader.swf',uploadScript:actionURL,afterScript:null,varName:$thisInput.attr("name"),allowedExt:'*.jpg; *.jpeg; *.png',allowedExtDescr:'Images (*.jpg; *.jpeg; *.png)',params:{menu:false},flashvars:{},hideSubmit:true,barColor:'0000CC',maxFileSize:maxFileSize,startMessage:startMessage,errorSizeMessage:'File is too big!',validFileMessage:'now click Upload to proceed',progressMessage:'Please wait, uploading ',endMessage:'You\'re all done'},options||{});if(opts.hideSubmit==true){$("*[id='upload_submit']",this.form).hide();}
TerminateJQUploader=function(containerId,filename,varname){$this=$('#'+containerId).empty();$this.text('').append('<span style="color:#00CC00">Upload of <strong>'+filename+'</strong> finished!</span><input name="'+varname+'" type="hidden" id="'+varname+'" value="'+filename+'"/>');var myForm=$this.parents("form");myForm.submit(function(){return true});$("*[id='upload_submit']",myForm).show();}
var myParams='';for(var p in opts.params){myParams+=p+'='+opts.params[p]+',';}
myParams=myParams.substring(0,myParams.length-1);jQuery(this).flash({src:opts.src,width:opts.width,height:opts.height,id:'movie_player-'+index,bgcolor:'#'+opts.background,flashvars:{containerId:containerId,uploadScript:opts.uploadScript,afterScript:opts.afterScript,allowedExt:opts.allowedExt,allowedExtDescr:opts.allowedExtDescr,varName:opts.varName,barColor:opts.barColor,maxFileSize:opts.maxFileSize,startMessage:opts.startMessage,errorSizeMessage:opts.errorSizeMessage,validFileMessage:opts.validFileMessage,progressMessage:opts.progressMessage,endMessage:opts.endMessage},params:myParams},{version:opts.version,update:false},function(htmlOptions){var $el=$('<div id="'+containerId+'" class="flash-replaced"><div class="alt">'+this.innerHTML+'</div></div>');$el.prepend($.fn.flash.transform(htmlOptions));$('div.alt',$el).remove();$(this).after($el).remove();});});};