/*
Script Galerie Slide 1.0.4
2009 djm Web sprl
*/

var class_content_slide_number = 0;
var class_cont_slide;
if (!class_cont_slide) class_cont_slide = function (vId,vWidthBox,vHeightBox,vPadding,vStepW,vStepH,vCol,vRow,vVitesse) {
	this.widthBox = vWidthBox;
	this.heightBox = vHeightBox;	
	this.padding = vPadding;	
	this.nCol = vCol;
	this.nRow = vRow;
	this.vitesse = vVitesse;
	this.stepW = vStepW;
	this.stepH = vStepH;
	
	this.count;
	this.countScreen;
	this.countVisi = this.nCol*this.nRow;
	this.pos = 0;	
	this.fadePos = 100;
	this.where_screen = 0;
	
	this.flag_sens = 0;
	this.etatAuto = 0;

	this.contGal = document.getElementById(vId); 
	
	var obj = this;
	this.Anime = 1;
	var durAuto = 5000;
	

	this.InitContSlide = function () {
		this.get_cont();
		}
		
	this.dropOldCont = function () {
		this.cont_box_slide.innerHTML = '';
		this.pos = 0;
		this.cont_box_slide.style.left= this.pos+'px';
		this.cont_left.style.display = 'none';
		this.cont_right.style.display = 'none';
		this.where_screen = 0;
		if (this.box_cont_step) {
			this.box_cont_step.innerHTML = '';
			}		
		}
	
	this.get_cont = function () {
		this.dropOldCont();
		var cont_data = this.contGal.getElementsByTagName('div');
		var attValue;
		var idx=0;
		var tabData = new Array();
		for (var i=0;i<cont_data.length;i++) {
			if (cont_data[i].getAttributeNode('class')) {
				attValue = cont_data[i].getAttributeNode('class').value; 
				} else {
					attValue = cont_data[i].getAttribute('class');
					}
			if (attValue == 'content_slide') {
				tabData[idx]=cont_data[i];
				idx++;
				}
			}
		this.construct_cont(tabData);		
		}
	
	this.construct_cont = function (cont_data) {
		
		this.count = cont_data.length;
		this.countScreen = Math.ceil(this.count/this.countVisi);
		
		this.cont_box_slide.style.width = (this.cont_cache.offsetWidth*this.countScreen)+'px';
		
		//savoir si plus que visible
		if (this.count>this.countVisi) {
			this.cont_right.style.display = 'block';
			}
		
		var vLink;
		var vContenu;
		
		for (var i=0;i<this.count;i++) {
			if (cont_data[i].getElementsByTagName("a")[0].getAttribute("href")) {
				vLink = cont_data[i].getElementsByTagName("a")[0].getAttribute("href");
				}
				else {
					vLink = false;
					}
			if (cont_data[i].innerHTML) {
				vContenu = cont_data[i].innerHTML;
				}
				else {
					vContenu = false;
					}
			this.put_cont (vContenu, vLink, i);				
			}
					
		this.box_clearB = document.createElement('div');
		this.box_clearB.className = 'box_clear';
		this.cont_box_slide.appendChild(this.box_clearB);	
			
		this.img_mis = 0;
		this.nbre_box = 0;	
		
		this.contruct_step(this.countScreen);
		
		if ((this.countScreen > 1)&&(this.Anime == 1)) {
			timeAuto = setTimeout(function() {obj.move_auto();},durAuto);
			}
		}	
	
	this.cont_cache = false;
	
	this.construct_cont_box = function () {		
		class_content_slide_number++;
		if (!this.cont_cache) {			
			
			this.cont_box_left = document.createElement('div');
			this.cont_box_left.style.cssFloat = 'left';
			this.cont_box_left.style.styleFloat = 'left';
			this.cont_box_left.className = 'cont_box_left';
			this.cont_box_left.setAttribute('id','cont_box_left_'+class_content_slide_number);
			this.contGal.appendChild(this.cont_box_left);
			
			this.cont_left = document.createElement('div');
			this.cont_left.style.display = 'none';
			this.cont_left.style.cursor = 'pointer';	
			this.cont_left.onclick = function () {
				obj.etatAuto=1;
				obj.move_prev();	
				}	
			this.cont_left.className = 'cont_left';
			this.cont_left.setAttribute('id','cont_left_'+class_content_slide_number);
			this.cont_box_left.appendChild(this.cont_left);				
			
			this.cont_cache = document.createElement('div');
			this.cont_cache.style.width = ((this.widthBox*this.nCol)+(this.padding*(this.nCol-1)))+'px';
			this.cont_cache.style.height = ((this.heightBox*this.nRow)+(this.padding*(this.nRow-1)))+'px';
			this.cont_cache.style.overflow = 'hidden';
			this.cont_cache.style.whiteSpace = 'nowrap';
			this.cont_cache.style.position = 'relative';	
			this.cont_cache.style.cssFloat = 'left';
			this.cont_cache.style.styleFloat = 'left';
			this.cont_cache.className = 'cont_cache'
			this.cont_cache.setAttribute('id','cont_cache_'+class_content_slide_number);
			this.contGal.appendChild(this.cont_cache);
			
			this.cont_box_slide = document.createElement('div');
			this.cont_box_slide.style.position = 'relative';	
			this.cont_box_slide.style.left= '0px';
			this.cont_box_slide.style.height = (this.cont_cache.offsetHeight)+'px';
			this.cont_box_slide.className = 'cont_box_slide';
			this.cont_box_slide.setAttribute('id','cont_box_slide_'+class_content_slide_number);			
			this.cont_cache.appendChild(this.cont_box_slide);
			
			this.cont_box_right = document.createElement('div');
			this.cont_box_right.style.cssFloat = 'left';
			this.cont_box_right.style.styleFloat = 'left';
			this.cont_box_right.className = 'cont_box_right'
			this.cont_box_right.setAttribute('id','cont_box_right_'+class_content_slide_number);
			this.contGal.appendChild(this.cont_box_right);
			
			this.cont_right = document.createElement('div');
			this.cont_right.style.display = 'none';
			this.cont_right.style.cursor = 'pointer';	
			this.cont_right.onclick = function () {
				obj.etatAuto=1;
				obj.move_next();	
				}
			this.cont_right.className = 'cont_right';
			this.cont_right.setAttribute('id','cont_right_'+class_content_slide_number);
			this.cont_box_right.appendChild(this.cont_right);			
			
			this.box_clear = document.createElement('div');
			this.box_clear.className = 'box_clear';
			this.contGal.appendChild(this.box_clear);	
			
			}
		}
	
	this.img_mis = 0;
	this.nbre_box = 0;
	
	this.put_cont = function (vTxt, vLink, nbre) {
		if ((this.countVisi==this.img_mis) || (this.img_mis==0)) {	
			this.nbre_box++;
				
			this.box_visi = document.createElement('div');
			this.box_visi.style.height = (this.cont_cache.offsetHeight)+'px';
			this.box_visi.style.width = (this.cont_cache.offsetWidth)+'px';
			this.box_visi.style.cssFloat = 'left';
			this.box_visi.style.styleFloat = 'left';
			this.box_visi.style.overflow = 'hidden';
			this.box_visi.className = 'box_visi';	
			this.box_visi.setAttribute('id','box_visi_'+class_content_slide_number+'_'+this.nbre_box);
			this.cont_box_slide.appendChild(this.box_visi);			
			
			this.img_mis = 0;
			}		
				
		this.cont_box = document.createElement('div');
		this.cont_box.style.width = this.widthBox+'px';
		this.cont_box.style.height = this.heightBox+'px';
		this.cont_box.style.overflow = 'hidden';
		this.cont_box.style.cssFloat = 'left';
		this.cont_box.style.styleFloat = 'left';
		this.cont_box.style.cursor = 'pointer';
		
		if (!(this.verif_numeric(this.img_mis/this.nCol))) {
			this.cont_box.style.marginLeft = this.padding+'px';
			}
			
		if (this.img_mis>=this.nCol) {
			this.cont_box.style.marginTop = this.padding+'px';
			}
		
		this.cont_box.className = 'cont_box';
		this.cont_box.onclick = function () {
			document.location.href = vLink;
			}
		this.cont_box.onmouseover = function () {
			//setFade(80,this);
			this.className += ' hover'
			}
		this.cont_box.onmouseout = function () {
			//setFade(100,this);
			this.className = this.className.replace('hover','');
			}
		this.cont_box.setAttribute('id','cont_box_'+class_content_slide_number+'_'+nbre);
		this.box_visi.appendChild(this.cont_box);
		
		this.cont_box.innerHTML = vTxt;		
		
		if ((this.img_mis==(this.countVisi-1)) || (nbre==(this.count-1))) {			
			this.box_clearC = document.createElement('div');
			this.box_clearC.className = 'box_clear';
			this.box_visi.appendChild(this.box_clearC);			
			}
		
		this.img_mis++;
		}
	
	this.verif_numeric = function (variable) {
		var exp = new RegExp("^[0-9]+$","g");
		return exp.test(variable); 
		}
		
	this.box_cont_step = false;
		
	this.contruct_step = function (nbre) {
		if (!this.box_cont_step) {
			this.box_cont_step = document.createElement('div');
			this.box_cont_step.className = 'box_cont_step';
			this.box_cont_step.setAttribute('id','box_cont_step_'+class_content_slide_number);
			this.contGal.appendChild(this.box_cont_step);
			}

		this.box_cont_step.style.width = (this.stepW*this.countScreen)+'px';
		
		this.box_step = new Array(nbre);
				
		for (i=0;i<nbre;i++) {
			this.box_step[i] = document.createElement('div');
			this.box_step[i].style.display = 'block';
			this.box_step[i].style.cssFloat = 'left';
			this.box_step[i].style.styleFloat = 'left';
			this.box_step[i].className = 'box_step';
			this.box_step[i].setAttribute('id','box_step_'+class_content_slide_number+'_'+i);
			this.box_cont_step.appendChild(this.box_step[i]);
			}	
			
		this.box_clearD = document.createElement('div');
		this.box_clearD.className = 'box_clear';
		this.box_cont_step.appendChild(this.box_clearD);
		
		this.step_sel(this.where_screen);
		}
	
	this.step_sel = function (lequel, etat) {
		var box = this.box_step[lequel];
		
		for (i=0;i<this.box_step.length;i++) {
			if (i==lequel) {
				this.box_step[i].className+=' box_step_selected';
				}
				else {
					this.box_step[i].className=this.box_step[i].className.replace('box_step_selected','');
					}
			}	
		}
		
	//debut gestion mouvement
	var timeNext;
	var timePrev;
	this.pos_temp=this.pos;
	
	this.move_next = function () {
		if ((Math.abs(this.pos_temp)<this.cont_cache.offsetWidth) && (Math.abs(this.pos)<(this.cont_box_slide.offsetWidth-this.cont_cache.offsetWidth))) {
			if ((Math.abs(this.pos_temp)+this.vitesse)>this.cont_cache.offsetWidth) {
				this.pos-=(this.cont_cache.offsetWidth-Math.abs(this.pos_temp));
				this.pos_temp-=(this.cont_cache.offsetWidth-Math.abs(this.pos_temp));
				}
				else {
					this.pos-=this.vitesse;
					this.pos_temp-=this.vitesse;
					}	
			
			this.cont_box_slide.style.left= this.pos+'px';
			timeNext = setTimeout(function() {obj.move_next();},20);
			this.cont_left.style.display = 'block';
			}
			else {
				clearTimeout(timeNext);
				this.pos_temp=0;
				if (Math.abs(this.pos)==(this.cont_box_slide.offsetWidth-this.cont_cache.offsetWidth)) {
					this.cont_right.style.display = 'none';
					this.flag_sens=1;
					}
				this.where_screen=(Math.abs(this.pos/this.cont_cache.offsetWidth));	
				this.step_sel(this.where_screen);
				}
		}
		
	this.move_prev = function () {
		if ((Math.abs(this.pos_temp)<this.cont_cache.offsetWidth) && (Math.abs(this.pos)>0)) {
			if ((Math.abs(this.pos_temp)+this.vitesse)>this.cont_cache.offsetWidth) {
				this.pos+=(this.cont_cache.offsetWidth-Math.abs(this.pos_temp));
				this.pos_temp+=(this.cont_cache.offsetWidth-Math.abs(this.pos_temp));
				}
				else {
					this.pos+=this.vitesse;
					this.pos_temp+=this.vitesse;
					}
			this.cont_box_slide.style.left= this.pos+'px';
			timePrev = setTimeout(function() {obj.move_prev();},20);
			this.cont_right.style.display = 'block';
			}
			else {
				clearTimeout(timePrev);
				this.pos_temp=0;
				if (Math.abs(this.pos)==0) {
					this.cont_left.style.display = 'none';
					this.flag_sens=0;
					}
				this.where_screen=(Math.abs(this.pos/this.cont_cache.offsetWidth));			
				this.step_sel(this.where_screen);
				}
		}
	
	//fin gestion mouvement
	
	//mouvement automatique
	
	var timeAuto;
	
	this.move_auto = function () {
		if (this.etatAuto==0) {				
			if (this.flag_sens==0) {
				this.move_next();
				timeAuto = setTimeout(function() {obj.move_auto();},durAuto);
				}
				else {
					this.move_prev();
					timeAuto = setTimeout(function() {obj.move_auto();},durAuto);
					}
			}
			else {
				clearTimeout(this.timeAuto);
				}
		}
	
	//fin mouvement automatique
	
	this.trim = function (str) {
		return str.replace(/(^\s*)|(\s*$)/g,"")
		}
	
	this.fadeTime;
	//Gestion fondu
	var fade = function (amt,to,obj) {
		if (amt <= to) {
			setFade(amt,obj);
			this.fadePos = amt;
			amt += 20;
			this.fadeTime = setTimeout(function () {fade(amt,to,obj);}, 80);
		}
		else {
			//clearTimeout(this.fadeTime);
			return;
			}
	}
	
	this.fadeOutTime;
	var fade_out = function (amt,to,obj) {
		if (amt >= to) {
			setFade(amt,obj);
			this.fadePos = amt;
			amt -= 25;
			this.fadeOutTime = setTimeout(function () {fade_out(amt,to,obj);}, 80);
		}
		else {
			//clearTimeout(this.fadeOutTime);
			return;
			}
	}
	
	var setFade = function (amt,obj) {		
		amt = (amt == 100)?100:amt;	  
		// IE
		obj.style.filter = "alpha(opacity:"+amt+")";	  
		// Safari<1.2, Konqueror
		obj.style.KHTMLOpacity = amt/100;	  
		// Mozilla and Firefox
		obj.style.MozOpacity = amt/100;	  
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		obj.style.opacity = amt/100;
	}
	//Fin gestion fondu
	
	return this.construct_cont_box();	

	}