function TextContainer_Ellipsis(e) {
	var el = e;
	e = e.dom;
	e.style.marginRight = "-10000px";

	var w = el.getWidth() - 10000;
	
	if (w < 0) {
	    e.style.marginRight = "0px";
		return;
	}

	var t = e.innerHTML;
	
	e.innerHTML = "<span>" + t + "</span>";

	var p = e;
	el = el.first();
	e = el.dom;
	var start = 0, end = t.length;
	if (el.getWidth() < w) {
	    p.style.marginRight = "0px";
		return;
	}

	var anchor = t.toLowerCase().indexOf("<a ");
	if (anchor > -1)
		start = t.indexOf(">", anchor);
	while (start != end) {
		var halfway = Math.floor((start+end)/2);
		e.innerHTML = t.substr(0, halfway) + "&hellip;";
		//e.style.whiteSpace = "nowrap";
		if (el.getWidth() < w && start != halfway)
			start = halfway;
		else
			end = halfway;
	}
	
	// Leave a bit of margin in case the table resizes its columns and squeezes a truncated word out of the cell
	p.style.marginRight = "-20px";
	
}

var TextContainer_List = new Array();

function TextContainer_Setup()
{
    Ext.select('.TextContainer', true).each(function(x) {
        TextContainer_List.push(Ext.get(x.dom));
    });
	TextContainer_Run();
}

function TextContainer_Run()
{
    var started = new Date();
    var tc;
    while (tc = TextContainer_List.shift()) {
		TextContainer_Ellipsis(tc);

		if ((new Date()) - started > 500) {
			setTimeout("TextContainer_Run()", 500);
			return;
		}
	}
}

addEvent('load', TextContainer_Setup);

// Removed the Javascript Version of the HeightTextContainer
// Use the Html Helper EllipsedTextWithAnimation Instead
// Uses the ToggleElement and SlideElement Javascript Functions Below


// slideElement Has Issues with a major Bug In Firefox
// Doesn't work with overflow divs
// http://www.yui-ext.com/forum/showthread.php?t=71422

// Used by the Artist Page to Slide In and Out the Divs
// Ellipsis is performed server side
function slideElement(e) {

    var element = Ext.get(e);
    element.setVisibilityMode(Ext.Element.DISPLAY);

    var child = element.dom.firstChild;
    child.style.overflow = "none !important";           

    if (element.isVisible())
        element.slideOut('t', {
            easing: 'easeOut',
            duration: 1,
            remove: false,
            useDisplay: true

        });
    else
        element.slideIn('t', {
            easing: 'easeIn',
            duration: .5
        });

    child.style.overflow = "";
}

// Used by the Artist Page to Show and Hide the Divs
// Ellipsis is performed server side
function toggleElement(e) {

    var element = Ext.get(e);

    element.setVisibilityMode(Ext.Element.DISPLAY);

    if (element.isVisible())
        element.hide();
    else
        element.show();
            
}  

