Element.extend
({
 fit: function(direction)
 {
 var bounds = this.parentNode.getSize();

 this.setStyles
 ({
 'height': 'auto',
 'width': 'auto'
 });

 switch (direction)
 {
 case 'horizontal':
 this.setStyle('height', bounds.size.y + 'px');
 break;
 case 'vertical':
 this.setStyle('height', bounds.size.x + 'px');
 break;
 default:
 var size = this.getSize();
 if (size.size.x / bounds.size.x > size.size.y / bounds.size.y)
 {
 if (size.size.x < bounds.size.x) return;
 this.setStyle('width', bounds.size.x + 'px');
 }
 else if (!(size.size.y < bounds.size.y)) this.setStyle('height', bounds.size.y + 'px');
 break;
 }
 },

 center: function()
 {
 this.setStyle('margin', '0px');

 this.fit();

 var bounds = this.parentNode.getSize();

 if (this.parentNode.getStyle('position') == 'static') this.parentNode.setStyle('position', 'relative');

 this.setStyles
 ({
 'position': 'absolute',
 'top': Math.floor((bounds.size.y - this.getSize().size.y) / 2) + 'px',
 'left': Math.floor((bounds.size.x - this.getSize().size.x) / 2) + 'px'
 });
 }
});

Number.extend
({
 toComma: function(prepend)
 {
 var str = this.toString().split('.');
 var rgx = /(\d+)(\d{3})/;
 while (rgx.test(str[0])) str[0] = str[0].replace(rgx, '$1' + ',' + '$2');

 if (str.length > 1) return prepend + str[0] + '.' + str[1];
 return prepend + str[0];
 }
});

Element.extend
({
 fireChange: function()
 {

 if (window.ie) this.fireEvent('change');
 else
 {
 var event = document.createEvent("HTMLEvents");
 event.initEvent('change', false, false);
 this.dispatchEvent(event);
 }

 return this;
 }
});