//if (!App.jquery) { LoadJS('/biblio/pgm/jquery/jquery-1.4.1.min');  LoadJS('/biblio/pgm/jquery/jquery.cycle.all.2.72');  App.jquery = 1 }
function OpenWin(Cle,Param,Opt) {
	var D, tp, JS, Nom, O, JS
	Nom = 'Win_'+Cle;  if (!Param)  Param = ",,720,580";  if (!Opt)  Opt={}
	if ((D=LID(Nom))){
		$(D).dialog('open')
	}else{
		tp = Param.split(',')
		D = MakeDom('div',null,{id:Nom});  JS = { width:ze(tp[2]), height:ze(tp[3]), modal:true };  if (tp[0])  JS.position = [tp[0],tp[1]]
	  D.Win = $(D).dialog(JS);
	  $(D).bind( "dialogclose", function(event, ui) {
			if ((O=this.SlideObj) && O.idProg)  clearInterval(O.idProg)
			$(this).dialog('destroy');  RMNod(this)
		});
	  if (App.SIP) {
			JS = { Action:'Win', ValCle:Cle, Zone:Nom }
			Heriter(JS, Opt.jsAct)
			ExecAction([JS],null,{noPush:1, Suite:function () { ToutAnims(D)} })
		}else
			ExecAction({ Action:'ListData',ValCle:Cle,Zone:Nom })
	}
}

function ToutAnims(D) {
	PreparAnims()
	Tables_to_Diapo()
	Tables_to_Slide(D)
	Tables_to_Accordeon(D)
	Tables_to_Tabs(D)
}

function PreparAnims() {
	//Repère les widgets en fonction du contenu widget= et les prépare pour les autres transformateurs (Table contenu avec classe info_nom-widget et pointeur sur container)
	//  Contenu   : <table class=Widget> : 1° cell=>nom=anim; widget=slide, autres cells : contenu widget
	//  Container : <div class=Widget style="width:700px; height:270px;">widget=anim</div>
	var Inf
	$("TABLE.Widget:contains('widget=')").each(function() {
	  var TA = this, D, Nom, Wid, S, T
		S = LText(this.rows[0].cells[0])
		T = Tableau1D(S, '=;')
		Nom = T.nom;
		Wid = T.widget
		AddClass(TA,'info_'+Wid)
		//alert(Nom+crr+Wid+crr+S)
		//Inf = S.split('\n');  alert(Inf[0])
		$(".Widget:contains('widget="+Nom+"')").each(function() {
			Aff(this)
			TA.DivWid = this;  this.TInfo = TA;		//alert(Lout(this))
		})
	})
}


// --------   Cross Slide   ------- dias animées par zoom ------
//T_Crosslide = [ { from:'100% 80% 1x', to:'100% 0% 1.7x', time:3 }, { from:'top left', to:'bottom right 1.5x', time:2 }, { from:'100% 80% 1.5x', to:'80% 0% 1.1x', time:2 }, { from:'100% 50%', to:'30% 50% 1.5x', time:2 } ]
T_Crosslide = [ { from:'top right 0.8x', to:'50% 0% 1.5x', time:3 }, { from:'top left', to:'75% 100% 1.5x', time:2 }, { from:'100% 80% 1.5x', to:'80% 0% 1.1x', time:2 }, { from:'100% 50%', to:'30% 50% 1.5x', time:2 } ]

function Tables_to_Diapo(Div) {
	var i, j, T, Ta, Is, JS, J, TI=[], D, S
	T = $('.info_diapo').get(); 		//for (i in T)  alert(Lout(T[i]))
	for (i in T) {
		Ta = T[i];  S = Isole(Ta.id,'_',1);  if (!(D=LID(S)))  continue
		Table_to_Diapo_Div(Ta,D)
	}
}

function Table_to_Diapo_Div(So, De, Tanim) {
	var i, j, T, Is, JS, J, TI=[], S
	if (!Tanim)  Tanim = T_Crosslide
	Is = $('img',So).get();
	JS = { fade:1 }
	//alert(JSW(Tanim))
	for (j=0; j<Is.length; j++) {
		J = Tanim[j%4];  J.src = Is[j].src
		TI.push(J)
	}
	$(function() { $(De).crossSlide(JS,TI) })
}


// --------   Cross Slide   ------- images déjà dans la div ------
function Div_Images(D) {
	var i, Is, JS, J, TI=[]
	D = $g(D)
	Is = $('img',D).get();  if (Is.length<2)  return
	//for (i in Is)  alert(Lout(Is[i])+crr+Lout(D))
	JS = { fade:1 }
	for (i=0; i<Is.length; i++) {
		J = T_Crosslide[i%4];  J.src = Is[i].href
		TI.push(J)
	}
	$(function() { $(D).crossSlide(JS,TI) })
	//if (!App.jquery) { LoadJS('/biblio/pgm/jquery/jquery-1.4.1.min');  LoadJS('/biblio/pgm/jquery/jquery.cycle.all.2.72');  App.jquery = 1 }
}

