var gbPopup = new Class({
	
	Implements: Options,
    options: {
		// container
		handleClass		: 'submituser',
		popupcontainer	: 'gbpopup',
		btnsubmit		: 'ok',
		btncancel		: 'cancel',
		formhandle		: 'form',
		textarea		: 'slogantxt',
		popup			: false
	},
	
	initialize: function(options){
		this.setOptions(options);
		if (this.options.popup){
			$(this.options.popupcontainer).setStyle('display','none');
			this.initContainer();
		}
		
	},
	
	initContainer: function (){
		this.bound = {};
		// container
		totalContainer = $$('.'+this.options.handleClass);
		totalContainer.each(function(el){
			this.bound.byClick = this.byClick.bindWithEvent(this, el);
			el.addEvent('click', this.bound.byClick);
			/*
			this.bound.byOver = this.byOver.bindWithEvent(this);
			el.addEvent('mouseover', this.bound.byOver);
			this.bound.byOut = this.byOut.bindWithEvent(this);
			el.addEvent('mouseout', this.bound.byOut);
			this.reSet(el);
			*/
		},this);
		// del
		this.bound.bySubmit = this.bySubmit.bindWithEvent(this);
		$(this.options.btnsubmit).addEvent('click', this.bound.bySubmit);
		this.bound.byCancel = this.byCancel.bindWithEvent(this);
		$(this.options.btncancel).addEvent('click', this.bound.byCancel);
	},
	
	getEl: function (event){
		el = $(event.target);
		if (el.className != this.options.handleClass){
			while (el.className != this.options.handleClass) {
				el = el.getParent();
			}
		}
		return el;
	},
	
	byClick: function (event){
		$(this.options.popupcontainer).setStyle('display','');
		return false;
	},
	
	bySubmit: function (event){
		if ($(this.options.textarea).get('html').length > 0){
			$(this.options.formhandle).submit();
		}
	},
	
	byCancel: function (event){
		$(this.options.popupcontainer).setStyle('display','none');
	},
	
	reSet: function (el){
		el.setStyles({
			'border': '1px solid '+this.options.container_n,
			'cursor': 'auto'
		});
		el.getElement('div.'+this.options.textcontainer).setStyle('color', this.options.textcolor_n);
	},
	
	refreshTo: function (id){
		url = this.options.refreshto.split(this.options.urlprefix);
		url = url[0]+'/edit'+id+this.options.urlprefix;
		window.location.href = url;
	},
	
	isDelOpen: function (){
		if ($(this.options.delcontainer).getStyle('display') == 'none'){
			return false;
		}
		return true;
	}
	
});
gbPopup.implement(new Options);

window.addEvent('domready', function(){
	if (typeof gbpopupopt == 'undefined'){
		gbpopupopt = {}; 
	}
	
	gbPopup = new gbPopup(gbpopupopt);
});
