var BBH = BBH || {};

BBH.Navigation=function ()
{
	var hiddenClass = 'visuallyhidden', openClass = 'open', activeClass = 'active', $nav = $('nav.main'), $ul = $('ul',$nav), $li = $('li',$ul), $shim = "<div id='navShim'></div>";
	function NavClick (id)
	{
		var $elm = id, $parent = $elm.parent('li');
		$('.active',$nav).removeClass(activeClass);
		if ($elm.hasClass(openClass)) { if ($('#navShim').length === 1) { $('#navShim').remove(); } $elm.removeClass(openClass).addClass(hiddenClass); $parent.removeClass(activeClass); }
		else { $('.open',$li).removeClass(openClass).addClass(hiddenClass); if ($('#navShim').length === 0) { $('body').append($shim); $('#navShim').height($(window).height()).click(function (e) { e.preventDefault(); $('.active',$nav).removeClass(activeClass); $('.open',$li).removeClass(openClass).addClass(hiddenClass); $(this).remove(); }); } $parent.addClass(activeClass); $elm.removeClass(hiddenClass).addClass(openClass); }
	}
	$li.children('a').each(function () { var $this = $(this), h = $('#'+$this.attr('href').split('#')[1]); $this.click(function (e) { e.preventDefault(); NavClick(h); }); });
	$('.flyout',$li).children('.close').each(function () { var $this = $(this), p = $this.parent('.flyout'); $this.click(function (e) { e.preventDefault(); NavClick(p); }); });
	
	$('.flyout .content').each(function ()
	{
		var dlh = 0;
		$(this).find('dl').each(function ()
		{
			var $this = $(this);
			if ($this.height() >= dlh) { dlh = $this.height(); }
		}).height(dlh);
	});
	
};

BBH.setCookie=function(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

BBH.getCookie=function(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name) return unescape(y);
	}
	
	return null;
}

BBH.getQueryStringVariable=function(val)
{
    var hu = window.location.search.substring(1);
    var gy = hu.split("&");

    for (i = 0; i < gy.length; i++) {
        var ft = gy[i].split("=");
        if (ft[0].toLowerCase() == val.toLowerCase()) {
            return ft[1];
        }
    }

    return '';
}


$(function(){
	BBH.Navigation();
}); 


$(function()
{
	$(".accordion2 h3").eq(0).addClass("active");
	$(".accordion2 p").eq(0).show();
	
	$(".accordion2 h3").click(function()
	{
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});
});

$(function()
{
	$(".accordion3 h3").eq(0).addClass("active");
	$(".accordion3 p").eq(0).show();
	
	$(".accordion3 h3").click(function()
	{
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});
});

$(function()
{
	$(".accordion4 h3").eq(0).addClass("active");
	$(".accordion4 p").eq(0).show();
	
	$(".accordion4 h3").click(function()
	{
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});
});

$(function()
{
	$(".accordion5 h3").eq(0).addClass("active");
	$(".accordion5 p").eq(0).show();
	
	$(".accordion5 h3").click(function()
	{
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});
});

$(function()
{
	$(".accordion6 h3").eq(0).addClass("active");
	$(".accordion6 p").eq(0).show();
	
	$(".accordion6 h3").click(function()
	{
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});
});

$(function()
{
	$(".accordion7 h3").eq(0).addClass("active");
	$(".accordion7 p").eq(0).show();
	
	$(".accordion7 h3").click(function()
	{
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});
});




$(function ()
{
	/*$("#expertise").selectbox();*/
	$("#expertise").selectbox({
		onChange: function (val, inst) {
			$.ajax({
				type: "GET",
				data: {expertise: val},
				success: function (data) {
					window.location = $('#expertise').val();
				}
			});
		}
	});

	/*$("#pressrelease").selectbox();*/
	$("#pressrelease").selectbox({
		onChange: function (val, inst) {
			$.ajax({
				type: "GET",
				data: {pressrelease: val},
				success: function (data) {
					window.location = $('#pressrelease').val();
				}
			});
		}
	});



	$("#accolades").selectbox();
	$("#accordion1").accordion( {autoHeight: false} );
	$("#accordion2").accordion({autoHeight: false} ); 
	$("#accordion3").accordion({autoHeight: false} ); 
	$("#accordion4").accordion({autoHeight: false} ); 
	$("#accordion5").accordion({autoHeight: false} ); 
	$("#accordion6").accordion({autoHeight: false} ); 
	$("#accordion7").accordion({autoHeight: false} ); 

	$('#tabs').tabs();
});


