function adjustFond(){
	var myHeight = document.body.scrollHeight
	var myWidth =   document.body.scrollWidth	
	
	myWidth = myWidth+"px";
	myHeight = myHeight+"px";
	modifyCssRule("0","#imgCadreFond", "width", myWidth)
	modifyCssRule("0","#imgCadreFond", "height", myHeight)
}

function adjustImageCadre(){	
	
	leftUpdate = fScrollLeft(imgWidth);	
	topUpdate = fScrollTop(imgHeight);
	$imgFxC1bImgCadre.start({
		'left': [leftUpdate],
		'top': [topUpdate]
	});
	
}

function fScrollTop(imgHeight) {
	if (window.innerHeight) { $wHeight = window.innerHeight; } else { $wHeight = document.body.clientHeight; } 
	if (document.documentElement.offsetHeight) { $wHeight = document.documentElement.offsetHeight } 
	$h = window.pageYOffset ||
       document.body.scrollTop ||
       document.documentElement.scrollTop;
  $scrollHeigth =  $h ? $h : 0;
	return  (Math.round((($wHeight-imgHeight)/2)+$scrollHeigth))
	
}

function fScrollLeft(imgWidth) {
	if (window.innerWidth) { $wWidth = window.innerWidth; } else { $wWidth = document.body.clientWidth; }
	
	return  (Math.round(($wWidth-imgWidth)/2))
	
}

function removeEvent(node ,evt, fnc){
	if (node.removeEventListener)
		node.removeEventListener(evt,fnc,false);
	else if (node.detachEvent)
		node.detachEvent('on'+evt,fnc);
	else
	return false;
	return true;
}

$previousImgClick = "null"

function createThumbsClick($travailNo, $thumbNo){	
		$imgThumb = 'img'+$thumbNo+'ThumbTgl';
		$($imgThumb).addEvent('click', function(e){
			$url = "images.php?no="+$selection+"&thumb="+$thumbNo;	
			$imgFxC1a.start({
				'-moz-opacity': [0.99, 0],
				'opacity': [.99, 0]				
			});				
			$imgQteCount = $thumbNo+1
			var imgLimit = imgQte
			imgLimit++
			if ($imgQteCount >= imgLimit){$imgQteCount = 1};
			$previousImgClick = "thumb"
		});	
}

$changeImageClickFunc = function(e){
	$url = "images.php?no="+$selection+"&thumb="+$imgQteCount;	
	$imgFxC1a.start({
		'-moz-opacity': [0.99, 0],
		'opacity': [.99, 0]				
	});	
	$previousImgClick = "img"
}
 
function changeImageClick($selection){	
		
	$('img').addEvent('click', $changeImageClickFunc);
	 
		if ($previousImgClick != "thumb"){
			$imgQteCount++			
		}
		var imgLimit = imgQte
		imgLimit++
		if ($imgQteCount >= imgLimit){$imgQteCount = 1};
}

function ouvreTravailThumb($travailNo){
	
	$travauxArray[$travailNo].thumbFx.start({			
		'-moz-opacity': [.0,.99],
		'opacity': [.00,.99]
	});		
}

function ouvreTravailImg(){
	
	adjustFond()
	$imgFxA3.start({								
			'-moz-opacity': [.75,0],
			'opacity': [.75,0]
	});	
	
	$imgFxA0.start({
		'-moz-opacity': [0.87, 0],
		'opacity': [.87, 0]
	});
}

