//FRENCH VERSION
var linkSwitchElement = "en-fr-switch";
//Add new URLS as new entry points are created
var internalBaseUrl = new Array(
	"http://www.defiafghanistan.ca/", 
	"http://defiafghanistan.igloocommunities.com/"	
);

var externalBaseUrl = "http://www.afghanistanchallenge.ca/";
/*
=========================
About
=========================
- Will take the current URL and find the matching french link. If the script cannot find the exact mapping,
  it will find the best match.
  For example, if there is no mapping for
  /conntect/message, but there is one for /connect, then the link will use /connect

=========================
How to add a link
=========================
	1) Get English and french links from website (copy link)
	2) remove http=//defiafghanistan.igloocommunities.com/ & http=//afghanistanchallenge.igloocommunities.com/ from
       url (you should now have a relative link)
    3) use template below to create Link, replace Eng & Fre with the links
    4) paste link in the appropriate area. It doesn't matter where you put it, but
       putting the link with links close to it will make it easier for making changes in the future
	5) Copy same template to other JS (no changes needed for the other file)
	    
=========================
TEMPLATE
=========================
mappingArray["Eng"] = "Fre";

=========================
How to add a new URL
=========================
When/If a new URL is added that points to this community (i.e. http://www.afghanistanchallenge.com), then you must add this to the
list of urls above To do this:

1) add a comma to the last URL 
	(in the current build, "http://defiafghanistan.igloocommunities.com/" would 
	become (on line 6: "http://defiafghanistan.igloocommunities.com/", 
2) add a the new url, making sure to add a forward slash at the end

Example:
We want to add http://www.defiafghanistan.com/ to the list of URLS:

OLD: 
var internalBaseUrl = new array(
	"http://www.defiafghanistan.ca/", 
	"http://defiafghanistan.igloocommunities.com/"	
);

NEW: 
var internalBaseUrl = new array(
	"http://www.defiafghanistan.ca/", 
	"http://defiafghanistan.igloocommunities.com/",
	"http://www.defiafghanistan.ca/"
);


=========================
Versions
=========================
If something goes wrong, you can always revert back to a previous working copy. Go to the following links to view the versions=

ENGLISH:
http://www.afghanistanchallenge.ca/templates/javascript/enfrswitch?action=versions

FRENCH:
http://www.defiafghanistan.ca/templates/javascript/frenswitch?action=versions

*/
if($(linkSwitchElement)){
	var mappingArray = new Hash();
	mappingArray["home"] = "accueil";
	mappingArray["news"] = "nouvelles";
	mappingArray["connect"] = "brancher";
		mappingArray["connect/message"] = "brancher/message";
		mappingArray["connect/toolkit"] = "brancher/boite";
	mappingArray["learn"] = "savoir";
		mappingArray["learn/education"] = "savoir/education";
		mappingArray["learn/entreprene"] = "savoir/entreprene";
		mappingArray["learn/food"] = "savoir/aide";
		mappingArray["learn/health"] = "savoir/sant";
		mappingArray["learn/infrastruc"] = "savoir/infrastruc";
		mappingArray["learn/resources"] = "savoir/ressources";
	mappingArray["partners"] = "partenaire";
	mappingArray["about"] = "a_propos";
		mappingArray["about/contact"] = "a_propos/contact~3";
		mappingArray["about/faq"] = "a_propos/foireauxqu";
		mappingArray["about/legal"] = "a_propos/juridique";
	mappingArray["signup"] = "inscrivez";
	mappingArray["donate"] = "donnez";
		mappingArray["donate/project1"] = "donnez/projet1";
		mappingArray["donate/project2"] = "donnez/projet2";
		mappingArray["donate/project3"] = "donnez/projet3";
	mappingArray["templates"] = "templates";
	
	
	var relativeUrl = document.location.href.replace(/\?.*$/g, "");
	
	for(var i = 0; i < internalBaseUrl.length; i++){
		relativeUrl = relativeUrl.replace(internalBaseUrl[i], "");
	}
	
	if(mappingArray.keyOf(relativeUrl)){				
		$(linkSwitchElement).href = externalBaseUrl + mappingArray.keyOf(relativeUrl);		
	}else{
		
		while(relativeUrl.length > 0){
			if(!relativeUrl.lastIndexOf('/') || relativeUrl.lastIndexOf('/') == -1){
				break;
			}
						
			relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf('/'));		
			
			if(mappingArray.keyOf(relativeUrl)){									
				$(linkSwitchElement).href = externalBaseUrl + mappingArray.keyOf(relativeUrl);
			}
		}
	}	
}