// Put ourselves into a jQuery function to define some price helpers
(function($) {

	// Add caps for visual effect
	$.capify = function(value) {
		return value.replace(/([A-Z])/g, "<span class='cap'>$1</span>");
	};

	// Convert form currency to a float
	$.floatFromCurrency = function(value) {
		if ( value != null && value != "") {
			return parseFloat((value + '').replace(",", ""));
		}
		else {
			return 0;
		}
	};

	// This will add commas to the given field
	$.toCurrency = function(value, options) {
	
		// If it's undefined, don't go futher
		if ( value != undefined ) {
		
			// Make the value a string
			var stringifiedValue = value + '';
		
			// Don't proceed if no this 
			if ( stringifiedValue ) {
		
				// Add the decimal if requested
				var modifiedValue = stringifiedValue;
				if ( options && options["forceDecimals"] == true ) {
					modifiedValue = parseFloat(stringifiedValue.replace(",", "")).toFixed(2);
				}
		
				// Update the string to add commas
				var text = modifiedValue + '';
				x = text.split('.');
				x1 = x[0];
				x2 = x.length > 1 ? '.' + x[1] : '';
				var rgx = /(\d+)(\d{3})/;
				while (rgx.test(x1)) {
					x1 = x1.replace(rgx, '$1' + ',' + '$2');
				}
		
				// This is our result with commas
				return x1 + x2;
			}
		}
		return null;
		
	};
	
	// jQuery.support.transition
	// to verify that CSS3 transition is supported (or any of its browser-specific implementations)
	$.support.transition = (function(){ 
	    var thisBody = document.body || document.documentElement,
	    thisStyle = thisBody.style,
	    webkitSupport = thisStyle.WebkitTransition !== undefined;
	    anySupport = thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.OTransition !== undefined || thisStyle.transition !== undefined;
	    return webkitSupport; 
	})();

})(jQuery);

