/*
 * widgets.js
 * requiert jQuery - http://jquery.com
 */

// Niveaux de redimensionnement du texte
var textSize = ['largest', 'large', 'medium'];

// Taille du texte par defaut
var currentSize = 'medium';

// Traductions des attributs "title"
var strPrint = {
	fr: 'Imprimer ce document',
	en: 'Print this document',
	es: 'Imprimir este documento',
	it: 'Stampare questo documento',
	de: 'Dieses Dokument zu drucken'
	};

var strTextSize = {
	medium: {
		fr: 'Taille du texte : normale',
		en: 'Normal text size',
		es: 'Tama\u00F1o del texto : normal',
		it: 'Testo di taglia normale',
		de: 'Textgr\u00F6\u00DFe : normal'
		},
	large: {
		fr: 'Taille du texte : grande',
		en: 'Large text size',
		es: 'Tama\u00F1o del texto : grande',
		it: 'Testo di taglia grande',
		de: 'Textgr\u00F6\u00DFe : gro\u00DF'
		},
	largest: {
		fr: 'Taille du texte : tr\u00E8s grande',
		en: 'Largest text size',
		es: 'Tama\u00F1o del texto : muy grande',
		it: 'Testo di taglia grandissima',
		de: 'Textgr\u00F6\u00DFe : klein'
		}
	};

// Langue du document
var lang = $('html').attr('lang');

$(document).ready(function() {
	
	// Fall-back pour traductions
	if (strPrint[lang] === undefined)
		lang = 'fr';
	
	// Bouton Imprimer
	$('<a></a>')
		.appendTo('#widgets')
		.attr('id', 'wPrint')
		.attr('href', document.location)
		.attr('title', strPrint[lang])
		.bind('click', function() {
			window.print();
			return false;
		});
	
	// Boutons Taille du texte
	if (true === $('#widgets').hasClass('text')) {
		for (var i in textSize) {
			$('<a></a>')
				.appendTo('#widgets')
				.attr('id', 'wTextSize-' + textSize[i])
				.attr('href', document.location)
				.attr('title', strTextSize[textSize[i]][lang])
				.bind('click', {size:textSize[i]}, setTextSize);
		}
		// Taille du texte par defaut
		$('div.wResizable').addClass(currentSize);
		$('a#wTextSize-' + currentSize).addClass('current');
	}
	
});

// Redimensionne le texte
function setTextSize(e) {
	$('div.wResizable').removeClass(currentSize).addClass(e.data.size);
	$(this).addClass('current').siblings().removeClass('current');
	currentSize = e.data.size;
	return false;
}
