YAHOO.mixpo.container = function () {

	var hostsEl;
	var hostsHeaderEl;
	var hostsMinHeight;
	var hostsMaxHeight;
	
	var hostsIsExpanded = false;

	return {
		init: function(e)
		{
			if (this.setSize)
			{
				// Set the dimensions upon initial render and listen for subsequent resizes
				YAHOO.mixpo.container.setSize();
				YAHOO.util.Event.addListener(window, "resize", YAHOO.mixpo.container.setSize, YAHOO.mixpo.container, true);
			}
			
			// Truncate the Business Description
			var businessDescriptionSrc = YAHOO.util.Dom.get("businessDescriptionSrc");
			if (businessDescriptionSrc)
			{
				var businessDescriptionLong = businessDescriptionSrc.innerHTML;
				var businessDescriptionShort = YAHOO.mixpo.container.truncateText(businessDescriptionLong);
				if (businessDescriptionLong > businessDescriptionShort)
				{
					YAHOO.util.Dom.get("businessDescriptionShort").innerHTML = businessDescriptionShort + "...";
					YAHOO.mixpo.container.toggleText(e, {elToDisplay: "businessDescriptionShort", elToHide: "businessDescriptionSrc", controlToDisplay: "businessDescriptionExpand", controlToHide: "businessDescriptionHide"});
					YAHOO.util.Event.addListener("businessDescriptionExpand", "click", YAHOO.mixpo.container.toggleText, {elToDisplay: "businessDescriptionSrc", elToHide: "businessDescriptionShort", controlToDisplay: "businessDescriptionHide", controlToHide: "businessDescriptionExpand"}, false);
					YAHOO.util.Event.addListener("businessDescriptionHide", "click", YAHOO.mixpo.container.toggleText, {elToDisplay: "businessDescriptionShort", elToHide: "businessDescriptionSrc", controlToDisplay: "businessDescriptionExpand", controlToHide: "businessDescriptionHide"}, false);
				}
			}
			
			// Add the listeners for highlighting the text
			YAHOO.util.Event.addListener("link", "click", YAHOO.mixpo.container.selectText, YAHOO.mixpo.container, false);
			
			// Find the maximum height the hosts element should be, minimize it, and apply click
			// event handlers to enable expanding and collapsing of the list
			hostsEl = YAHOO.util.Dom.get('hosts');
			if (hostsEl)
			{
				hostsHeaderEl = YAHOO.util.Dom.get('hostsHeader');
				hostsMaxHeight = hostsEl.offsetHeight;
				hostsMinHeight = hostsHeaderEl.offsetHeight;
	
				hostsEl.style.height = hostsMinHeight + "px";
				YAHOO.util.Dom.addClass(hostsHeaderEl, "collapsed");
				
				YAHOO.util.Event.addListener(hostsHeaderEl, "click", YAHOO.mixpo.container.expandCollapseHosts, YAHOO.mixpo.container, true);
			}
		},
		
		// obj example: {elToDisplay: "videoAdDescriptionShort", elToHide: "videoAdDescriptionSrc", controlToDisplay: "videoAdDescriptionExpand", controlToHide: "videoAdDescriptionHide"}
		toggleText: function(e, obj)
		{
			YAHOO.util.Dom.get(obj.elToDisplay).style.display = "block";
			YAHOO.util.Dom.get(obj.elToHide).style.display = "none";
			YAHOO.util.Dom.get(obj.controlToDisplay).style.display = "inline";
			YAHOO.util.Dom.get(obj.controlToHide).style.display = "none";
			YAHOO.util.Event.preventDefault(e);
		},
		
		selectText: function()
		{
			this.select();
		},
		
		truncateText: function(_text)
		{
			var text = _text;

			if (_text.length > 180)
			{
				text = _text.substring(0, 180);
			}
			
			return text;
		},

		setSize: function () {
			var viewportHeight = YAHOO.util.Dom.getViewportHeight();
			var playerHeight = viewportHeight - 20;
			var player = YAHOO.util.Dom.get("player");
			player.style.width = "auto";
			player.style.height = playerHeight + "px";
		},
		
		expandCollapseHosts: function() {
			if (hostsIsExpanded)
			{
				hostsEl.style.height = hostsMinHeight + "px";
				hostsIsExpanded = false;
				YAHOO.util.Dom.replaceClass(hostsHeaderEl, "expanded", "collapsed");
			}
			else
			{
				hostsEl.style.height = hostsMaxHeight + "px";
				hostsIsExpanded = true;
				YAHOO.util.Dom.replaceClass(hostsHeaderEl, "collapsed", "expanded");					
			}
		}
	};

}();
