(function($){
    $.fn.tcToggleInputVal = function(){
        var baseVal = this.val();

        this.focus(function(){
            if($(this).val() == baseVal)
                $(this).val('');
        });
        
        this.blur(function(){
            if($(this).val() == "")
                $(this).val(baseVal);
        });
    };
    
    $.fn.tcSlideInput = function(width, toggleChildren){
        var toggleElem;
        if (!toggleChildren.length)
            toggleElem = $(this);
        else
            toggleElem = $(this).children(toggleChildren);
        
        var baseWidth = toggleElem.width();
        
        toggleElem.click(function(){
            var w = width + "px";
            toggleElem.animate({width: w}, 500);
        });
        
        toggleElem.blur(function(){
            var w;
            toggleElem.parent().append('<span id="toggle-elem-temp-span" style="position: absolute; left: -999999px;">'+toggleElem.val()+'</span>');
            var toggleElemTxtWidth = $("#toggle-elem-temp-span").width()+3;
            
            if (toggleElemTxtWidth > baseWidth && toggleElemTxtWidth < width) {
                w = toggleElemTxtWidth + 'px';
            }
            else if (toggleElemTxtWidth > width) {
                w = width + 'px';
            }
            else {
                w = baseWidth + 'px';
            }
            toggleElem.stop().animate({width: w}, 500);
            $("#toggle-elem-temp-span").remove();
        });
    };
    
    $.fn.tcTextWidth = function(){
        var html_org = $(this).html();
        var html_calc = '<span>' + html_org + '</span>'
        $(this).html(html_calc);
        var width = $(this).find('span:first').width()+1;
        $(this).html(html_org);
        return width;
    };
    
})(jQuery);
