// JavaScript Document

//goLanguageARGS (String sitefolder, String changefolder)
//
// Call go language from a wrapper function as follows:
// goLanguage ("site","site_sp"); //or viceversa
// to change the current location ("site") to the new location
// ("site_sp")
//
// Arguments:
//sitefolder = the current folder (in this template)
//changefolder = the folder we wish to change to.

//Creates a new Translator object - used to go from one language version to another
this.siteFolder = "";
this.changeFolder = "";
function Translator (siteFolder, changeFolder, imgLoc, ptrName){
	this.siteFolder = siteFolder;
	this.changeFolder = changeFolder;
	document.write ('<a href="javascript:'+ptrName+'.goLanguage();">');
	document.write ('<img alt="Change Language" border="0" src="'+imgLoc+'">');
	document.write ('</a>');
}

Translator.prototype.goLanguage = function (){
	//sitefolder="firstgarden";          //"original folder" where the script is currently at
	//changefolder="firstgarden_sp";     //folder we should go to.
	goBack=1;					       //variable used to crawl the sep_url array.
	current_url=""+document.location;  //current_url: temp var
	
	
	if (current_url.indexOf ("%5F") != -1){
		current_url = unescape (current_url);
	}
		
	current_url = current_url.toLowerCase ();
	
	sep_url=new Array();               //sep_url: array 
	sep_url=current_url.split ("/");   
	path="";
	
	do { //look for the sitefolder in array.
		goBack++;
		folder=sep_url[sep_url.length-goBack].toString();
	} while (folder != this.siteFolder && goBack < sep_url.length);
	
	sep_url[sep_url.length-goBack]=this.changeFolder;  //swap the sitefolder by changefolder
	
	//rebuild url
	for (i=0; i<sep_url.length-1; i++){
		path=path+sep_url[i]+"/";
	}
	
	//tag on the webpage.html file
	path=path+sep_url[sep_url.length-1];
	
	//change current location
	parent.location=path;
}

Translator.prototype.goLanguageARGSReturn = function (){
	//sitefolder="firstgarden";          //"original folder" where the script is currently at
	//changefolder="firstgarden_sp";     //folder we should go to.
	goBack=1;					       //variable used to crawl the sep_url array.
	current_url=""+document.location;  //current_url: temp var
	
	if (current_url.indexOf ("%5F") != -1){
		current_url = unescape (current_url);
	}
		
	sep_url=new Array();               //sep_url: array 
	sep_url=current_url.split ("/");   
	path="";
	
	do { //look for the sitefolder in array.
		goBack++;
		folder=sep_url[sep_url.length-goBack].toString();
	} while (folder != this.siteFolder && goBack < sep_url.length);
	
	sep_url[sep_url.length-goBack]=this.changeFolder;  //swap the sitefolder by changefolder
	
	//rebuild url
	for (i=0; i<sep_url.length-1; i++){
		path=path+sep_url[i]+"/";
	}
	
	//tag on the webpage.html file
	path=path+sep_url[sep_url.length-1];
	
	//return current location
	return path;
}