var tr = {
	
	SETTINGS: {
		lang: null
	},
	
	TEXT: {
		FR: {
			Product:		'Produit',
			Country:		'Pays',
			Usage:			'Usage',
			Project:		'Projet',
			Architect:		'Architecte',
			Location:		'Emplacement',
		},
		DE: {
			Product:		'Produkt',
			Country:		'Land',
			Usage:			'Usage',
			Project:		'Projekt',
			Architect:		'Architekt',
			Location:		'Standort',
		}
	},
	
	init: function() {
		tr.SETTINGS.lang = tr.getLanguage();
		
		if(null !== tr.SETTINGS.lang) {
			tr.replaceText();
		}
	},
	
	getLanguage: function() {
		var language = $('.language-link.active').text();
		if(language == 'Français') {
			return 'FR';
		} else if(language == 'Deutsch') {
			return 'DE';
		}
		return null;
	},
	
	replaceText: function() {
		// first replace the top elements
		var topBase = $('.view-ReferenceList .views-exposed-form .views-exposed-widget:not(:has(.form-button))');
		topBase.each(function(index) {
			var label = $(this).find('label');
			var text = jQuery.trim(label.text());
			label.html(tr.TEXT[tr.SETTINGS.lang][text]);
		});
		
		
		// first three in thead
		var headerBase = $('.view-ReferenceList table thead');
		headerBase.find('th a').each(function(index) {
			var img = $(this).find('img');
			var text = jQuery.trim($(this).text());
			$(this).html(tr.TEXT[tr.SETTINGS.lang][text]);
			if(img) {
				$(this).append(img);
			}
		});
		
		// and the last one in the thead
		headerBase.find('th.tid').html(tr.TEXT[tr.SETTINGS.lang]['Product']);
		
	}
}



jQuery(document).ready(function($) {
	tr.init();
});