$(function ()
{
	if ($.browser.msie && $.browser.version=="7")
	{
		$("#slider2").easySlider(
		{ 
			auto:true,
			continuous:true,
			numeric: true
		});
	}
});	



$(document).ready(function()
{

	//if ($('.breadcrumb').children().length > 4) {
	//	$('.breadcrumb div:gt(3)').remove();
	//}

	
	$(".breadcrumb a:contains('Expertise')").removeAttr("href"); 
	$(".breadcrumb a:contains('Solutions')").removeAttr("href"); 
	$(".breadcrumb a:contains('Insights')").removeAttr("href"); 
	
	$(".breadcrumb a:contains('Expertise')").hover(function (){
       	$(this).attr('style', 'text-decoration:none !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);
	$(".breadcrumb a:contains('Solutions')").hover(function (){
       	$(this).attr('style', 'text-decoration:none !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);
	$(".breadcrumb a:contains('Insights')").hover(function (){
       	$(this).attr('style', 'text-decoration:none !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);

	$(".breadcrumb a:contains('Our People')").attr('href', '/wps/portal/ourfirm/contactus/ourpeople?category=bbh_design/all-expertise,bbh_design/all');


	$("div.breadcrumb a[href*='/BBH_Content/Public+Home+Page']").each(function()
	{              
      	this.href = this.href.replace("/BBH_Content/Public+Home+Page","").replace(/\+/g,"").toLowerCase().replace(/and/g,"");
	});


	$("a[href*='.wav?']").each(function()
	{
		$(this).attr('class', 'per_mp3_link');
	}); 

	$("a[href*='.mp3?']").each(function()
	{
		$(this).attr('class', 'per_mp3_link');
	}); 


	$("div.sitemap a[href*='/BBH_Content/Public+Home+Page']").each(function()
	{              
      	this.href = this.href.replace("/BBH_Content/Public+Home+Page","").replace(/\+/g,"").toLowerCase().replace(/and/g,"");
	});
	
	
	$(".sitemap a:contains('Default Home Content')").attr('href', '/wps/portal/home');
	$(".sitemap a:contains('HomePage')").attr('href', '/wps/portal/home');
	$(".sitemap a:contains('Expertise')").removeAttr("href"); 
	$(".sitemap a:contains('Solutions')").removeAttr("href"); 
	$(".sitemap a:contains('Insights')").removeAttr("href"); 
	
	$(".sitemap a:contains('Expertise')").hover(function (){
       	$(this).attr('style', 'text-decoration:none !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);
	$(".sitemap a:contains('Solutions')").hover(function (){
       	$(this).attr('style', 'text-decoration:none !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);
	$(".sitemap a:contains('Insights')").hover(function (){
       	$(this).attr('style', 'text-decoration:none !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);

	$(".sitemap a:contains('Fund Distribution Support & Solutions')").attr('href', '/wps/portal/expertise/investorservices/productscapabilities/funddistributionsupportsolutions');
	$(".sitemap a:contains('Fund Solutions')").attr('href', '/wps/portal/expertise/investorservices/productscapabilities/funddistributionsupportsolutions/fundsolutions');
	$(".sitemap a:contains('Offshore Fund Solutions')").attr('href', '/wps/portal/expertise/investorservices/productscapabilities/funddistributionsupportsolutions/offshorefundsolutions');
	$(".sitemap a:contains('Senior Debt Solutions')").attr('href', '/wps/portal/expertise/corporatebanking/seniordebtsolutions');
	$(".sitemap a:contains('Global Retirement Solutions')").attr('href', '/wps/portal/expertise/investorservices/specializedservices/globalretirementsolutions');
	$(".sitemap a:contains('Grand Cayman')").attr('href', '/wps/portal/ourfirm/contactus/officelocations/northamerica/grandcayman');
	$(".sitemap a:contains('Member SIPC')").attr('href', '/BBHInternet/themes/html/BBHInternet/sipc.html?keepThis=true&TB_iframe=true&height=300&width=720&modal=true');
	$(".sitemap a:contains('Member SIPC')").attr('class', 'thickbox');
	$(".sitemap a:contains('Member SIPC')").attr('id', 'promo-block-txt-a-id-0');


	$(".sitemap a:contains('Fund Distribution Support & Solutions')").hover(function (){
       	$(this).attr('style', 'text-decoration:underline !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);
	$(".sitemap a:contains('Fund Solutions')").hover(function (){
       	$(this).attr('style', 'text-decoration:underline !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);
	$(".sitemap a:contains('Offshore Fund Solutions')").hover(function (){
       	$(this).attr('style', 'text-decoration:underline !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);
	$(".sitemap a:contains('Senior Debt Solutions')").hover(function (){
       	$(this).attr('style', 'text-decoration:underline !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);
	$(".sitemap a:contains('Global Retirement Solutions')").hover(function (){
       	$(this).attr('style', 'text-decoration:underline !important');
    		},function(){
        	$(this).attr('style', 'text-decoration:none !important');
    		}
	);



	var iStartElmIdx = $(".sitemap a:contains('Our People')").index(); 
        var iStopElmIdx = $(".sitemap a:contains('Email BBH')").index()-1; 
        $(".sitemap").children().each(function() { 
                try {
                var iCurrElmIdx = $(this).index(); 
                if(iCurrElmIdx > iStartElmIdx && iCurrElmIdx < iStopElmIdx) { 
				$(this).attr('href', '');
                        $(this).hide(); 
				$(this).text(""); 
			 } 
                } catch(e) {}
        });
	
	$(".sitemap a:contains('Email BBH')").removeAttr("href"); 
	$(".sitemap a:contains('Email BBH')").hide(); 
	$(".sitemap a:contains('Email BBH')").text(""); 

	var startIndex = $(".sitemap a:contains('U.S. Small & Mid-Cap Equity')").index(); 
        var stopIndex = $(".sitemap a:contains('Mutual Funds')").index()-2; 
        $(".sitemap").children().each(function() { 
                try {
                var currentIndex = $(this).index(); 
                if(currentIndex > startIndex && currentIndex < stopIndex) { 
				$(this).attr('href', '');
                        $(this).hide(); 
				$(this).text(""); 
			 } 
                } catch(e) {}
        });


	

    	for(var i = 0; i <= $(".profile_canvas").length; i+=4){
    	    $(".profile_canvas:nth-child("+(i+1)+")").attr("style","background-color: #FEF7EA");
    	    $(".profile_canvas:nth-child("+(i+2)+")").attr("style","background-color: #FEF7EA");
    	}
    	$(".profile_canvas:odd").removeClass("profile_canvas").addClass("profile_canvas2");

	if($(".contact_picture").html() != null){
		$(".contact_picture").html($(".contact_picture").html().replace('http://mlxwp04q.testbbh.com:10040/wps', '/wps'));
		$(".contact_picture").html($(".contact_picture").html().replace('http://mlxwp04p.bbh.com:10040/wps', '/wps'));
		$(".contact_picture").html($(".contact_picture").html().replace('http://mlxwp01q.testbbh.com:10040/wps', '/wps'));
		$(".contact_picture").html($(".contact_picture").html().replace('http://mlxwpa1q.testbbh.com:10040/wps', '/wps'));
		$(".contact_picture").html($(".contact_picture").html().replace('http://mlxwp01q.testbbh.com:10048/wps', '/wps'));
		$(".contact_picture").html($(".contact_picture").html().replace('http://mlxwpa1q.testbbh.com:10048/wps', '/wps'));
		$(".contact_picture").html($(".contact_picture").html().replace('http://mlxwp01p.bbh.com:10040/wps', '/wps'));
		$(".contact_picture").html($(".contact_picture").html().replace('http://mlxwpa1p.bbh.com:10040/wps', '/wps'));
		$(".contact_picture").html($(".contact_picture").html().replace('http://mlxwp01p.bbh.com:10048/wps', '/wps'));
		$(".contact_picture").html($(".contact_picture").html().replace('http://mlxwpa1p.bbh.com:10065/wps', '/wps'));
	}
	
	$(".context_submenu a:contains('Investment Criteria')").removeAttr("href"); 
	$(".context_submenu a:contains('Investment Criteria')").hide(); 
	$(".context_submenu a:contains('Investment Criteria')").text(""); 

	 
	
 });  
