﻿
$(document).ready(function() {
	SearchResults();
	HideLibraryLinks();
	ClassTopNavigation();
	MatchSidebarHeight();	
});

function SearchResults() {
	try {
		$('.srch-URL2').each(function() {
			console.log($(this).text() + '=' + $(this).text().length );
			if($(this).text().length > 80) {
				$(this).attr('title',$(this).text());
				$(this).text($(this).text().substring(0,80)+'...');
			}
		});
	
	}
	catch(e) {}

}

function ClassTopNavigation() {

	try {
		var path = window.location.pathname;
		var mclass = "none";
		if(path.indexOf("Professionals") >= 0) {
			mclass = "professionals";
		}
		else if(path.indexOf("Public") >= 0) {
			mclass = "public";
		}
		else if(path.indexOf("Members") >= 0) {
			mclass = "members";
		}
		else if(path.indexOf("Search") >= 0) {
			mclass = "search";
		}
		
		$('#top-nav ul.root ul.static li.static a.static').each(function(i) {
			$(this).addClass(mclass+'-menu-item-'+i);
		});
	
	}
	catch(e) {}

}

/* Plugin to make variable height divs equal heights */ 
function MatchSidebarHeight() {  
	try	{

		var sidebarHeight = $('#left-sidebar').height();
		var rightSideHeight = $('#content').height();		
		if(rightSideHeight > sidebarHeight) {
			$('#left-sidebar').height(rightSideHeight);
		}				

	}	
 	catch(err) {}
}; 


function HideLibraryLinks() {
	
	$('#left-sidebar-inner a.static.menu-item').each(function(){
		if($(this).text()=='Libraries'){
			$(this).parent().hide();
		}
	});
	
}


/* sharepoint scrolling fix */
function FixRibbonAndWorkspaceDimensions()
{ULSxSy:;
    g_frl=true;
    var elmRibbon=GetCachedElement("s4-ribbonrow");
    var elmWorkspace=GetCachedElement("s4-workspace");
    var elmTitleArea=GetCachedElement("s4-titlerow");
    var elmBodyTable=GetCachedElement("s4-bodyContainer");
    if(!elmRibbon ||
       !elmWorkspace ||
       !elmBodyTable)
    {
        return;
    }
    if(!g_setWidthInited)
    {
        var setWidth=true;
        if(elmWorkspace.className.indexOf("s4-nosetwidth") > -1)
            setWidth=false;
        g_setWidth=setWidth;
        g_setWidthInited=true;
    }
    else
    {
        var setWidth=g_setWidth;
    }
    var baseRibbonHeight=RibbonIsMinimized() ? 44 : 135;
    var ribbonHeight=baseRibbonHeight+g_wpadderHeight;
    if (GetCurrentEltStyle(elmRibbon, "visibility")=="hidden")
    {
        ribbonHeight=0;
    }
    if(elmRibbon.children.length > 0 && document.getElementsByTagName("html")[0].className.indexOf('ms-dialog-nr') == -1){
    	if(document.getElementById('pageStatusBar').style.display == 'block'){
    		ribbonHeight += 27;
    	}
	    elmWorkspace.style.paddingTop = ribbonHeight + 'px';
	}
}

function addStatus(f, g, e) {
    ULSA13: ;
    var a = document.getElementById("pageStatusBar");
    if (a != null) {
        a.setAttribute("aria-live", "polite");
        a.setAttribute("aria-relevant", "all");
        var b = _createStatusMarkup(f, g, true);
        if (!e) a.appendChild(b);
        else {
            var c = a.getElementsByTagName("SPAN"),
                d = c.length > 0 ? c[0] : null;
            if (d != null) a.insertBefore(b, d);
            else a.appendChild(b)
        }
        if (a.childNodes.length == 1) {
            StatusIdWithTopPriority = b.id;
            StatusColorWithTopPriority = 1
        }
        a.style.display = "block";
        FixRibbonAndWorkspaceDimensions()
        return b.id
    }
}

