var uploader = function(upload_file, height, width, page_id, swf_id, swf_version, server, processor, callbacks){
	this.random_id = Math.round(10000000000 * Math.random());
	this.processor = processor;
	this.swf_version = swf_version;
	this.swf_id = swf_id;
	this.upload_file = upload_file;
	this.height = height;
	this.width = width;
	this.page_id = page_id;
	this.server = server+"?uuid="+this.random_id;
	this.uid = new Date().getTime();
	this.proxy = 0;
	this.callbacks = callbacks;
	this.inter = 0;
	this.init();
}

uploader.prototype.start_bytes = function(){
	var home = this;	
	this.inter = setInterval(function(){
		home.on_progress(home.get_bytes());
	}, 3000);
}

uploader.prototype.stop_bytes = function(){
	clearInterval(this.inter);
}

uploader.prototype.init = function(){
	this.proxy = new ext_int(this.swf_id, this);
	this.create_tag();
}

uploader.prototype.create_tag = function(){
	this.swfo = new SWFObject(this.upload_file, this.swf_id, this.width, this.height, this.swf_version, "FFFFFF");
	this.swfo.useExpressInstall('/swf/expressinstall.swf');
	this.swfo.addVariable('ext_id', this.swf_id);
	this.swfo.addVariable('server_url', this.server);
	this.swfo.addVariable('processor', this.processor);
	this.swfo.addVariable('uuid', this.random_id);
    this.swfo.write(this.page_id);
    this.obj = document.getElementById(this.swf_id);
}


uploader.prototype.upload = function(){
	this.obj.start_upload('lala');
}

uploader.prototype.browse = function(){
	this.obj.browse();
}

uploader.prototype.cancel = function(){
	this.obj.cancel_upload();
}

uploader.prototype.get_bytes = function(){
	return this.obj.get_bytes();
}

uploader.prototype.is_uploading = function(){
	return this.obj.is_uploading();
}

uploader.prototype.on_flash_load = function(){
	if(this.callbacks['on_flash_load'])  this.callbacks['on_flash_load']();
}

uploader.prototype.leopard_error = function(){
	if(this.callbacks['leopard_error'])  this.callbacks['leopard_error']();
}

uploader.prototype.on_progress = function(obj){
	if(this.callbacks['on_progress'])  this.callbacks['on_progress'](obj);
}

uploader.prototype.on_upload = function(){
	this.start_bytes();
	if(this.callbacks['on_upload'])  this.callbacks['on_upload']();
}

uploader.prototype.on_cancel = function(file_ref){
	this.stop_bytes();
	if(this.callbacks['on_cancel'])  this.callbacks['on_cancel'](file_ref);
}

uploader.prototype.upload_done = function(obj){
	this.stop_bytes();
	if(this.callbacks['upload_done'])  this.callbacks['upload_done'](obj);
}
	
uploader.prototype.file_selected = function(obj){
	if(this.callbacks['file_selected']) this.callbacks['file_selected'](obj);
}
	
uploader.prototype.io_error = function(obj){
	if(this.callbacks['io_error']) this.callbacks['io_error'](obj);
}
	
uploader.prototype.http_error = function(obj, error){
	if(this.callbacks['http_error']) this.callbacks['http_error'](obj, error);
}
	
uploader.prototype.security_error = function(obj, error){
	if(this.callbacks['security_error']) this.callbacks['security_error'](obj);
}

uploader.prototype.transfer_done = function(obj){
	if(this.callbacks['transfer_done']) this.callbacks['transfer_done'](obj);
}
