$(document).ready(function() {
	if(navigator.userAgent.indexOf("MSIE 6")!=-1) {
		$('#header-location').css("right","-2px");
	}
	$('#header-location-clickable').click(function (){
		$('#header-location-choices').toggle();
		choose_location();
	});
	$('#country-choice').change(function() {
		country_changed();
		set_languages(false);
	});
	set_languages(true);
});

function choose_location() {
	if($('#header-location')[0].offsetHeight==141) {
		$('#header-location').css({"height":"20px", "background-image":"url(/img/location-bg.png)"});
	} else {
		$('#header-location').css({"height":"141px", "background-image":"url(/img/location-open-bg.png)"});
	}
}

function country_changed() {
	var countryName = $('#country-choice')[0].options[$('#country-choice')[0].selectedIndex].text.toUpperCase();
    if(countryName.indexOf(" (")!=-1)
		countryName = countryName.substring(0, countryName.indexOf(" ("));
	$('#current-country-name')[0].innerHTML = countryName;
	$('#current-country-flag')[0].src = "/img/loc/Flag_"+$('#country-choice')[0].options[$('#country-choice')[0].selectedIndex].value+".jpg";
	// force a redraw
	document.body.className="";
}

function set_languages(bArg) {
    if (bArg) {
        for (var m in objRegions) {
            if(objRegions[m][sSelectedLocale]) {
                $('#country-choice').val(m);
                country_changed();
                break;
            }
        }
    }
	sRegion = $('#country-choice option:selected').val();
	objSelect = $('#lang');
	objSelect.removeOption(/./);
	for (var i in objRegions[sRegion]) {
        if (sSelectedLocale == i) {
            objSelect.addOption(i, objRegions[sRegion][i], true);
        } else {
            objSelect.addOption(i, objRegions[sRegion][i], false);
        }
		
	}
	
}
