/******
*  Author: Reed Evans
*  Description: This is to solve the shared content dillema.
*		Some shared content will contain relative links,
*		so these links must be converted to be relative
*		to the region that they are contained in. 
*		Content contributors are instructed to add the 
*		class "shared" to all created links that are intended 
*		to be relative.
******/


$(document).ready(function() {
  var url=window.location.href.split("Website/WebSite");
  var frontUrl="";
  
  if(url[1])
    frontUrl=url[1].match(/\/[a-z_]+\/[a-z]{2}\//i);
  else
    frontUrl=url[0].match(/\/[a-z_]{2,15}\/[a-z]{2}\//i);
    
	$("a.shared").each(function() { 
	//alert(frontUrl);
	var anch = $(this);	
	var link = anch.attr("href");
	var match = link.match(/shared[%a-z _\d]*\/[a-z]{2}\//i);
	//  example: matches the /AA_Global_Shared_Content/EN/ in  
	//  /AA_Global_Shared_Content/EN/Company/Governance/BoardCommittees.html 
	//  to replace with local domain ..paper.com/US/EN...
	if(match){
	  index = link.indexOf(match[0]);
	  var backUrl = link.substring(index+match[0].length);
	  // example: Company/Governance/BoardCommittees.html  in example above
	  anch.attr("href",previewUrl+frontUrl+backUrl);
	}

	 }); 
 });