/* --- JavaScript --- */
/* --- Home --- */


/* --- set hover action for WhereToGo-links --- */
initWhere2Go = function() {
	var imgPath = "http://italiano.interrailnet.com/enit/images/interrail/countries/";	// folder in which the swap images are stored (end with '/')
	var imgPrepend = "w2g_";			// filename prepend
	
	var whereToGo, countryToGo, countryLinks;
	if (!(whereToGo = document.getElementById('whereToGo'))) return false;
	if (!(countryToGo = document.getElementById('countryToGo'))) return false;
	if (!(countryLinks = whereToGo.getElementsByTagName('a'))) return false;
	for (c=0; c<countryLinks.length; c++) {
		if (countryLinks[c].className.indexOf("swapImg") == -1) continue;
		var country = countryLinks[c];
		country.cImage = countryToGo;		// reference to country image
		//country.cName = country.innerHTML;	// country name
		dest = country.href;
		//country.cName = dest.substring(dest.lastIndexOf("/")).replace("/2_destination_","").replace("_","");	// country name
		country.cName = dest.substring(dest.lastIndexOf("/")).replace("/2_","").replace("_tourist_information","").replace("_","");	// country name
		country.defSrc = countryToGo.src;	// default src
		country.hoverSrc = imgPath + imgPrepend + country.cName.replace(/\s+/g,'_').toLowerCase() + ".jpg";
		countryImg = new Image();	
		countryImg.src = country.hoverSrc;	// preload hover image
		country.onmouseover = function() {
			this.cImage.src = this.hoverSrc;
			this.cImage.alt = this.cName;
		}
		country.onmouseout = function() {
			this.cImage.src = this.defSrc;
			this.cImage.alt = "";
		}
	}
}


/* --- call functions only if the used methods are supported --- */
if (document.getElementById && document.getElementsByTagName) {
	addLoadEvent(initWhere2Go);
}