// Email window popup with disclaimer static text.
// use: when user clicks and attorney email link
//
function emailWindow(email)
{
	window.open("email-popup.html?email=" + email, "EmailNotice", "toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes,width=500,height=380");
}

// Bookmark page link, IE only.
// all other browsers displays an alert box.  not sure how detailed we
// want to make this, eg NS, Firefox 'press ctrl+d' message, Mozilla ??
//
function addToFavorites()
{
	var ua = navigator.userAgent.toLowerCase(); 

	// browser engine name
	this.isGecko	   = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
	this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

	// browser name
	this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
	this.isSafari	   = (ua.indexOf('safari') != - 1);
	this.isOmniweb	   = (ua.indexOf('omniweb') != - 1);
	this.isOpera	   = (ua.indexOf('opera') != -1); 
	this.isIcab	   = (ua.indexOf('icab') != -1); 
	this.isAol	   = (ua.indexOf('aol') != -1); 
	this.isIE	   = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
	this.isMozilla	   = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
	this.isFirebird    = (ua.indexOf('firebird/') != -1);
	this.isFirefox	  = (ua.indexOf('firefox/') != -1);
	this.isNS	   = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );

	this.versionMajor = parseInt(this.versionMinor);
	this.isMac    = (ua.indexOf('mac') != -1);

	this.isIE5x = (this.isIE && this.versionMajor == 5);

	if (window.external && !this.isMac)
	{
		var url=window.location.href;
		var title=document.title;
		window.external.AddFavorite(url,title)
	} else if (!this.isMac && (this.isNS || this.isFirefox || this.isMozilla))
	{
		alert("Press Ctrl+D to bookmark this page."); 
	} else if (this.isMac && (this.isSafari || this.ie5x || this.isMozilla))
	{
		alert("Press Apple/Squiggle+D to bookmark this page."); 
	} else {
		alert("Sorry! Your browser doesn't support this function.\nUse your browser's bookmark feature to add a bookmark."); 
	}
}

// Place holder for the 'print this page' link
// s/b replaced when we do the html templates
//
function printPage()
{
	window.print();  
}

// 
// NS only
//
function findOnThisPage()
{
	window.find();	
}


// preload images
function preloadImages()
{
	var imagesToLoad = new Array('i/arrow_right.gif','i/nav/nav_about.gif', 'i/nav/nav_practices.gif', 'i/nav/nav_professionals.gif', 'i/nav/nav_news.gif', 'i/nav/nav_careers.gif', 'i/nav/nav_clients.gif', 'i/nav/nav_ecommunications.gif', 'i/nav/nav_industries.gif');

	// Don't bother if there's no document.images
	if (document.images)
	{
		if (typeof(document.WM) == 'undefined')
		{
			document.WM = new Object();
		}

		document.WM.loadedImages = new Array();

		// Loop through all the arguments.
		var argLength = imagesToLoad.length;

		for(arg=0;arg<argLength;arg++) 
		{
			// For each arg, create a new image.
			document.WM.loadedImages[arg] = new Image();
			// Then set the source of that image to the current argument.
			document.WM.loadedImages[arg].src = imagesToLoad[arg];
		}
	}
}



// Tool Bar image links - help text
// call by: onMouseOver=\"toolHelp('Email this Page');\" onMouseOut=\"toolHelp('Options');\">
//
function toolHelp( helptext )
{
	 var toolhelp = document.getElementById('toolhelp');
	toolhelp.innerHTML = helptext;
}

function homeSiteSearch()
{
	var searchBox = document.getElementById('searchtext');
	var searchForm = document.getElementById('siteSearchForm')

	if( searchBox && searchForm && searchBox.value && searchBox.value != '' )
	{
		searchForm.submit();
		return false;
	}
}

function homeAttorneySearch()
{
	var searchBox = document.getElementById('fullname');
	var searchForm = document.getElementById('attorneySearchForm')

	if( searchBox && searchForm && searchBox.value && searchBox.value != '' )
	{
		searchForm.submit();
		return false;
	}
}

// hovering boxes on bios and cases
function hoverBoxes()
{
	var $hoverLinks = $('div.locationBox a');
	
	if( !$hoverLinks.length )
		return;
	
	var hoverTimeout = null;
	var $hoverBox = $("<div id='hoverBox'></div>").hide().appendTo('body');
	
	$hoverLinks
	.mouseover(function(e){
		
		var $this = $(this);
		$hoverBox.hide();
		clearTimeout(hoverTimeout);

		if( !$this.data('snippet') )
		{
			var snippetURL = this.href.replace('.html', ',snippet.html');
			$this.data('hoverWaiting', true);
			
			$.get(snippetURL, function(data){
				$this.data('snippet', data);
				
				if( $this.data('hoverWaiting') )
					$this.mouseover();
			});
			
			return;
		}
		
		// make the top of the hover box line up with the link
		var pos = $this.offset();		
		var newTop = pos.top-30;
		var newLeft = pos.left + $(this).outerWidth()+5;
		
		// put the fetched html into the hover box
		$hoverBox
		.html($this.data('snippet'))
		.css({
			top: newTop,
			left: newLeft,
		})
		.fadeIn('fast');
		
		// see how much we're hanging over the bottom
		var newBottom = newTop + $hoverBox.outerHeight();
		var scrollTop = $(window).scrollTop();
		var overBottom = newBottom - $(window).height() - scrollTop;
		
		// if we're hanging over the bottom, figure out a new top
		if( overBottom > 0 )
		{
			oldTop = newTop;
			
			// make sure the new top does go above the viewport
			// give a 2-pixel distance from the top or bottom
			newTop = Math.max(scrollTop + 2, newTop-overBottom - 2);
			
			// move the hover box
			$hoverBox.css({
				top: newTop
				});
		}
		
	});
	
	// if you hover the box, clear the timeout
	$hoverBox.mouseover(function(){
		clearTimeout(hoverTimeout);
	});
	
	// if they mouse out of the box or the link, set a fade out
	$hoverLinks.add($hoverBox).mouseout(function(){
		
		$(this).data('hoverWaiting', false);
		hoverTimeout = setTimeout(function(){
			$hoverBox.fadeOut();
		}, 900)
		
	});
}

$(hoverBoxes);
