// 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=480,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/navAbout_on.jpg', 'i/navPractice_on.jpg', 'i/navAttorney_on.jpg', 'i/navNews.jpg', 'i/navDiversity.jpg', 'i/navCareers.jpg', 'i/navContact.jpg');

	// 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];
		}
	}
}

function hideElement( elementID )
{
	document.getElementById(elementID).style.display='none';
}

function showElement( elementID )
{
	document.getElementById(elementID).style.display='block';
}

///
function toggleBio(){
	var toTog = $('#fullBio');
	
	if(toTog.hasClass('fullBioOff'))
	{
		$('#bioDis').text('View abbreviated profile');
		$.cookie('bioopen', 'true');

	} else {
		$('#bioDis').text('View full profile');
		$.cookie('bioopen', null);
	}

	toTog.toggleClass('fullBioOn').toggleClass('fullBioOff');
}

///
function qToggle(theId)
{
	$('#'+theId).toggleClass('listOff').toggleClass('listOn');
	$('#'+theId+'L').toggleClass('serListOff').toggleClass('serListOn');
}

function qCollapseAll() 
{
	$('li.listOn').removeClass('listOn').addClass('listOff');	
	$('span.serListOn').removeClass('serListOn').addClass('serListOff');
}

function qExpandAll()
{
	$('li.listOff').removeClass('listOff').addClass('listOn');	
	$('span.serListOff').removeClass('serListOff').addClass('serListOn');
}

function showMoreMatters(linkObject)
{
	linkObject.style.display = 'none';
	
	document.getElementById('moreMatters')
	.style.display = 'block'

	document.getElementById('lessMattersLink')
	.style.display = 'block'

	if( $.cookie('bio') )
		$.cookie('biomattersopen', 'true');
	else 
		$.cookie('mattersopen', 'true');
}

function showLessMatters(linkObject)
{
	linkObject.style.display = 'none';
	
	document.getElementById('moreMatters')
	.style.display = 'none'

	document.getElementById('moreMattersLink')
	.style.display = 'block'

	if( $.cookie('bio') )
		$.cookie('biomattersopen', null);
	else
		$.cookie('mattersopen', null);
}


function moreBioAlerts()
{
	// specific page stuff
	var bioAlerts = $('#bioAlerts');
	
	if( bioAlerts.length )
	{
		var extras = bioAlerts.find('li:gt(7)');
		
		if( extras.length )
		{
			extras.hide();
			
			$("<li><a><strong>More Alerts &raquo;</strong></a></li>")
			.css('cursor', 'pointer')
			.css('list-style', 'none')
			.click(function(){ 
				extras.show();
				$(this).hide();
			})
			.appendTo(bioAlerts.children('ul'));
		}
	}
}

function jumpForms()
{
	$('#services select[name^=area_id_]')
	.change(function(){
		val = this.value;
		this.value = '**';
		document.location.href= 'services-' + val + '.html';
	})
}

$(moreBioAlerts);
$(jumpForms);

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


/* db 06/01/10 - bug 15501: added for atty name hover popups */
function attyPopups()
{
		
     	$('.attyListName').hover(
      		function (e) {	
      			
      			$attyPopup = $(this).parent().parent().prev('div');
      			
      			$attyPopup_location = $(this).offset();
      			
      			//$attyPopup_x = $attyPopup_location.left;
      			$attyPopup_y = $attyPopup_location.top;
      			
      			$attyPopup_height = $attyPopup.height();
      			$window_height = $(window).height();
      			$window_bottom = $window_height + $(window).scrollTop();
      			$attyPopup_plus_y = $attyPopup_height + $attyPopup_y;
      			
      			if($attyPopup_plus_y > $window_bottom)
      			{
      				$move_diff = $attyPopup_plus_y - $window_bottom - 8;
      				$attyPopup_y = $attyPopup_y - $move_diff;
      			}
      			
      			//$attyPopup_new_x = $attyPopup_x;
      			$attyPopup_new_y = $attyPopup_y - 12;
      			
      			$attyPopup.css({'top' : $attyPopup_new_y});
      			
      			$attyPopup.css({'display' : 'none'});
      			$attyPopup.show();
      			$attyPopup.css({'z-index' : '10000'});
      			
      			if($(this).is(':visible'))
      			{
      				$('.popupAtty').mouseenter(
      					function () {		
      						$(this).stop().css({'display' : 'block'});
      					}).mouseleave(
      					function(){	
      						$(this).hide();
      					}
    				);
    			}	
      		}, 
      		function () {
         		$(this).parent().parent().prev('div').hide();
      		}
    	);
 }
 
$(attyPopups);

