function gt_getChild(obj, index, tagName) {
	var children = obj.childNodes;
	var cpt = -1;
	for ( var i = 0; i < children.length; i++ ) {
		if ( children[i].tagName == tagName ) {
			cpt++;
			if ( cpt == index )
				return children[i];
		}
	}
	return null;
}
function gt_show(thumb_id, index) {
	var thumb = document.getElementById(thumb_id);
	var gt_main   = gt_getChild(thumb  , 0, 'DIV');
	var gt_top    = gt_getChild(gt_main, 0, 'DIV');
	var gt_bottom = gt_getChild(gt_main, 1, 'DIV');
	var gt_img    = gt_getChild(gt_top , 0, 'DIV');
	var gt_descr  = gt_getChild(gt_top , 1, 'DIV');

	for ( var i = 0; i < gt_img.childNodes.length; i++ ) {
		gt_getChild(gt_img,   i, 'IMG').style.display   = (i==index) ? 'block' : 'none';
		gt_getChild(gt_descr, i, 'DIV').style.display   = (i==index) ? 'block' : 'none';
	}
}
function gt_init(thumb_id, imgs) {
	var thumb = document.getElementById(thumb_id);

	// Récupère les descriptions
	var children = thumb.childNodes;
	var descrs = new Array();
	for ( var i = 0; i < children.length; i++ ) {
		if ( children[i].tagName == 'DIV' )
			descrs[descrs.length] = children[i].innerHTML;
	}
	if ( descrs.length != imgs.length ) {
		alert("Le nombre d'images ne correspond pas au nombre de descriptions.");
		return;
	}

	// Remplace le thumb
	thumb.innerHTML = 
		'<div class="gt_main">'+
		'	<div class="gt_top">'+
		'		<div class="gt_img"></div>'+
		'		<div class="gt_descr"></div>'+
		'	</div>'+
		'	<div class="gt_bottom">'+
		'	</div><div style="clear:left"></div>'+
		'</div>';
	
	var gt_main   = gt_getChild(thumb  , 0, 'DIV');
	var gt_top    = gt_getChild(gt_main, 0, 'DIV');
	var gt_bottom = gt_getChild(gt_main, 1, 'DIV');
	var gt_img    = gt_getChild(gt_top , 0, 'DIV');
	var gt_descr  = gt_getChild(gt_top , 1, 'DIV');

	for ( var i = 0; i < imgs.length; i++ )	{
		// Insère les miniatures
		var addStyle = ( i == imgs.length-1 ) ? 'margin-right: 0' : '';
		gt_bottom.innerHTML += '<a href="#" onclick="gt_show(\''+thumb_id+'\', '+i+'); return false;" style="display:block; float: left; display: block; overflow: hidden;'+addStyle+'"><img src="'+imgs[i]+'" border="0"></a>';

		// Insère les images
		gt_img.innerHTML    += '<img src="'+imgs[i]+'" style="display: none"/>';

		// Insère les descriptions
		gt_descr.innerHTML  += '<div style="display: none">'+descrs[i]+'</div>';
	}

	gt_show( thumb_id, 0 );
	thumb.style.display = 'block';
}

