// Custom jQuery extensions
// (c) 2008 Computer Business Services, Inc.

jQuery.fn.extend({
	// Format string as price (0.00)
	priceFormat: function() {
		var p = new Number(parseFloat(this.val()));
		var maxPrice = 9999999.99; // +/-$10M should be about enough :)
		var minPrice = -9999999.99;
		if (isNaN(p.valueOf()))  p = 0;
		if (p.valueOf() > maxPrice)  p = maxPrice;
		else if (p.valueOf() < minPrice)  p = minPrice;
		this.val(p.toFixed(2));
		return this;
	},

	// Place an absolutely positioned element in the center of the viewport
	centerScreen: function() {
		return this.css('left', (($('body').width() - this.width()) / 2) + 'px')
			.css('top', (($(window).height() - this.height()) / 2 + $(window).scrollTop())+ 'px');
	},

	// Toggle attribute based on the value of 'on'
	switchAttr: function(a, on, valOn, valOff) {
		if (on)  this.attr(a, valOn);
		else if (valOff)  this.attr(a, valOff);
		else  this.removeAttr(a);
		return this;
	}
});

