(function(jQuery){

	// declaring an TT namespace for functions
	if(!jQuery.TT) jQuery.TT = {};

	// delcare a TT i18n namespace
	jQuery.TT.i18n = {};

	// object literal to be filled with locales that are hosted outside of TT
	jQuery.TT.i18n.Domains = {};

	// method to assign onchange event handler to the i18n slect box
	jQuery(function(){

		jQuery('#i18n-select').change(function(){
			var lid = jQuery(this).val();
			var url = jQuery.TT.i18n.Domains[lid];

			if(!url) {
				var script = document.location.pathname;
				var query = document.location.search;

				if(!query) {
					query = '?Lid='+lid;
				} else if (query.match(/Lid=\d+/)) {
					query = query.replace (/Lid=\d+/,'Lid='+lid);
				} else {
					query += '&Lid='+lid;
				}

				url = script + query;
			}

			document.location.href = url;
		});
	});

})(jQuery);
