	// requires browser.js
        // Variable open generated by XSLT

	function transit(imgid, img_down, img_up, othid, oth_down, oth_up, param) {

//		alert("|"+imgid);
//		alert(imgid+"\t"+img_down+"\t"+img_up+"\n"+othid+"\t"+oth_down+"\t"+oth_up+"\n"+param);

		// parameters 1-3 are span ids for the three flags (coloured, black and white and waving) 
		// of the target (clicked) language, then 4-6 are the same for the current (waving) language
		// the last parameter is the clicked language code

		// check that the click is from the coloured flag in its down position
		if (getObject(imgid).style.left == getObject(img_down).style.left 
			&& getObject(imgid).style.top == getObject(img_down).style.top) {
			
			getObject(img_down).style.display = ''; // show the black and white flag
			getObject(oth_up).style.display = 'none'; // hide the waving flag...
			getObject(othid).style.display = ''; // ... replacing it with the coloured flag
		
			// start both flags moving
			window.setTimeout('doTransit(\'' + imgid + '\', \'' + img_up + '\', \'' + img_down + '\', true, \'' + param + '\')',10);
			window.setTimeout('doTransit(\'' + othid + '\', \'' + oth_up + '\', \'' + oth_down + '\', false, \'' + param + '\')',10);
		}
	}
	function getPixels(str) {
		var n = str.length;
		if (n > 2) {
			if (str.substring(n - 2, n) == "px") {
				return parseInt(str.substring(0, n - 2));
			} else {
				alert("Bad string " + str);
			}
		} else {
			alert("Short string " + str);
		}
	}
	function doTransit(imgid, img_up, img_down, bRaise, param) {		
		var stl = getObject(imgid).style; // style object to be manipulated
		var left = getPixels(stl.left);
		var top = getPixels(stl.top);
		if (bRaise) { // flag being raised
			if (left > getPixels(getObject(img_up).style.left)) { // first move to the left...
				stl.left = (left - 1) + "px";
				window.setTimeout('doTransit(\'' + imgid + '\', \'' + img_up + '\', \'' + img_down + '\', true, \'' + param + '\')',10);
			}
			else if (top > getPixels(getObject(img_up).style.top)) { // ... then move up...
				stl.top = (top - 1) + "px";
				window.setTimeout('doTransit(\'' + imgid + '\', \'' + img_up + '\', \'' + img_down + '\', true, \'' + param + '\')',10);
			}
			else { // ... then show the waving flag and go to the next page
				getObject(img_up).style.display = ''; // show the waving flag
				stl.display = 'none'; // hide the coloured flag
				window.setTimeout('doneTransit(\'' + param + '\')', 1000); // change page
			}
		}
		else { // flag being lowered
			if (top < getPixels(getObject(img_down).style.top)) { // first move down...
				stl.top = (top + 1) + "px";
				window.setTimeout('doTransit(\'' + imgid + '\', \'' + img_up + '\', \'' + img_down + '\', false, \'' + param + '\')',10);
			}
			else if (left < getPixels(getObject(img_down).style.left)) { // ... then move right...
				stl.left = (left + 1) + "px";
				window.setTimeout('doTransit(\'' + imgid + '\', \'' + img_up + '\', \'' + img_down + '\', false, \'' + param + '\')',10);
			}
			else { // ... then hide the black and white flag
				getObject(img_down).style.display = 'none';
			}
		}
	}
	function doneTransit(param) {
		var newSearch = "?language=" + param;
                var newGroup = open ? "&group=" + open : "";
		
		// find the page param if it exists
		var query = location.search.substring(1);
		var pairs = query.split("&");
		for (var i = 0; i < pairs.length; i++) {
			var pos = pairs[i].indexOf('=');
			if (pos == -1) continue;
			if (pairs[i].substring(0, pos) == 'page') {
				newSearch += "&page=" + pairs[i].substring(pos + 1);
				break;
			}			
		}
                newSearch += newGroup;
		window.navigate(window.location.search = newSearch);
	}

