
j(document).ready(function() {
   
	if(j.browser.safari){		
		j("head").append("<link href='/common/css/safari.css' type='text/css' relation='stylesheet'/>");	
	}
	//create the highlighter
	var navHighlighter = new tbelt.url.Highlighter({
		url:document.location.href,
		alterElements:[{element:"each", className:"active"}]
	});
	//highlight top/primary nav
	navHighlighter.options.links = j("div#siteHeader a,div#siteNav a");
	navHighlighter.highlight();
	
	//higlight secondary nav
	var leftNavLinks = j("div#siteLeftNav a");	
	navHighlighter.options.links = leftNavLinks.not(".active");
	navHighlighter.highlight();	
	
	var activeLink = j(navHighlighter.bestMatch.link);
	activeLink.closest("li").children("ul").css({display:"block"});
	activeLink.parents("ul").css({display:"block"});
	
	activeLink.parents("li.has-subs").each(function(i, li){			
		j(li).children("ul").prev("a").addClass("active");
	});
	
	leftNavLinks.filter("[href='"+activeLink.attr("href")+"']").not(".active").each(function(i, a){
		j(a).addClass("active");
	});
	
   
   // set input element classes
	j("input[type='text'][class='']").addClass("input-text");
	j("input[type='button'][class='']").addClass("input-button");
	j("textarea[class='']").addClass("input-textarea");
	
	
	// site Search function
	siteSearchBox();	
	
 });

 

function emailPage(){
                var emailSubject = "Your friend wants to share a link to a webpage on http://www.ibridgegroup.com/";
                var emailBody = "Here is the URL to a webpage on the iBridge website (http://www.ibridgegroup.com/) I'd like to share with you: "+window.location.href;
                window.location = "mailto:?subject="+emailSubject+"&body="+emailBody;
}



function siteSearchBox(){
	var searchBox = j("input#txtSiteSearch");
	searchBox.val("Search")
	searchBox.focus(function(evt){
					if(evt.target.value=="Search") evt.target.value="";
	});
	searchBox.blur(function(evt){
		if(evt.target.value=="") evt.target.value="Search";
	});
	searchBox.keydown(function(evt){
		if(evt.keyCode==13) window.location = "/search/?q="+evt.target.value;
	});
	j("a#btnSiteSearch").click(function(evt){
		if(searchBox.val()!="Search") window.location = "/search/?q="+searchBox.val();
    });
	
}
