function MenuBuilder(scheme,serverName,currentURL){
	var threshold = 961;//document.body.offsetWidth;
	var usedWidth = 0;
	var groups = $('#nav').find('li.group-menu > a');
	$('#lastGroup').css("border-right","0");
	var noofelements = groups.length;
	for(var z=0; noofelements > z; z++)
		usedWidth+= groups[z].offsetWidth;
	var paddingSpace = parseInt((threshold-usedWidth)/(noofelements));
	//alert(paddingSpace);
	//paddingSpace = paddingSpace - noofelements;
	//alert(paddingSpace);
	var totalgeneratedwidth = 0 ; // Make 0 if no L/R border, or 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");
		
	});
	$('li.group-menu:last a').css("border-right", "none");
	$(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");
		/*
		 * Removes baseurl from 3rd Party Links ( Secure )
		 */
		if (host_name == "https") {
			var environment = (url_prefix.indexOf("https://devsecure") != -1)?"dev.":(url_prefix.indexOf("https://qasecure") != -1)?"qa.":(url_prefix.indexOf("https://secure1") != -1)?"www.izdemosite.com/":"www.";
			var obj = String(document.location).split("/");
			obj = String(obj[3]).split(".");
			var secure_host_name = (environment=="www.izdemosite.com/")? String(obj[1]):String(obj[1] + "." + obj[2]);
			$("#nav a").each(function(){
				$(this).attr("href", $(this).attr("href").replace("http://" + environment + secure_host_name + "http://", "http://"));
			});
		}
		/* 
		 * Remove baseurl from Demo 3rd Party Links (Non Secure)
		 */
		if(url_prefix == "http://www.izdemosite.com"){
			var demo_urls = String(document.location).split("/");
			var demo_host_name = demo_urls[3];
			$("#nav a").each(function(){
				$(this).attr("href", $(this).attr("href").replace("http://www.izdemosite.com/" + demo_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)) return false; //Secure with link having izdemosite.com
                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");
		});
});
