var PopLocale = Class.create();
Object.extend(PopLocale.prototype, {

	initialize: function()
	{
		Event.observe(window, 'load', this.onLoad.bind(this));
		this.popup = null;
	},
	
	onLoad: function()
	{
		
		$$('div#footer_languages li a').each(function(item) {
			if($(item).readAttribute('href') == '#') {
			
				item.observe('click', this.onClick.bindAsEventListener(this));
				item.setStyle({position: 'relative'});
			}
		}, this)
	},
	
	onClick: function(e) 
	{
		e.stop();
		this.showPopup($(e.findElement('a')));
	},
	
	getText: function(key)
	{
		var texts = {
			'FR': "Bientôt en ligne",
			'DE': "In Kürze online",
			'ES': "Pronto en línea",
			'IT': "Presto in linea"
		};
		
		return texts[key];
	},
	
	showPopup: function(item)
	{
		if(this.popup != null) {
			clearTimeout(this.delay);
			this.popup.remove();
		}
		
		this.popup = new Element('div')
			.addClassName('popup-locale')
			.update(this.getText(item.innerHTML));	
		
		$(item).up('div').insert(this.popup);
		
		this.launchCountdown();
	},
	
	
	launchCountdown: function()
	{
		this.delay = setTimeout(this.destroyPopup.bind(this), 1500);
	},
	
	destroyPopup: function()
	{
		this.popup.remove();
		this.popup = null;
	}
	
	
})

new PopLocale();