function writeEmailAddress(u,d, boolShowText) {
		
			document.write('<a href="mailto:');
			document.write(u);
			document.write('@');
			document.write(d);
			document.write('" class="mailto">');
			if (arguments.length == 3 && boolShowText == false){;}
			else {
				document.write(u);
				document.write('@');
				document.write(d);
			}
			document.write('</a>');
			return true;

}

function heightHeader(){
		var heightHeader;
		if($(".homePage").size()>0){
			heightHeader = $("#pageHeader").height()+$("#navigation").height()+$(".slideshow").height()+"px";
		} else {
			heightHeader = $("#pageHeader").height()+$("#navigation").height()+ $("#breadcrumbs").height()+"px";
		}
		$("#bgHeader").css("height",heightHeader);
	}
	
function addClassBreadcrumb(){
    $("#breadcrumbs a:last").addClass("breadCrumbLast");	
	}	
	
function resizeCols(col1,col2){
	if($(col1).height()>$(col2).height()){
		$(col2).css("height",$(col1).height()+"px");
		} else {
			$(col1).css("height",$(col2).height()+"px");		
		}
	}	
	
function toggleSecondLevelTopMenu(){
    $("#navigation.horizontal li").hover(
      function () {
        $(this).find("ul").show();
		$(this).find("ul ul").hide();
      }, 
      function () {
       	$(this).find("ul").hide();
      }
    );
    $("#navigation.horizontal li li").hover(
      function () {
		$(this).addClass("selected");
		$(this).find("ul").hide();
      },
      function () {
       	$(this).removeClass("selected");
      }	  
    );	
}
$('.slideshow').cycle({
	fx: 'fade',
	timeout: 5000,
	prev: $('#btn_cycle_prev'),
	next: $('#btn_cycle_next')
}); 

function rotatingResources(){
	$("#resources").each(function(){
		var sizeLiResources = $(this).find("li").size();	
		if(sizeLiResources>5){
			$('#resources').clone().addClass('printOnly').appendTo($(this).parent());
			$("#resources").jCarouselLite({
				circular: true,
				vertical:true,
				visible: 5,
				start: 0,
				scroll: 3,
				auto:1,
				speed: 3800
			}).addClass('noPrint');	
		}
	});
}

function rotatingLawyers(){
	$("#lawyers").each(function(){
		var sizeLiLawyers = $(this).find("li").size();	
		if(sizeLiLawyers>5){
			$('#lawyers').clone().addClass('printOnly').appendTo($(this).parent());
			$("#lawyers").jCarouselLite({
				circular: true,
				vertical:true,
				visible: 5,
				start: 0,
				scroll: 3,
				auto:1,
				speed: 3200
			}).addClass('noPrint');	
		}
	});	
	}
	
function detectHomePage(){
	$(".homePage").parent().parent().parent().parent().addClass("homePage");
}

function cookieSite() {
		var COOKIE_NAME = 'LRMMCookie';
		// set cookie by date
		$('#LRMMCookieEn').click(function() {
			var date = new Date();
			date.setTime(date.getTime() + (1000 * 24 * 60 * 60 * 1000));
			$.cookie(COOKIE_NAME, 'LRMMCookieEn', { path: '/', expires: date });
			 $('#dialog').jqmHide();
			window.location.replace("/en-CA");
			return false;
		});
	
		// set cookie by date
		$('#LRMMCookieFr').click(function() {
			var date = new Date();
			date.setTime(date.getTime() + (1000 * 24 * 60 * 60 * 1000));
			$.cookie(COOKIE_NAME, 'LRMMCookieFr', { path: '/', expires: date });
			$('#dialog').jqmHide();
			window.location.replace("/fr-CA");
			return false;
		});	
		
		if(!($.cookie(COOKIE_NAME) =="LRMMCookieEn") &&  !($.cookie(COOKIE_NAME) =="LRMMCookieFr")){
			 $('#dialog').jqm();
			 $('#dialog').jqmShow(); 
		} 
}


 $(document).ready(function() {
	detectHomePage();
	addClassBreadcrumb();
	heightHeader();
	resizeCols($("#sideLeft"),$("#center"));
	$(".adressBlock .adressBlockBorder:last").css("border-bottom","none");	
	$("#expertiseRight .linkAll:last").css("border-bottom","1px solid #d5e5eb");
	$("#relatedPublications li:last").css("border-bottom","none");
	toggleSecondLevelTopMenu();
	rotatingResources();
	rotatingLawyers();
	var maxHeight = 0;
	$("#expertiseRight li a").each(function(){
		if($(this).height()>maxHeight){
			maxHeight = $(this).height();
		}	
	});
	$("#expertiseRight li a").each(function(){
		$(this).parent().css("height",maxHeight+"px");
		if($(this).height()<maxHeight){
			$(this).css("padding-top",maxHeight/4+"px");
		}
				
	});
	 cookieSite();


 });
 
              

