// JavaScript Document
function textsplit(divId, charsMax, prevText, nextText){
	if(prevText == undefined){
		prevText = '<';
	}
	if(nextText == undefined){
		nextText = '>';
	}
	
	
	domObj = $('#'+divId);
	texte = domObj.html();
	textsplitSeq = new Array();
	while (texte.length>0){
		// on cherche la rupture
		pos1 = texte.indexOf('<br>', charsMax);
		if(pos1 == -1){
			pos1 = texte.length;
		} else {
			pos1 += 4;
		}
		pos2 = texte.indexOf('. ', charsMax);
		if(pos2 == -1){
			pos2 = texte.length;
		} else {
			pos2 += 2;
		}
		pos = Math.min(pos1, pos2);
		// on coupe, et on rec le début dans le tableau
		textsplitSeq.push(texte.substr(0, pos));					
		// on ampute le texte
		texte = texte.substr(pos, texte.length-pos);
	}
	domObj.html(textsplitSeq[0]);	
	
	// pour la nav
	textsplit_rank = 0;
	textsplit_obj = domObj;
	
	// menu de nav
	//domObj.append('<p>&nbsp;</p><a href="javascript:textsplitPrev();"><</a><a href="javascript:textsplitNext();" style="margin-left:40px;">></a>');
	textsplitCheckNav();
}
function textsplit_counter(){
	return '<span style="margin-left:30px;">'+(textsplit_rank+1)+'/'+textsplitSeq.length+'</span>';
}
function textsplitCheckNav(){
	if(textsplit_rank == 0){
		// on cache le prev
		textsplit_obj.append('<p>&nbsp;</p><span style="color:#888888;"><</span>'+textsplit_counter()+'<a href="javascript:textsplitNext();" style="margin-left:30px;">></a>');
	} else if(textsplit_rank >= textsplitSeq.length-1){
		// on cache le next
		textsplit_obj.append('<p>&nbsp;</p><a href="javascript:textsplitPrev();"><</a>'+textsplit_counter()+'<span style="color:#888888; margin-left:30px;">></a>');
	} else {
		textsplit_obj.append('<p>&nbsp;</p><a href="javascript:textsplitPrev();"><</a>'+textsplit_counter()+'<a href="javascript:textsplitNext();" style="margin-left:30px;">></a>');
	}
}
function textsplitPrev(){
	textsplit_rank--;
	textsplit_obj.html(textsplitSeq[textsplit_rank]);
	textsplitCheckNav();

}
function textsplitNext(){
	textsplit_rank++;
	textsplit_obj.html(textsplitSeq[textsplit_rank]);
	textsplitCheckNav();
}
