var addthis_config =
{
	services_expanded: 'digg,linkedin,plaxo,twitter,delicious,facebook,favorites,google',
	services_compact: 'digg,linkedin,plaxo,twitter,delicious,facebook,favorites,google'
}

/* MAC SPECIFIC CSS 
if($.client.os == 'Mac'){
	if($.client.browser == "Safari"){ 
		document.write('<link type="text/css" media="screen" rel="stylesheet" href="<?=$modx->config[ "base_url"]?>assets/css/mt-mac-safari.css" />');
	}else if($.client.browser == "Firefox"){ 
		document.write('<link type="text/css" media="screen" rel="stylesheet" href="<?=$modx->config[ "base_url"]?>assets/css/mt-mac-firefox.css" />');
	}
}
*/	

$(document).ready(function(){
	
	// GLOBAL - Button Rollovers
	$('img').hover(
		function(){
			$(this).attr('src', $(this).attr('src').replace("-out", "-over"));
		},
		function(){
			$(this).attr('src', $(this).attr('src').replace("-over", "-out"));
		}
	);
	$('#associated_blogs').hover(
		function(){
			$('#blognav').addClass( "active" );
		},
		function(){
			$('#blognav').removeClass( "active" );
		}
	);
	$('.right a, #results .listing a').each( function(i){
		if (  $(this).attr('href') && $(this).attr('href').substr( 0, 7 ) == "mailto:" ) 
		{
			if ( $(this).html().length >= 30 ) 
			{
				/*
				var size =  $(this).html().length; 
				$(this).css( "font-size", ( parseInt( $(this).css( "font-size" ) ) - Math.ceil( ( size - 30 ) / 6  ) ) + "px" );
			*/
				
				$(this).html( 
				
								$(this).html().substr( 0, $(this).html().indexOf('@') + 1 ) 
								+ "<BR>" 
								+ $(this).html().substr( $(this).html().indexOf('@') +1 )
							 )
				
				
			}
			
		}
	});
	
	// GLOBAL - Resize top tab of each main navigation dropdown menu
	$('#nav li.tab').each(function(i){
		$(this).css('width',
			$(this).parent().prev().width()		
		);							 
	});
	
	// HOME PAGE FLASH NAVIGATION
	$('ul#bannerNav a').click(function(){
		$('ul#bannerNav a').removeClass('active');
		$(this).addClass('active');
		var i = $(this).html();

		var obj = swfobject.getObjectById("homeBanner");
		if (obj) {
		  obj.onNavClick((i - 1));
		}
		return false;
	});
	
	// SELECTED LAWYER - EXPANDABLE HEADERS
	$('#expandables h2').click(function(){
		if($(this).hasClass('active')){
			$(this).removeClass('active');	
		}else{
			$(this).addClass('active');	
		}
		
		$(this).next().slideToggle(250); 
		return false;
	});
	$('#expandables h2:lt(2)').trigger('click');
	
	// SELECTED LAWYER - READ PROFILE BUTTON
	/*
	$('#readProfile').click(function(e){

		if($(this).hasClass('active')){
			$(this).removeClass('active');	
			$(this).html($(this).html().replace("Close","Read"));
		}else{
			$(this).addClass('active');	
			$(this).html($(this).html().replace("Read","Close"));
		}
		
		$('#moreProfile').animate({
			opacity: 'toggle',
			height: 'toggle',
			duration: 500 
		});		
		return false;
	}); */
	
	// LIFE AT MILLER THOMSON - Apply quotes on load
	if($('.moreProfile').parent().parent().hasClass('testimonials')){
		var isTestimonials = true;
		var baseUrl = $('base').attr('href');
		$('.moreProfile').prev().addClass('first').append('<img class="quote" height="9" width="11" alt="" src="'+baseUrl+'assets/images/general/quoteEnd.gif">');
		$('.moreProfile').find('p:last').append('<img class="quote" height="9" width="11" alt="" src="'+baseUrl+'assets/images/general/quoteEnd.gif">');	
	}
	
	$('.readProfile').click(function(e){
		obj = $(this).attr( "rel" ) ? eval( $(this).attr( "rel" ) ) : null;
		if($(this).hasClass('active')){
			$(this).removeClass('active');
			if(isTestimonials){
				$(this).parent().siblings('p.first').find('img.quote').fadeIn(250);	
			}
			if ( obj ) $(this).html( obj[0] );
		}else{
			$(this).addClass('active');	
			if(isTestimonials){
				$(this).parent().siblings('p.first').find('img.quote').fadeOut(250);
			}
			if ( obj ) $(this).html( obj[1] );
		}
		$(this).parent().siblings('.moreProfile').animate({
				opacity: 'toggle',
				height: 'toggle',
				duration: 500
			}, function(){ 
				if ($.browser.msie )
					this.style.removeAttribute("filter");
			}
		);		
		return false;
	});
	
	// ADVANCED SEARCH - SHOW/HIDE
	$('#showAdvanced').click(function(){
		if($('#advancedSearch').css('display') == 'none'){
			$('#advancedSearch').css('display','block');
		}else{
			$('#advancedSearch').css('display','none');
		}
		return false;
	});
	
	$('#urlfilter').change(function() {
			location.href = $(this).val();
	});
	
	$('#searchFilter').change(function() {
		 $(this).closest("form").submit();
	});
	
	 $('#fontsizer').jfontsizer({
		applyTo: "#innercontent",
		changesmall: '2',
		changelarge: '2',
		 expire: 30
	 });
		 
});

function updateNav(index){
	$('ul#bannerNav a').removeClass('active');
	$('ul#bannerNav a:eq('+(index)+')').addClass('active');
}

function resizeiframe( frame ) {
	var resizeFrame = jQuery( frame );
	var innerDoc = (resizeFrame.get(0).contentDocument) ? resizeFrame.get(0).contentDocument : 
														  resizeFrame.get(0).contentWindow.document;
	resizeFrame.height(innerDoc.body.scrollHeight + 35);
}

// Cookie functions
function setCookie( c_name, value, expiredays ){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ";domain=" + domain + ";path=/" + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
	
function getCookie( c_name ){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

var langId = getCookie( 'langId' );
if ( langId != '' ) setCookie( 'langId', langId, 364 );
