var dia = null;
var dia_pause = 3000; // temps de pause en ms
var dia_trans = 0.15; // vitesse transition

function dia_init(){
	dia = document.getElementById("diapo");
	dia_check_saf();
	dia.foc = document.getElementById("dia_focus");
	dia.th = document.getElementById("dia_thumbs");
	dia.act = document.getElementById("dia_actions");
	dia.th.scrollLeft = 0;
	dia.cur = -1;
	dia.tm = null;
	dia.col = dia.th.getElementsByTagName("LI");
	dia.len = (dia.col.length-1);
	rangestep = (parseInt(dia.th.scrollWidth)-parseInt(dia.th.offsetWidth))/dia.len;
	for(var i=0;i<(dia.len+1);i++){
		liobj = dia.col[i];
		liobj.ind = i;
		liobj.xval = parseInt(i*rangestep);
		liobj.prt = dia;
		liobj.cont = liobj.innerHTML;
		liobj.onclick = function(){
			dia_focus(this.ind);
		}
		dia_resize(dia.col[i].getElementsByTagName("IMG")[0]);
	}
	onresize = dia_upd_steps;
	dia_focus(0);
}
function dia_resize(obj){
	if(!obj) return;
	var w_max = 155;
	var h_max = 115;
	
	var w = obj.attributes['width'].value;
	var h = obj.attributes['height'].value;
	
	var h_new = parseInt(h * w_max / w);

	if(h_new > h_max)h_new = h_max;
	else h_new = h_new;

	var w_new = parseInt(w * h_new / h);

	if(w_new > w_max) w_new = w_max;
	else w_new = w_new;
	
	obj.width = w_new;
	obj.height = h_new;

}

function dia_check_saf(){

	if(!document.all){
		dia.style.display = 'none';
		
		if(dia.parentNode.offsetWidth-20 < 330)
			dia.style.width = "330px";
		else
			dia.style.width = (dia.parentNode.offsetWidth-20) + 'px';
		dia.style.display = 'block';
	}	
}

function dia_upd_steps(){
	dia_check_saf();
	rangestep = (parseInt(dia.th.scrollWidth)-parseInt(dia.th.offsetWidth))/dia.len;
	for(var i=0;i<(dia.len+1);i++)
		dia.col[i].xval = parseInt(i*rangestep);
}

function dia_focus(lind){
	dia.foc.innerHTML = dia.col[lind].cont;
	if(dia.cur>=0){
		if(dia.cur==lind)
			return;
		else
			dia.col[dia.cur].className = 'dia_off';
		dia.cur = -1;
	}
	dia.col[lind].className = 'dia_on';
	dia.cur = lind;
	dir = (dia.th.scrollLeft<dia.col[dia.cur].xval);
	if(dir==0)
		dir = -1;
	dia_move(dia.th.scrollLeft, dia.col[dia.cur].xval, dir);// deplacement avec transition
//				dia.th.scrollLeft = dia.col[dia.cur].xval; // deplacement sans transition
}

function dia_prec(){
	if(dia.cur==0)
		dia_focus(dia.len);
	else
		dia_focus(dia.cur-1);
	return false;
}

function dia_suiv(){
	if(dia.cur==dia.len)
		dia_focus(0);
	else
		dia_focus(dia.cur+1);
	if(arguments.length==1)
		dia.tm = window.setTimeout("dia_suiv(1)", dia_pause);
	return false;
}

function dia_launch(o){
	if(o.chld==null){
		o.chld = o.getElementsByTagName("IMG")[0];
		o.dia = o.chld.src;
		o.tit_dia = o.chld.alt;
		o.arr = o.getElementsByTagName("IMG")[1].src;
		o.tit_arr = o.getElementsByTagName("IMG")[1].alt;
	}
	if(dia.tm!=null){
		window.clearTimeout(dia.tm);
		dia.tm = null;
		o.chld.src = o.dia;
		o.chld.title = o.tit_dia;
	}
	else{
		o.chld.src = o.arr;
		o.chld.title = o.tit_arr;
		window.setTimeout("dia_suiv(1)", dia_pause);
	}
	return false;
}

function dia_move(x, rpoint, dir){
	dia.th.scrollLeft = Math.round(x);
	x += (rpoint - x)*dia_trans;
	if(dir==1){
		if(Math.round(x)>=rpoint){
			dia.th.scrollLeft = rpoint;
			return;
		}
	}
	else{
		if(Math.round(x)<=rpoint){
			dia.th.scrollLeft = rpoint;
			return;
		}
	}
	window.setTimeout("dia_move("+x+", "+rpoint+", "+dir+")", 10);
}

/*
* Auteur : K.Benazouz
* Description : Fonction qui réalise le changement d'année et passe en paramètre l'année dans l'URL.
*/

function select_annee(objSelect)
{
	self.location.href = 'index.aspx?id=' + objSelect.options[objSelect.selectedIndex].value;
}