/*
	jQuery plugin that adds ellipsis() function
*/
(function($) {
	$.fn.ellipsis = function(enableUpdating){
		var s = document.documentElement.style;
		if (!('textOverflow' in s || 'OTextOverflow' in s)) {
			return this.each(function(){
				var el = $(this);
				if(el.css("overflow") == "hidden"){
					var originalText = el.html();
					var w = el.width();
					
					var t = $(this.cloneNode(true)).hide().css({
						'position': 'absolute',
						'width': 'auto',
						'overflow': 'visible',
						'max-width': 'inherit'
					});
					el.after(t);
					
					var text = originalText;
					while(text.length > 0 && t.width() > parseInt(el.css("width"))){
						text = text.substr(0, text.length - 1);
						t.html(text + "...");
					}
					el.html(t.html());
					
					t.remove();
					
					if(enableUpdating == true){
						var oldW = el.width();
						setInterval(function(){
							if(el.width() != oldW){
								oldW = el.width();
								el.html(originalText);
								el.ellipsis();
							}
						}, 200);
					}
				}
			});
		} else return this;
	};
})(jQuery);
/*
	End jQuery ellipsis plugin
*/


$(document).ready(function(){
	$("#nav li a").bind("mouseover", function(e){
		var uls = $(this).next("ul");
		var newHTML = "<li style=\"display:none;\"></li>";
		if(uls.length > 0){
			var ul = uls[0]; //Just grab the first one
			newHTML = $(ul).html();
		}
		$("#subnav").html(newHTML);
	});
	var ells = $(".ellipsis");
	ells.ellipsis(); //apply the ellipsis function to anything using the CSS class "ellipsis"
});