function ouvreTravailImg2(){
	$imgFxC1bImgChargement2.start({
		'-moz-opacity': [.87, 0],
		'opacity': [.87, 0]
	});
	
	if ( parseFloat(getCssRuleValue("0","#imgCadre", "height")) < imgCadreHeight ){
		modifyCssRule("0","#imgCadre", "height", imgCadreHeight+"px")	
		modifyCssRule("0","#imgCadreContenu", "height", imgCadreHeight+"px")						
	}					
	modifyCssRule("0","#img", "height", imgHeight+"px")
	modifyCssRule("0","#imgCadre", "top", $topUpdate)
	modifyCssRule("0","#imgCadre", "left", $leftUpdate)						
	modifyCssRule("0","#imgChargement", "width", imgWidth+"px")
	//modifyCssRule("0","#imgThumbs", "top", imgThumbsTop+"px")
	//modifyCssRule("0","#imgCadreContenu", "width", imgWidth+"px")	
		
	imgThumbsTop = parseFloat(imgThumbsTop);
	$imgFxC1bThumb.start({
		'top': [imgThumbsTop]
	});
	
	imgWidth = parseFloat(imgWidth);
	$imgFxC1bImgCadreContenu.start({
		'width': [imgWidth]
	});
	
	leftUpdate = fScrollLeft(imgWidth);
	$imgFxC1bImgCadre.start({
		'left': [leftUpdate]
	});
}

				
/*function dataStorage() { // function de variables globales
	var var1;
	var var2;
}*/
/*var globalDatas = new dataStorage();

window.addEvent('domready', function() {
	
	
})*/

