window.onload = init;

function init(){
	if (document.getElementById('spectacles')) {
		var class_attr_name = (document.getElementById('spectacles').getAttribute('class') == 'test' ? 'class' : 'className');
		
		liens_vignettes = document.getElementById('bandeau-images').getElementsByTagName('a');
		nb	= liens_vignettes.length;
		nb	= 0; /* shunte le hover sur les vignettes */
		for (i = 0; i < nb; i++) {
			if (liens_vignettes[i].getAttribute(class_attr_name) == 'vignette') {
				liens_vignettes[i].onmouseover = function (){
					hide_zoomed();
					
					this.onmouseout = function (){
						hide_zoomed();
					}
					
					image_zoom = zoom = this.getElementsByTagName('img')[0].cloneNode(true);
					/* place l'image dans le div zoomed */
					if (document.getElementById("zoomed")) {
						document.getElementById("zoomed").style.display = 'block';
						image_zoom.style.display = 'block';
						document.getElementById("zoomed").appendChild(image_zoom);
					} else {
						alert('pas de div zoomed');
					}
				}
			}
		}
	}
	
	
	images_file_url = $('input[@id=url_site_spip]').attr('value') + '/IMG/titres/titres.php';
	
	$('div[@id=nav-top] a').each(
		function(i){
			link 		= $('div[@id=nav-top]/a:eq('+ i +')');
			text		= link.html();
			img_url		= images_file_url + '?' + 'text='+escape(text)+'&font_size=18&font_family=english';
			link.append('<span>&nbsp;</span>');
			link.children('span').css('background-image', 'url('+img_url+')');
			link.bind('click', function(){
				this.blur();	
			});
			//$('body').append(img_url + '<br/>');
		}
	);
	
	//titres_h1	= $('h1');
	titre	= $('span[@id=nom-site]');
	text	= titre.html();
	img_url		= images_file_url + '?' + 'text='+escape(text)+'&font_size=32&font_family=english';
			
	titre.append('<span>&nbsp;</span>');
	titre.children('span').css('background-image', 'url('+img_url+')');
	
	if ($('fieldset[@class=previsu]').length > 0){
		$('form fieldset:eq(2)').css('display', 'none');
		$('form fieldset[@class=previsu] div[@class=spip_bouton] input').css('color', '#F00');
		$('form fieldset[@class=previsu] div[@class=spip_bouton] input').css('border', '1px solid #F00');
	}
}

/*#top #nav-top a span{
	
}*/

/*function replace_text(images_file_url, elements){
	//alert(elements.length);
	
	nb = elements.length;
	
	for (i = 0; i < 1; i++) {
			alert(elements[i].nodeName);
			alert(elements[i].style.getPropertyValue('font-size'));
			//alert(this.css('font-family'));
		//font_family = this.attr('font_family');
		//alert(font_family);
		/*$font_file  				= isset($_GET['font_family']) ? trim($_GET['font']).'.ttf' : 'english.ttf';
$font_size  				= isset($_GET['font_size']) ? (int)$_GET['font_size'] : 11;
$font_color 				= isset($_GET['color']) ? '#'.$_GET['color'] : '#000000';
$background_color			= isset($_GET['background_color']) ? '#'.$_GET['background_color'] : '#ffffff' ;
*/		
/*	}
}*/

function hide_zoomed(){
	if (document.getElementById("zoomed")) {
		//alert('hide');
		images_zoom = document.getElementById("zoomed").getElementsByTagName('img');
		for (var i = 0; i < images_zoom.length; i++) {
			images_zoom[i].style.display = 'none';
		}
	}
}