/*
language menu by Ing. Michal Hasko, Slovakia Supercomputers
*/

var flag_path = 'http://' + location.host + '/javascript/flags/';
var used_flags = 0;
var timer;
var flags_icons = new Array();
flags_icons.push(new Array('fr', flag_path + 'flag_fr_no_arrow.png', flag_path + 'flag_fr_arrow.png', 'French'));
//flags_icons.push(new Array('de', flag_path + 'flag_de_no_arrow.png', flag_path + 'flag_de_arrow.png', 'German'));
//flags_icons.push(new Array('es', flag_path + 'flag_sp_no_arrow.png', flag_path + 'flag_sp_arrow.png', 'Spanish'));
flags_icons.push(new Array('en', flag_path + 'flag_uk_no_arrow.png', flag_path + 'flag_uk_arrow.png', 'English'));
flags_icons.push(new Array('en', flag_path + 'flag_us_no_arrow.png', flag_path + 'flag_us_arrow.png', 'English'));



function show_flags(visibility)
{
	used_flags = 0;
	
	if(visibility == true)
	{
		document.getElementById("flags").innerHTML = '';
		for(i=0; i<flags_icons.length; i++)
		{
			//if(flags_icons[i][0] != current_language)
			{	
				document.getElementById("flags").innerHTML += '<img src="' + flags_icons[i][1] + '" id="lang_flag_' + flags_icons[i][0] + '" class="lang_flag" width="30px" height="20px" onclick="flag_click(\'' + flags_icons[i][0] + '\')" onmouseover="flag_on_mouse_over(this)" onmouseout="flag_on_mouse_out(this)" title="' + flags_icons[i][3] + '"/><br>';
				used_flags++;
			}
		}
		for(i=0; i<flags_icons.length; i++)
		{
			if(flags_icons[i][0] == current_language)
			{	
				document.getElementById("flags").innerHTML += '<img src="' + flags_icons[i][2] + '" id="current_lang_flag" class="lang_flag" width="30px" height="20px" onclick="show_flags(false)" onmouseover="flag_on_mouse_over(this)" onmouseout="flag_on_mouse_out(this)" title="' + flags_icons[i][3] + '"/><br>';
				used_flags++;
				break;
			}
		}
		document.getElementById("flags").style.background = "#FAE0AF";
	}
	else
	{
		for(i=0; i<flags_icons.length; i++)
		{
			if(flags_icons[i][0] == current_language)
			{	
				document.getElementById("flags").innerHTML = '<img src="' + flags_icons[i][2] + '" id="current_lang_flag" class="lang_flag" width="30px" height="20px" onclick="show_flags(true)"/><br>';
				used_flags++
				break;
			}
		}
		document.getElementById("flags").style.background = "";
	}
	
	document.getElementById("flags").style.height = (used_flags*26) + "px";
	if(navigator.appName.toUpperCase().search('EXPLORER') != -1)
	{
		//alert('explorer');
		document.getElementById("flags").style.top = "-15px";
	}
	else
	{
		//alert('not explorer');
		document.getElementById("flags").style.top = (-15-(used_flags-1)*26) + "px";
	}
}

function flag_click(flag_lang)
{
	//alert(flag_lang);
	show_flags(false);
	self.location = "/" + flag_lang;
}

function flag_on_mouse_over(flag)
{
	flag.style.background = "#F7BA4A";
}

function flag_on_mouse_out(flag)
{
	flag.style.background = "";
}

function create_flag_menu(itemid)
{
	document.getElementById(itemid).innerHTML = '<div id="flags" onmouseout="start_timer(1000, \'show_flags(false)\');" onmouseover="stop_timer();"></div>';
	document.getElementById("flags").style.position = "relative";
	document.getElementById("flags").style.left = "-35px";
	document.getElementById("flags").style.top = "-15px";
	document.getElementById("flags").style.width = "36px";
	document.getElementById("flags").style.height = "26px";
	document.getElementById("flags").style.overflow = "hidden";
	document.getElementById("flags").style.cursor = "pointer";
	document.getElementById("flags").style.zIndex = 100;
	show_flags(false);
}

function start_timer(time, action)
{
	timer = setTimeout(action, time);
}

function stop_timer()
{
	clearTimeout(timer);
}