// --------   SLIDE   ------- défilement simple mais fluide ------
function Tables_to_Slide(Div) {
	var T, Ta, i, l, D, DD, nb, nbDia, O, S, H, Tit
	T = $('.info_slide',Div).get();		//alert(TypOf(T)+crr+T.length+crr+Lout(T[0]))
	for (i in T) {
		Ta = T[i];  if (!(D=Ta.DivWid)) { S = Isole(Ta.id,'_',1);  if (!(D=LID(S)))  continue }
		D.innerHTML = '';  W = D.offsetWidth
		$(D).css('overflow', 'hidden')
		DD = MakeDom('div',D,{Class:'slideIn'})
		S = LText(Ta.rows[0].cells[0])
		l = (S.indexOf('=')) ? 1:0
		for (nbDia=0, nb=Ta.rows.length; l<nb; l+=2) {
			Tit = LText(Ta.rows[l].cells[0]);  if (!Tit)  continue;
			if ((l+1)<nb)  H = Ta.rows[l+1].cells[0].innerHTML;
			O = MakeDom('div',DD,{Class:'dia'});  PX(O,'Lib',Tit)
			$(O).css({'float':'left', 'width':W})
			O.innerHTML = H
			nbDia++
		}
		$(DD).css('width', W * nbDia)
		var sl = new SlideClass(D,{Win:Div, W:W})
	}
}

var SlideClass = function(Div, Proto) {
	this.Div = Div
	this.delai = 4
	this.no = 1
	this.W
	this.SlideIn = $('.slideIn',this.Div);  if (!this.SlideIn.length) { alert("Aucun diaporama trouvé");  return }
	this.Dias = $('.dia',this.SlideIn)
	this.nb = this.Dias.length
	if (Proto)  for (var K in Proto)  this[K] = Proto[K]
	if (this.Win)  this.Win.SlideObj = this
	this.Titre()
	if (this.delai) { var Me = this;  this.idProg = setInterval( function() { Me.Anim('D') } , this.delai*1000); }
}

SlideClass.prototype.Anim = function(dir) {
	if (this.delai) { if (this.no==this.nb)  this.no = 0 }
	if (dir=='D') {
		if (this.no<this.nb)  this.no++
	}else{
		if (this.no>1)  this.no--
	}
	this.Titre()
	this.SlideIn.animate({ 'marginLeft':this.W*(-(this.no-1)) });
}

SlideClass.prototype.Titre = function() {
	if (!this.Win)  return
	var D = this.Dias.get(this.no-1)
//alert(Lout(D))
	//var D = PosIndex(this.SlideIn.get(0),this.no-1)
	$(this.Win).dialog("option", "title", '(' + this.no+'/'+this.nb+') &nbsp;&nbsp;' + LX(D,'Lib'))
}

// --------   ACCORDEON   -------------------
function Tables_to_Accordeon(Div) {
	var T, Ta, i, l, TD, D, nb, h3, O, S, H, DestAnim, deb, TV
	T = $('.info_accordeon',Div).get(); 		//for (i in T)  alert(Lout(T[i]))
	for (i in T) {
		Ta = T[i];  if (!(D=Ta.DivWid)) { S = Isole(Ta.id,'_',1);  if (!(D=LID(S)))  continue }
		D.innerHTML = ''
		S = LText(Ta.rows[0].cells[0])
		if (S.indexOf('widget=')<0)
			deb = 0
		else{
			deb = 1
			if ((S=VarListe(S, 'anim', ';'))) {   //ex : anim=100% 80% 1x,100% 0% 1.7x,3: top left,bottom right 1.5x,2
				TD = S.split(':');  TV = []
				for (l in TD) {
					S = Trim(TD[l])
					h3 = S.split(',')
					TV.push({ from:Trim(h3[0]), to:Trim(h3[1]), time:ze(h3[2]) })
				}
				//alert(JSW(TV))
			}
		}
		for (l=deb, nb=Ta.rows.length; l<nb; l++) {
			TD = Ta.rows[l].cells[0];  H = TD.innerHTML;  if (!Trim(LText(TD)) && H.length<10)  H=''    // Pour supprimer les &nbsp; d'une TD vide pas vraiment vide
			if ((l-deb)%2) {
				O = MakeDom('div',D);  O.innerHTML = H
			}else{
				h3 = MakeDom('h3',D)
				O = MakeDom('a',h3,{href:'#'});  O.innerHTML = TD.innerHTML
			}
			if (l==deb+1 && !H) { DestAnim = O }
		}
		$(D).accordion();
		if (DestAnim)  Table_to_Diapo_Div(Ta, DestAnim, TV);
		RMNod(Ta)
	}
}

// --------  Système à onglet   ----------------
function Tables_to_Tabs(Div) {
	var T, i, l, TD, nb, ul, li, D, div, O, Nom, id, H, DestAnim
	T = $('.info_tabs',Div).get(); 		//for (i in T)  alert(Lout(T[i]))
		//alert(TypOf(T)+crr+T.length+crr+Lout(Div))
	for (i in T) {
		Ta = T[i];  Nom = Isole(Ta.id,'_',1);  if (!(D=LID(Nom)))  continue
		D.innerHTML = ''
		ul = MakeDom('ul',D);  div = MakeDom('div',D);
		for (l=0, nb=Ta.rows.length; l<nb; l++) {
			TD = Ta.rows[l].cells[0];  H = TD.innerHTML;  if (!Trim(LText(TD)) && H.length<10)  H=''
			if (l%2) {
				O = MakeDom('div',div,{id:id});  O.innerHTML = H
			}else{
				id = Nom + '_' + l
				li = MakeDom('li',ul);  O = MakeDom('a',li,{href:'#'+id},LText(TD))
			}
			if (l==1 && !H) { DestAnim = O }
		}
		$(D).tabs();
		if (DestAnim) {
			DestAnim.style.width = (D.offsetWidth-20)+'px';  DestAnim.style.height = (D.offsetHeight-60)+'px';
			Table_to_Diapo_Div(Ta,DestAnim);
		}
		RMNod(Ta)
	}
}

