/**
 *  Signature-IT's jQuery plugins.
 *  Please extend it as you wish.
 *  @Author Valery Kotlarov
 */
jQuery.fn.extend({

    /**
         *  Calculate and return string's width based on it's container. Takes into consideration font, text  and other CSS properties.
         *  Usage: jQuery('#some_selector').textWidth()
         */
    textWidth: function() {

        if (this.length != 1) {
            return 0;
        }
        else {
            // Add the container here as sibling to have all the CSS font and text properties inherited
            jQuery(this).append('<span id="widthCalculator"></span>');
            // Ensure it doesn't break the HTML
            var wc = jQuery('#widthCalculator').css({position: "absolute", visibility: "hidden", height: "auto", width: "auto"});
            // Get width
            var wc_width = wc.text(jQuery(this).text()).width();
            // And remove it from the document
            jQuery('#widthCalculator').remove();
            // subtract left and right borders
            return wc_width - 2;
        }
    }

    /**
     *  Add your plugin here...
     */
});
