/*
 * Gx.Button
 */

Gx.Button = new Class({
	Extends: Gx.Widget,
	initialize: function(container, options) {
		this.parent(container, options);

		// Get button label
		this.label = this.container.get('text');
		
		// Go back button unselectable
		this.container.diselected();

		// Off the Menu button right
		this.container.addEvent('contextmenu', function(event) { event.stop(); });

		// For return html dom node element with all properties
		return $extend(this.container, this);
	},
	setWidth: function(width) {
		this.container.setStyle('width', width);
		return this;
	},
	setLabel: function(text) {
		this.container.set('text', text);
		this.label = text;
		return this;
	},
	getLabel: function() {
		return this.label;
	}
});

/*
 * Gx.Button.Simple
 */

Gx.Button.Simple = new Class({
	Extends: Gx.Button,
	initialize: function(container, options) {
		this.parent(container, options);

		// Delete text
		this.container.empty();

		// Building the structure of the HTML button
		this.container.adopt(
			new Element('span', {'class': 'left'}),
			new Element('span', {'class': 'gx middle', 'text': this.label}),
			new Element('span', {'class': 'right'})
		);

		// 
		// console.log('create label ....');
		//this.label = new Gx.Label(this.container.getElement('span.gx.middle'));

		// Show button and initialize the box
		// console.log('create HBox ....');
		//this.box = new Gx.HBox(this.container.setBlock());
		
		return $extend(this.container, this);
	},
	//resize: function() {
	//	this.box.resize();
	//},
	setWidth: function(width) {
		//if (width < (min = this.container.getStyle('min-width').toInt()))
		//	width = min;
	
		this.container.setStyle('width', width);
		//this.box.resize();
		//this.setRangeVThree(width);
		return this;
	},
	setLabel: function(text) {
		this.container.getElement('span.middle').set('text', text);
		this.label = text;
		return this;
	}
});

/*
 * Gx.Button.Toggle
 */

Gx.Button.Toggle = new Class({
	Extends: Gx.Button,
	initialize: function(container, options) {
		this.parent(container, options);

		return $extend(this.container, this);
	}
});

/*
 * Gx.Button.Fade
 */

Gx.Button.Fade = new Class({
	Extends: Gx.Button,
	options: {
		duration: 600
	},	
	initialize: function(container, options) {
		this.setOptions(options);
		this.parent(container, options);
		this.mask = new Element('div', {'class': 'mask'}).inject(this.container);
		
		// Clone click event
		this.mask.addEvent('click', (function() {
			this.container.fireEvent('click');
		}).bind(this));
		
		this.fx = new Fx.Tween(this.mask, {
			duration: this.options.duration,
			link: 'cancel'
		});
		
		this.container.addEvents({
			'mouseenter': this.mouseenter.bind(this),
			'mouseleave': this.mouseleave.bind(this)
		});

		// For return html dom node element with all properties
		return $extend(this.container, this);
	},
	mouseenter: function() {
		if (Browser.Engine.trident && Browser.Engine.version <= 6)
			this.mask.setOpacity(0);
		else	
			this.fx.start('opacity', 0);
	},
	mouseleave: function() {
		if (Browser.Engine.trident && Browser.Engine.version <= 6)
			this.mask.setOpacity(1);
		else
			this.fx.start('opacity', 1);
	}
});

/*
 * Gx.Button.Checkbox
 */

Gx.Button.Checkbox = new Class({
	Extends: Gx.Button,
	options: {
		duration: 200
	},	
	initialize: function(container, options) {
		this.parent(container, options);

		// Delete text
		this.container.empty();

		// Create seen element
		this.seen = new Element('span', {'class': 'seen'}).inject(this.container);

		// Create label element
		new Element('span', {'class': 'label', 'text': this.label}).inject(this.container);
		
		// Add keyup event for check or uncheck
		//this.container.addEvent('keyup', this.keyup.bindWithEvent(this));
		
		// Seen effect
		this.fx = new Fx.Tween(this.seen, {
			duration: this.options.duration,
			link: 'ignore'
		});

		// For return html dom node element with all properties
		return $extend(this.container, this);
	},
	setValue: function(value) {
		if (!value)
			return this;
	
		if (value.toInt() == 1)
			this.checked()
		else
			this.unchecked()
		
		return this;
	},
	getValue: function() {
		return (this.seen.getStyle('display') == 'none') ? 0 : 1;
	},
	//keyup: function(event) {
		//if (event.key != 'enter')
		//	return;
		//this.toggle();
	//},
	checked: function() {
		if (Browser.Engine.trident) {
			this.seen.setOpacity(1).setBlock();
		} else {
			this.seen.setOpacity(0).setBlock();
			this.fx.start('opacity', '1');
		}
	
		return this;
	},
	unchecked: function() {
		if (Browser.Engine.trident) {
			this.seen.setNone();	
		} else {
			this.fx.start('opacity', '0').chain((function() {
				this.seen.setNone();
			}).bind(this));
		}

		return this;
	},
	toggle: function() {
		(this.seen.getStyle('display') == 'none') ? this.checked() : this.unchecked();
		return this;
	},
	mouseup: function(event) {
		this.toggle();
		this.parent(event);
	}
});

/*
 * Gx.Button.Step
 */

/*
Gx.Button.Step = new Class({
	Extends: Button,
	options: {
		duration: 200,
		selected: 0
	},	
	initialize: function(container, options) {
		this.parent(container, options);

		this.start = true;
		this.index = null;
		
		this.fx = new Fx.Tween(this.label, {link: 'ignore'});
		this.label = container.getElements('div').diselected();

		if (this.label.length != 0 && this.options.selected != null)
			this.select(this.options.selected);
		
		return $extend(this.container, this);
	},
	select: function(index) {
		if ($type(index) == 'string') {
			switch(index) {
				case 'preview':	index = this.index - 1;	break;
				case 'next':	index = this.index + 1;	break;
			}
		}

		if (index < 0 || index >= this.label.length || index == this.index)
			return;
		
		this.label.setNone();
		var size = this.label[index].getCharacterSize();
		
		if (this.start) {
			this.fx.element.setStyle('width', size.x);
			this.label[index].setBlock();
			this.start = false;
			this.index = index;
			return;
		}
		
		this.fx.options.duration = this.options.duration;
		this.fx.start('width', size.x).chain((function () {
			this.index = index;
			this.label[index].setBlock();
			
			//if (this.options.href && index == this.label.length - 1)
				//this.container.set('href', this.options.href);
			
		}).bind(this));
		return this;
	}	
});
*/