function MenuBuilder(scheme,serverName,currentURL){
	var threshold = 1000;//document.body.offsetWidth;
	var usedWidth = 0;
	var groups = $('#nav').find('li.group-menu > a');
	var noofelements = groups.length;
	for(var z=0; noofelements > z; z++){
		usedWidth+= groups[z].offsetWidth;
	}
	var paddingSpace = parseInt((threshold - usedWidth)/(noofelements));
	var totalgeneratedwidth = 0 ; // Make 0 if no L/R border, also above
	$(jQuery.grep(groups, function(n, i){
		return (i < (noofelements-1) );
    })).each(
		function(){
			$(this).width(parseInt($(this).width()+(paddingSpace)));
				totalgeneratedwidth+= $(this).width();
		}
	);
	$(groups[noofelements-1]).width(threshold - totalgeneratedwidth);
	$(groups).each(function(){ //height of main navigation links
		$(this).css("line-height", $("#nav").height()+"px");
	});
	$(function() {
		$('#nav').droppy()
	});
}
function QuickLinkBuilder(){
	var threshold = 1000;
	var usedWidth = 0;
	var groups = $('#quicklink').find('li.quick-link > a');
	var noofelements = groups.length;
	for(var z=0; noofelements > z; z++){
		usedWidth+= groups[z].offsetWidth;
	}
	var paddingSpace = parseInt((threshold - usedWidth - noofelements)/(noofelements));
	var totalgeneratedwidth = noofelements ; // Make 0 if no L/R border, also above
	$(jQuery.grep(groups, function(n, i){
		return (i < (noofelements-1) );
    })).each(
		function(){
			$(this).width(parseInt($(this).width()+(paddingSpace)));
				totalgeneratedwidth+= $(this).width();
		}
	);
	$(groups[noofelements-1]).width(threshold - totalgeneratedwidth);
	$(function() {
		$('#quicklink').droppy();
	});
}

$(document).ready(function(){
		
		var url_prefix = String(document.location)
                .replace(/^(https?:\/\/[^:\/]+).*$/, "$1")
                .replace(/^((site)?file:\/\/.+\/)[^\/]+$/, "$1")
                .replace(/(\\.)/g, "\\$1");
	  	var host_name = String(document.location)
                .replace(/^/, "X")
                .replace(/^X(https?|ftp):\/\/([^:\/]+).*$/, "$1")
                .replace(/^X.*$/, "")
                .replace(/(\\.)/g, "\\$1");
		if (host_name == "https") {
			var obj = String(document.location).split("/");
			obj = String(obj[3]).split(".");
			var secure_host_name = String(obj[1] + "." + obj[2]);
			var environment = "";
			if (url_prefix.indexOf("https://devsecure") != -1) 
				environment = "dev.";
			else 
				if (url_prefix.indexOf("https://qasecure") != -1) 
					environment = "qa.";
				else 
					environment = "www.";
			
			$("#nav a").each(function(){//Removes baseurl from 3rd Party Links
				$(this).attr("href", $(this).attr("href").replace("http://" + environment + secure_host_name + "http://", "http://"));
			});
		}
		
	 var externalLinks =    $("#nav a,#smoothmenu2 a,#quicklink a,#sitemap_nav a", this).filter(function (i) { // For Header
                var href = $(this).attr("href");
                if (href == null)
                    return false;
			
				if (host_name=="https" && !(href.match(secure_host_name) == null)){ //Secure
					return false;
				}
                return (
                       href.match(RegExp(
                           "^(" + url_prefix + ".*" +
                           (host_name != "" ? ("|" + "(https?|ftp)://" + host_name + "([/:].*)?") : "") +
                           "|" + "((https?|ftp):)?/[^/].*" +
                           ")$"
                       )) == null
                    && href.match(RegExp("^(https?|ftp)://.+")) != null
					
                );
            });
		
		externalLinks.each(function(){
			 $(this).attr("target","_blank");
		});
});