function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// parser un param de l'url en js
function parseparam( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)$";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  
  if( results == null )
    return "";
  else
    return results[1];
}
	/*****
			Pages book, miniatures references
	*****/
	function changeReference (id_image, src_image, id_image_cible) {
		$(id_image).src = src_image ;
		for (i = 0 ; i < 10; i++) {
			if ($("icone"+i)) {
				$("icone"+i).style.backgroundPosition = 'right top' ;
			}
		}
		$(id_image_cible).style.backgroundPosition = 'left top' ;
			
	}
	
	/*
	var Diaporama = new Class({
		initialize: function(el, options){
			this.diapoWidth = 200;
			this.current = 0;
			this.startPosition = 0 ;
			this.endPosition = 0 ;	
			this.nbDiapos =  $$('#'+el+' .diapo').length ;
			this.element = $(el);	
			this.element.style.width = (this.nbDiapos * this.diapoWidth)+'px' ;
						
			this.fx = new Fx.Style(el, 'left', { duration: 800, wait:false});
		},
		next: function () {
			this.current++;
			if(this.current < this.nbDiapos) {
				this.startPosition = this.element.getStyles('left').left.toInt() ;
				this.endPosition = this.current * this.diapoWidth ;					
				this.fx.start(this.startPosition, -this.endPosition);
			} else {
				this.current = this.nbDiapos - 1;
			}
		},
		previous: function () {
			this.current--;
			if (this.current >= 0) {
				this.startPosition = this.element.getStyles('left').left.toInt() ;
				this.endPosition =  this.current * this.diapoWidth ;
				this.fx.start(this.startPosition, -this.endPosition);	
			} else {
				this.current = 0;
			}
		},
		gotoDiapo: function (num_diapo) {
			
			while (this.current != num_diapo && num_diapo < this.nbDiapos) {
				if (num_diapo < this.current) {
					this.previous();
				} else if (num_diapo > this.current) {
					this.next();
				}
			}
			
		},
		setDiapo: function (num_diapo) {
			this.current = num_diapo;
			this.fx.set(-(num_diapo * this.diapoWidth));
			
		},
		getNbDiapos: function () {
			return this.nbDiapos;
		}
	});
	*/
	
	function slide(element, lien,id_lien) {
		//alert(element +' '+ lien);
		var responseContenu ;
		var request_link;
		
		var slideToLeft = new Fx.Style(element, 'left', {duration:500});
		var fadeMaquette = new Fx.Style(element, 'opacity', {duration:500 });
		h = new HistoryManager();
		
		if (lien) {
			h.addState(lien);
			request_link = lien + "&ajax_call=1";
		} else {
			h.addState($(id_lien).getAttribute("href"));
			request_link = $(id_lien).getAttribute("href") + "&ajax_call=1";
			$(id_lien).addClass('ajax-loading');
			
		}
		

		var myAjax = new Ajax(request_link , {evalScripts: true, method: 'get', 
							  								/*headers: {'X-Request': 'JSON'},*/
															encoding: 'ISO-8859-1',
															onComplete: function () {

																var responseText = this.response.text;		
																var regex = new RegExp ('<img[^>]*src="([^"]*)"[^>]*>', "gim");
																
																var images;
																var tabImagesPreload = Array();
																var nbimage = -1;
																while ((images = regex.exec(responseText)) != null)
																{
																	nbimage++;
																	tabImagesPreload[nbimage] = images[1];
																}
																													
																
																new Asset.images(tabImagesPreload, {
																	onComplete: function () {
																		
																		slideToLeft.start(0, -997); 
																		fadeMaquette.start(1,0);
																		
																		fx = function() {
																			
																			// on enleve l'ancien style de la page, et on le remplace par celui de la page appelée
																			
																			feuilleStlye = responseText.split(/\r*\n/);
																			responseText = "";
		
																			var j = 0;
																			var lignesNonVides = [];
																			for (i=0; i<feuilleStlye.length; i++) {
																				if (feuilleStlye[i]) {
																					lignesNonVides[j] = feuilleStlye[i];
																					j++;
																				}
																				
																			}
																			// la premiere ligne est la feuille de style
																			for (i=2; i<lignesNonVides.length; i++) {
																				responseText += lignesNonVides[i];
																			}
																			
																			$('style_template').remove();
																			new Asset.css(lignesNonVides[0], 
																							 {id: 'style_template', 
																								onComplete: completeCss()
																								 });
																			
																			function completeCss () {
																				// éxécution du gestionnaire des animations de la page
																				var getJs = new Ajax(lignesNonVides[1] , 
																													{method: 'get'}).chain(function() { 
																						if (!lien && $(id_lien)) {
																							$(id_lien).removeClass('ajax-loading');
																						}
																						var slideFromRight = new Fx.Style(element, 'left', {duration:700, transition: Fx.Transitions.Back.easeOut});				
																						var fadeMaquette2 = new Fx.Style(element, 'opacity', {duration:700 });
																						$(element).setHTML(responseText);
																						eval(this.response.text);
			
																						slideFromRight.start(997, 0);
																						fadeMaquette2.set(0);
																						fadeMaquette2.start(0,1); 
																				});
																				
																				
																				getJs.request();
																				
																				
																			}
																			
																			

																			
																		}.delay(500);
																	}
																});
																
																
															}
								});
		myAjax.request();
	}




function changeColor(id_objet) {
	
	
	for (i = 0 ; i < 10; i++) {
			if ($("linkIcone"+i)) {
				$("linkIcone"+i).style.color = '#000' ;
			}
		}
	$(id_objet.id).style.color="#fff";		

}