var userLang;

if (!(document.cookie)) {
	// If the language isn't set, then set it to English as default
	userLang = "english";
} else {
	// If the language is set, then use the cookie
	// But also get rid of "lang="
	userLang = document.cookie.substring(5,document.cookie.length);
	// If there is a semicolon present in the cookie string
	if (userLang.indexOf(';') != -1) {
		// Make a note of where the semicolon is in the string
		var x = userLang.indexOf(';');
		// ... and chop everything from the start of the string to just before the semicolon
		userLang = userLang.substring(0,x);
	}
}

// *****************************************************************
// *            Text for Column 3 (thin col on right)              *
// *****************************************************************
var englishTextColumn3 = '<a href="http://www.fundforpeace.org/" class="col3">The Fund for Peace website</a><br /><br /><a href="../text_only.htm" class="col3">Text-only version (all other languages)</a><br /><br /><a href="../resources/flyer.htm" class="col3">Download the HRE flyer</a>';

// *****************************************************************
// *                       Rollover Engine                         *
// *****************************************************************

// Preload the images

preloadEnglish = new Image;
preloadBosnian = new Image;
preloadIndonesian = new Image;

preloadEnglish.src = "../images/english_on.gif";
preloadBosnian.src = "../images/bosnian_on.gif";
preloadIndonesian.src = "../images/indonesian_on.gif";

function swapImage(imageName) {
	if (userLang != imageName) {
		document[imageName].src = "../images/" + imageName + "_on" + ".gif";
	}
}
function restoreImage(imageName) {
	if (userLang != imageName) {
		document[imageName].src = "../images/" + imageName + ".gif";
	}
}

// *****************************************************************
// *              Code that prepares language tab images           *
// *****************************************************************
function chooseImage(imageName) {
	if (userLang == imageName) {
		// Make the image grey (i.e _active suffix)
		document.write('<a href="#"  onClick="setUserLang\(\''+ imageName + '\'\); return false;" onMouseOver="swapImage\(\''+ imageName + '\'\);" onMouseOut="restoreImage\(\''+ imageName + '\'\);"><img name="'+ imageName + '" src="../images/'+ imageName + '_active.gif" border="0" alt="' + imageName + '" /></a>');
	} else {
		// Make the image whatever it is (i.e. no suffix)
		document.write('<a href="#"  onClick="setUserLang\(\''+ imageName + '\'\); return false" onMouseOver="swapImage\(\''+ imageName + '\'\);" onMouseOut="restoreImage\(\''+ imageName + '\'\);"><img name="'+ imageName + '" src="../images/'+ imageName + '.gif" border="0" alt="' + imageName + '" /></a>');
	}
}

function setUserLang(lang) {
	// Step 1: change the cookie, adding "lang=" before the text, and ";path=/" after it
	document.cookie = 'lang=' + lang + ';' + 'path=/;';
	// Step 2: Reload the page
	location.reload();
}

function firstColumn() {
	if (userLang == "bosnian") {
		return bosnianTextColumn1;
	} else if (userLang == "indonesian") {
		return indonesianTextColumn1;
	} else {
		return englishTextColumn1;
	}
}

function secondColumn() {
	if (userLang == "bosnian") {
		return bosnianTextColumn2;
	} else if (userLang == "indonesian") {
		return indonesianTextColumn2;
	} else {
		return englishTextColumn2;
	}
}

function thirdColumn() {
	return englishTextColumn3;
}

function sideNav() {
	if (userLang == "bosnian") {
		return bosnianSideNav;
	} else if (userLang == "indonesian") {
		return indonesianSideNav;
	} else {
		return englishSideNav;
	}
}

function writeTopNav(index) {
	if (userLang == 'bosnian') {
		return bosnianTopNav[index];
	} else if (userLang == 'indonesian') {
		return indonesianTopNav[index];
	} else {
		return englishTopNav[index];
	}
}