window.addEvent('load', function() {
																 
	modifyCssRule("0","span#travaux", "visibility", "visible")
	if (navigator.userAgent.indexOf('MSIE') ==-1) { modifyCssRule("0","span#travaux", "overflow", "visible"); }
	modifyCssRule("0","span#travaux", "height:", "auto")		
	
	modifyCssRule("0","span#chargement", "visibility", "hidden")
	modifyCssRule("0","span#chargement", "overflow", "hidden")
	modifyCssRule("0","span#chargement", "height", "0px")
	modifyCssRule("0","span#chargement", "marginTop", "0px")
	modifyCssRule("0","span#chargement", "float", "right")
	$('chargement').setHTML('');
	
	
	modifyCssRule("0","span#travaux", "overflow", "visible")
	modifyCssRule("0","span#travaux", "overflow-y", "visible")
	modifyCssRule("0","span#travaux", "display", "block")
	modifyCssRule("0","span#travaux", "height", "auto")
	modifyCssRule("0","span#travauxWeb", "overflow", "visible")
	modifyCssRule("0","span#travauxWeb", "overflow-y", "visible")
	modifyCssRule("0","span#travauxWeb", "display", "block")
	modifyCssRule("0","span#travauxWeb", "height", "auto")
	modifyCssRule("0","span#travauxImprime", "overflow", "visible")
	modifyCssRule("0","span#travauxImprime", "overflow-y", "visible")
	modifyCssRule("0","span#travauxImprime", "display", "block")
	modifyCssRule("0","span#travauxImprime", "height", "auto")
	modifyCssRule("0","span#travail", "overflow", "visible")
	modifyCssRule("0","span#travail", "overflow-y", "visible")
	modifyCssRule("0","span#travail", "display", "block")
	modifyCssRule("0","span#travail", "height", "auto")

																 
	
	
function createSlide(v1, v2){
	$ongletsTravaux[$travauxTypes[v1]]["travaux"]["val"] = 0;
	$ongletsTravaux[$travauxTypes[v1]]["sld"]["val"] = new Fx.Slide(''+$ongletsTravaux[$travauxTypes[v1]]["travaux"]+'', {
		duration: 1000,
		// to dynamically change the height of the div as needed for content
		onComplete: function(){				
			$animComplete = 1
			if(this.wrapper.offsetHeight != 0){
				this.wrapper.setStyle('height', 'auto');
			}else{
				this.wrapper.setStyle('height', 0);
			}
			$animComplete = 0
		}
	});	

$ongletsTravaux[$travauxTypes[v1]]["sld"]["val"].hide();
			
$(''+$ongletsTravaux[$travauxTypes[v1]]["tgl"]+'').addEvent('click', function(e){
	e = new Event(e);
	if ($ancienTravail != "null"){
		fermeAncienTravail();
		$ancienTravail = "null";			
	}
	
	if ($ongletsTravaux[$travauxTypes[v1]]["travaux"]["val"] == 0){	
		$(''+$ongletsTravaux[$travauxTypes[v1]]["tgl"]+'Switch').setHTML('[-]');	
		$(''+$ongletsTravaux[$travauxTypes[v2]]["tgl"]+'Switch').setHTML('[+]');		
		$ongletsTravaux[$travauxTypes[v1]]["sld"]["val"].slideIn();
		$ongletsTravaux[$travauxTypes[v2]]["sld"]["val"].slideOut();
		$ongletsTravaux[$travauxTypes[v1]]["travaux"]["val"] = 1;
		$ongletsTravaux[$travauxTypes[v2]]["travaux"]["val"] = 0;
	}else{
		$ongletsTravaux[$travauxTypes[v1]]["travaux"]["val"] = 0;
		$(''+$ongletsTravaux[$travauxTypes[v1]]["tgl"]+'Switch').setHTML('[+]');
		$ongletsTravaux[$travauxTypes[v1]]["sld"]["val"].slideOut();
	}
	e.stop();
	});
};


function callTravailFunct ($travailNo) {
	$travailInfo = $travauxArray[$travailNo][3];
	$travailTgl = $travauxArray[$travailNo][4];
	$travailImage = $travauxArray[$travailNo][7];
	if (navigator.userAgent.indexOf('MSIE 6.0') ==-1)
	{
		$cssRule = "span#"+$travailInfo
		createCssRule($cssRule, "padding-top:2px;  display:block;  color: #333333;  width:325px;  height:auto")
	}
	
	$travailSld = new Fx.Slide($travailInfo, {duration:500,
		onComplete: function(){		
			
			if ($animComplete ==0){
				if ($ancienTravail !="null" && $ancienTravail != $travailNo){
					fermeAncienTravail()	
					$ancienTravail = $travailNo;	
					$animComplete = 1
				}	else {
					$ancienTravail = $travailNo;	
					$animComplete = 0
				}
			} else {
				$animComplete = 0
			}		
		}
	});
	$travailSld.hide();
	$travauxArray[$travauxNo][6] =  ($travailSld)
		
	$($travailTgl).addEvent('click', function(e){
		var cssRule =  'a#travail'+$travailNo+'Tgl:link'
		modifyCssRule("2", cssRule, "color", "#850000")		
		var cssRule =  'a#travail'+$travailNo+'Tgl:visited'
		modifyCssRule("2", cssRule, "color", "#850000")
		
		e = new Event(e);
		$selection = $travauxArray[$travailNo][1]
		
		travailOuvre($travailNo)
		e.stop()
	});
	
	if ($travailImage != "null"){
	$($travailImage).addEvent('click', function(e){		
		$ImgReset.start({
			'-moz-opacity': [.87, 0],
			'opacity': [.87, 0]
		});
		$ImgChargementReset.start({
			'-moz-opacity': [.87, 0],
			'opacity': [.87, 0]
		});
																							
		e = new Event(e);
		$url = "images.php?no="+$selection+"";
		new Ajax($url, {
			method: 'get',
			evalScripts: true,
			onComplete: function() {				
				adjustFond()
				$('imgChargement').setHTML('<img src="images/loading1i.gif" alt="chargement" />');
				
				leftUpdate = fScrollLeft(imgWidth);	
				topUpdate = fScrollTop(imgHeight);
				$imgFxC1bImgCadre.start({
					'left': [leftUpdate],
					'top': [topUpdate]
				});
				
				$topUpdate = (fScrollTop(imgCadreHeight))+"px"
				$leftUpdate = (fScrollLeft(imgWidth))+"px"
				modifyCssRule("0","#imgCadre", "top", $topUpdate)
				modifyCssRule("0","#imgCadre", "left", $leftUpdate)
				modifyCssRule("0","#imgCadre", "height", imgCadreHeight+"px")	
				
				
				modifyCssRule("0","#imgCadreFond", "visibility", "visible")
				modifyCssRule("0","#imgCadre", "height", imgCadreHeight+"px")	
				modifyCssRule("0","#imgCadreContenu", "height", imgCadreHeight+"px")			
				modifyCssRule("0","#img", "height", imgHeight+"px")
				modifyCssRule("0","#imgChargement", "top", (imgHeight/2)+"px")			
				
				imgThumbsTop = parseFloat(imgThumbsTop);
				$imgFxA4bThumb.start({
					'top': [imgThumbsTop]
				});
				
				imgWidth = parseFloat(imgWidth);
				$imgFxA4bImgCadre.start({
					'width': [imgWidth]
				});
				
				imgQte = parseFloat(imgQte);
				
				if (imgQte >= 2){
					$imgQteCount = 1;
					changeImageClick($selection)	
				
					$thumbsCode = ""
					$travauxArray[$travailNo][9] = new Array ("")
					for ($iCount = 1 ; $iCount <= imgQte ; $iCount++){
						$thumbPath = "images/travaux/"+imgCurrent+"/"+imgCurrent+""+$iCount+"-thumb-small.jpg";
						$thumbsCode = $thumbsCode+'<img src="'+$thumbPath+'" id="img'+$iCount+'ThumbTgl" /> '
						$travailInfo = $travauxArray[$travailNo][9].push ($iCount)
					}
					
					$('imgThumbs').setHTML($thumbsCode);	
					for ($iCount = 1 ; $iCount <= imgQte ; $iCount++){
						createThumbsClick($travailNo, $iCount)
					}			
				}else{		
					$('imgThumbs').setHTML('');
					$("img").removeEvent('click');
				}
				
				$imgFxA0.start({
					'-moz-opacity': [0,0.87],
					'opacity': [0,.87]
				});
				
					
				$imgFxA1.start({
					'-moz-opacity': [0,0.87],
					'opacity': [0,.87]
				});				
    	}
		}).request();			
						
		$('img').removeEvent('click', $changeImageClickFunc);
	})
	}
	
};
	
function fermeAncienTravail(){	
	$ancienTravailTglSwitch = $travauxArray[$ancienTravail][4];
	$ancienTravailTglSwitch = $travauxArray[$ancienTravail][5];
	$ancienTravailSld = $travauxArray[$ancienTravail][6];

	$($ancienTravailTglSwitch).setHTML('&nbsp;[+]');			
	$ancienTravailSld.slideOut();
	$travauxArray[$ancienTravail][8] = 0;
}
	
function travailOuvre($travailNo){
	$travail = $travauxArray[$travailNo][2];
	$travailTgl = $travauxArray[$travailNo][4];
	$travailTglSwitch = $travauxArray[$travailNo][5];
	$travailSld = $travauxArray[$travailNo][6];
	$travailOpen = $travauxArray[$travailNo][8];
	if ($travauxArray[$travailNo][7] != "null"){			
		$travailImageContent = $travauxArray[$travailNo][7]+"Content";
		
		if ( $travauxArray[$travailNo].format == "imprime"){		
			if ( $travauxArray[$travailNo].imageOpen == "null"){
			$travauxArray[$travailNo].imageOpen = "done"
				$url = "images.php?no="+$travailNo+"&format=thumb"
				new Ajax($url, {
					method: 'get',
					evalScripts: true,
					onComplete: function() {	
					$($travailImageContent).setHTML("<img src='"+imgPath+"' alt='"+imgTitle+"' width='"+imgWidth+"px' height='"+imgHeight+"px' name='imageTravail' id='imageTravail' onLoad='ouvreTravailThumb("+$travailNo+")' />");	
						
				}}).request();
			}
		}
		//$travauxArray[$travauxNo].format
		//$travauxArray[$travauxNo].imageOpen
		
	}	
	
	if ($travailOpen == "null" || $travailOpen == 0 ){	
		$($travailTglSwitch).setHTML('&nbsp;[-]');			
		$travailSld.slideIn();
		$travauxArray[$travailNo][8] = 1;
	} else if ($travailOpen == 1){	
		$travauxArray[$travailNo][8] = 0;
		$($travailTglSwitch).setHTML('&nbsp;[+]');
		$travailSld.slideOut();
	}	
}

//------- Images-Big-Ouvre
	
	$imgFxA0 = new Fx.Styles('imgChargement', {duration:550,wait:false, onComplete: function(){
	}});
	
	$imgFxA1 = new Fx.Styles('imgCadreFond', {duration:550,wait:false, onComplete: function(){				
		adjustFond()
		modifyCssRule("0","#imgCadre", "visibility", "visible")		
		$imgFxA2.start({			
			'-moz-opacity': [0,.75],
			'opacity': [0,.75]
		});	
	}});
	$imgFxA2 = new Fx.Styles('imgCadreContenu', {duration:550,wait:false, onComplete: function(){		
		$alt = imgTitle;																																									 
		$alt = $alt.replace("<i>", "");
		$alt = $alt.replace("<\/i>", "");
		$('img').setHTML("<img src='"+imgPath+"' 'alt='"+$alt+"' width='"+imgWidth+"px' height='"+imgHeight+"px' name='imageTravail' id='imageTravail' onLoad='ouvreTravailImg()' />");	
	}});	
	
	$imgFxA3 = new Fx.Styles('imgCadreContenu', {duration:550,wait:false, onComplete: function(){	
		
		modifyCssRule("0","#imgTop", "visibility", "visible")
		modifyCssRule("0","#imgThumbs", "visibility", "visible")
		modifyCssRule("0","#img", "visibility", "visible")		
		
		adjustFond()
		$imgFxA4.start({
					'-moz-opacity': [0,.99],
					'opacity': [0,.99]
		});
		
		$imgFxA4b.start({
					'-moz-opacity': [0,.99],
					'opacity': [0,.99]
		});
		
	}});
	
	$imgFxA4 = new Fx.Styles('imgCadreContenu', {duration:550,wait:false, onComplete: function(){	
																																																	 
	}});
	
	$imgFxA4b = new Fx.Styles('img', {duration:550,wait:false, onComplete: function(){	
																																																	 
	}});
	
	$imgFxA4bThumb = new Fx.Styles('imgThumbs', {duration:10,wait:false, onComplete: function(){																																										 
	}});
	
	$imgFxA4bImgCadre = new Fx.Styles('imgCadreContenu', {duration:10,wait:false, onComplete: function(){																																										 
	}});
	
	//------- Images-Big-Change		
	$imgFxC1a = new Fx.Styles('img', {duration:550,wait:false, onComplete: function(){	
		if (imgQte >=2){
			changeImageClick($selection)			
		}
		$('imgChargement').setHTML('<img src="images/loading1i.gif" alt="chargement" />');
		$imgFxC1bImgChargement1.start({
			'-moz-opacity': [0, .87],
			'opacity': [0, .87]
		});	
																																										 
	}});


	$imgFxC1bThumb = new Fx.Styles('imgThumbs', {duration:550,wait:false, onComplete: function(){
		if ( parseFloat(getCssRuleValue("0","#imgCadre", "height")) > imgCadreHeight ){																																													
			modifyCssRule("0","#imgCadre", "height", imgCadreHeight+"px")	
			modifyCssRule("0","#imgCadreContenu", "height", imgCadreHeight+"px")
			
		}
		$imgFxC1bImg.start({
			'-moz-opacity': [0, .99],
			'opacity': [0, .99]
		});	
	}});
	
	$imgFxC1bImgCadreContenu = new Fx.Styles('imgCadreContenu', {duration:550,wait:false, onComplete: function(){																																										 
	}});
	
	$imgFxC1bImgCadre = new Fx.Styles('imgCadre', {duration:550,wait:false, onComplete: function(){																																										 
	}});
	
	$imgFxC1bImg = new Fx.Styles('img', {duration:550,wait:false, onComplete: function(){																																										 
	}});
	
	$imgFxC1bImgChargement1 = new Fx.Styles('imgChargement', {duration:550,wait:false, onComplete: function(){
		new Ajax($url, {
			method: 'get',
			evalScripts: true,
			onComplete: function() {	
				$('img').setHTML("<img src='"+imgPath+"' alt='"+imgTitle+"' width='"+imgWidth+"px' height='"+imgHeight+"px' name='imageTravail' id='imageTravail' onLoad='ouvreTravailImg2()' />");	
				
				
			}
		}).request();		
	}});

	$imgFxC1bImgChargement2 = new Fx.Styles('imgChargement', {duration:550,wait:false, onComplete: function(){
	}});
	
	
	$ImgReset = new Fx.Styles('img', {duration:1,wait:false, onComplete: function(){
	}});
	
	$ImgChargementReset = new Fx.Styles('imgChargement', {duration:1,wait:false, onComplete: function(){
	}});

	
	//------- Images-Big-Ferme
	
	$('fermerImage').addEvent('click', function(e){
		e = new Event(e);		
		$imgFxB1a.start({
			'-moz-opacity': [0.99,0],
			'opacity': [0.99,0]
		});
	});
	
	$('imgCadreFond').addEvent('click', function(e){
		e = new Event(e);		
		$imgFxB1a.start({
			'-moz-opacity': [0.99,0],
			'opacity': [0.99,0]
		});
	});
		
	$imgFxB1a = new Fx.Styles('imgCadreContenu', {duration:550,wait:false, onComplete: function(){		
		
		$imgFxB1b.start({
			'-moz-opacity': [0.8,0],
			'opacity': [0.8,0]
		});
		
		$imgFxB1b2.start({
			'-moz-opacity': [0.8,0],
			'opacity': [0.8,0]
		});
		
		
	}});
	
	$imgFxB1b = new Fx.Styles('imgCadreFond', {duration:550,wait:false, onComplete: function(){	
		
		modifyCssRule("0","#imgTop", "visibility", "hidden")
		modifyCssRule("0","#img", "visibility", "hidden")	
		modifyCssRule("0","#imgCadre", "visibility", "hidden")	
		modifyCssRule("0","#imgThumbs", "visibility", "hidden")
		modifyCssRule("0","#imgCadre", "height", "0px")			
		modifyCssRule("0","#imgCadreFond", "visibility", "hidden")	
	}});
	
	$imgFxB1b2 = new Fx.Styles('img', {duration:550,wait:false, onComplete: function(){		
	}});
	
	

	function loadThumbs(){	
		new Ajax("images.php?printPos=true", {	method: 'get', evalScripts: true, onComplete: function() {	
		$travauxTypes =  new Array ("Web","Imprime");
		$ongletsTravaux =  new Array ("")
		for (iCount = 0 ; iCount <= $travauxTypes.length-1 ; iCount++){
		$ongletsTravaux[$travauxTypes[iCount]] = new Array ("")
			$ongletsTravaux[$travauxTypes[iCount]]["travaux"] = new Array ("travaux"+$travauxTypes[iCount])
			$ongletsTravaux[$travauxTypes[iCount]]["travaux"]["val"] = new Array ()
			$ongletsTravaux[$travauxTypes[iCount]]["tgl"]= new Array ($travauxTypes[iCount].toLowerCase()+"Tgl")
			$ongletsTravaux[$travauxTypes[iCount]]["sld"]= new Array ($travauxTypes[iCount].toLowerCase()+"Sld")
			$ongletsTravaux[$travauxTypes[iCount]]["sld"]["val"] = new Array ()
		}
	
		createSlide(0, 1)
		createSlide(1, 0)
		
		
		//--------------TRAVAUX ITEMS
		$travauxNo = 1;
		$ancienTravail = "null";
		$travauxArray = new Array;
		while ($travauxNo <=nbrTravauxTrfrt){	
			if ($travauxNo >= printBegin){
				$travauxArray[$travauxNo] = new Array ("", $travauxNo, "travail"+$travauxNo, "travail"+$travauxNo+"Info", "travail"+$travauxNo+"Tgl", "travail"+$travauxNo+"TglSwitch", "travail"+$travauxNo+"Sld", "travail"+$travauxNo+"Image", "null", "thumbs");
				$travauxArray[$travauxNo].imageOpen= "null"
				$travauxArray[$travauxNo].format = "imprime"
				
				$imgContent = "travail"+$travauxNo+"ImageContent"
				createTravauxImgFx($travauxNo, $imgContent)				
				
			} else {
				$travauxArray[$travauxNo] = new Array ("", $travauxNo, "travail"+$travauxNo, "travail"+$travauxNo+"Info", "travail"+$travauxNo+"Tgl", "travail"+$travauxNo+"TglSwitch", "travail"+$travauxNo+"Sld", "null", "null", "thumbs");
				$travauxArray[$travauxNo].format = "web"
			}
			callTravailFunct($travauxNo);
			$travauxNo++;
		}
	}}).request();
}
	
	function createTravauxImgFx($travailNo, $imgContent){
						
		$travauxArray[$travailNo].thumbFx = new Fx.Styles($imgContent, {duration:400,wait:false, onComplete: function(){																																																											
		}});
	}
	
	loadThumbs()
	

});


window.addEvent('resize', function() {
	adjustFond();
	adjustImageCadre()
});
