var gbUpload = new Class({
	
	Implements: Options,
    options: {
		handleClass		: 'uploadwindow',
		openhandle		: 'uploadimg',
		nomorhandle		: 'no_more_uploads_box',
		editId			: false,
		maxImg			: 1
	},
	
	initialize: function(options){
		this.setOptions(options);
		if ($('no_js')){
			$('no_js').setStyle('display','none');
			$('formavatar').setStyle('display','');
		}
		if (this.options.editId){
			$(this.options.handleClass).setStyle('display','none');
			$(this.options.nomorhandle).setStyle('display','none');
			this.initContainer();
		}
	},
	
	initContainer: function (){
		this.bound = {};
		this.bound.byClick = this.byClick.bindWithEvent(this);
		$(this.options.openhandle).addEvent('click', this.bound.byClick);
		// nomore
		this.bound.nomorClick = this.nomorClick.bindWithEvent(this);
		$('no_more_uploads_ok').addEvent('click', this.bound.nomorClick);
	},
	
	byClick: function (event){
		if (edIt.options.imgAr.length+1 > this.options.maxImg){
			$(this.options.nomorhandle).setStyle('display','');
			return;
		}
		if (this.isDelOpen()){
			return;
		}
		$(this.options.handleClass).setStyle('display','');
	},
	
	isDelOpen: function (){
		if ($(this.options.handleClass).getStyle('display') == 'none'){
			return false;
		}
		return true;
	},
	
	nomorClick: function (){
		$(this.options.nomorhandle).setStyle('display','none');
	},
	
	hideSubmit: function (status){
		$(this.options.openhandle).setStyle('display',status);
	}
	
});
gbUpload.implement(new Options);

window.addEvent('domready', function(){
	if (typeof gbUploadOpt == 'undefined'){
		gbUploadOpt = {}; 
	}
	
	gbUpload = new gbUpload(gbUploadOpt);
});
