/**
* class Button
* 
*/
var Button = Class.create({
	initialize: function(parent, src, callBack) {

		this.id = '' + new Date().getTime() + Math.round(Math.random()*1000);
		this.parent = parent;
		this.src = src;
		this.callBack = callBack;
		
		this.wrapper = this.parent.appendChild($(Builder.node('div',{id:'bw_' + this.id}))); // to position absolute
		this.wrapper.absolutize();
		this.wrapper.setStyle({
			'left':'0px',
			'top':'0px'
		});
		this.link = this.wrapper.appendChild($(Builder.node('a',{href: '#' })));
		this.image = new Image();
		this.image = $(this.image);
		this.image.src = src;
		this.image.setStyle({
			'border':'0'
		});
		this.link.setStyle({
			'width': this.image.width + 'px',
			'height': this.image.height + 'px',
			'display':'block'
		});
		this.link.appendChild(this.image);
		this.link.setStyle({
			'display':'block'
		});
			
		Event.observe(this.link,"click",this.callBack);
		//Event.observe(this.image, "load",this.init);
	},
	
	show: function() {
		this.image.show();
	},
	
	hide: function() {
		this.image.hide();
	},

	getWidth: function() {
		return this.image.getWidth();
	},
	
	getHeight: function() {
		return this.image.getHeight();
	},
	
	setSize: function(w, h) {
		// find smallest factor
		var factW = w/this.image.getWidth();
		var factH = h/this.image.getHeight();
		var factor = factW>factH?factH:factW;
		if (factor<1) {
			this.wrapper.setStyle({
				'width': (this.image.width * factor) + 'px',
				'height': (this.image.height * factor) + 'px'});
			this.image.setStyle({
				'width': (this.image.width * factor) + 'px',
				'height': (this.image.height * factor) + 'px'});
		}
	},
	
	setPosition: function(x, y) {
		this.wrapper.setStyle({
			'left':x + 'px',
			'top':y + 'px'
		});
	}
});
