(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() > el.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);

$(document).ready(function(){
	$("#d-mod").hide();
	$("a.a-mod").click(function() {
		var windowWidth = $(document).width();
		var windowHeight = $(document).height();
		$("#d-mod").show();
		$("#d-mod").css({"width":windowWidth,"height":windowHeight});
		$("#d-mod a.btt-close").click(function() { $("#d-mod").hide(); });
	});

	if(window.location.hash)
	{
		$("a.a-mod").click();
	}
	$('a.btt-close').click(function(){
		location = window.location.href;
		location.replace('#'+window.location.hash, '');
		window.location = location;
	});
	
	$("#page .d-box h3").ellipsis();
	$("#content .d-box h3").ellipsis();
	
});
