/**
 * @package		VisionCMS
 * @subpackage	View
 * @copyright	Copyright (c) 2008-2009, Timothy de Paris, New Brand Vision.
 */

(function($){

	/**
	 * Replaces the specified heading elements with inline image replacements.
	 *
	 * @return	void
	 * @since	5.6.2
	 */
	$.fn.hreplace = function() {

		// Convert headings to images.
		$(this).each(function() {

			// Determine CSS font properties.
			var font = $(this).css('font-family').split(',')[0].replace(/['"]/g, '');
			var fontSize = $(this).css('font-size').replace(/[^0-9]*/g, '');
			var colour = document.getStyleValue($(this).get(0), 'color');
			var backgroundColour = document.getStyleValue($(this).get(0), 'background-color');
			var headingText = $(this).text().replace(/\xA0/, ' ').trim();
			
			// Transform text if required.
			switch ($(this).css('text-transform')) {
				case 'uppercase':
					headingText = headingText.toUpperCase();
					break;
				case 'lowercase':
					headingText = headingText.toLowerCase();
					break;
			}

			// Replace the text.
			if (headingText) {
				$(this).html('<img src="' + _includeUrl + 'hreplace/hreplace.php?text=' + escape(headingText) + '&font=' + escape(font) + '&fontSize=' + fontSize + '&colour=' + escape(colour) + '&backgroundColour=' + escape(backgroundColour) + '" alt="' + headingText + '" />')
			}

		});

	} // end function hreplace.

})(jQuery);