/*************** addDOMLoadEvent **************/ 
function addDOMLoadEvent(func) {
   if (!window.__load_events) {
      var init = function () {
          // quit if this function has already been called
          if (arguments.callee.done) return;
      
          // flag this function so we don't do the same thing twice
          arguments.callee.done = true;
      
          // kill the timer
          if (window.__load_timer) {
              clearInterval(window.__load_timer);
              window.__load_timer = null;
          }
          
          // execute each function in the stack in the order they were added
          for (var i=0;i < window.__load_events.length;i++) {
              window.__load_events[i]();
          }
          window.__load_events = null;
          
          // clean up the __ie_onload event
          /*@cc_on @*/
          /*@if (@_win32)
              document.getElementById("__ie_onload").onreadystatechange = "";
          /*@end @*/
      };
   
      // for Mozilla/Opera9
      if (document.addEventListener) {
          document.addEventListener("DOMContentLoaded", init, false);
      }
      
      // for Internet Explorer
      /*@cc_on @*/
      /*@if (@_win32)
          document.write("<scr"+"ipt id=__ie_onload defer src=javascript:void(0)><\/scr"+"ipt>");
          var script = document.getElementById("__ie_onload");
          script.onreadystatechange = function() {
              if (this.readyState == "complete") {
                  init(); // call the onload handler
              }
          };
      /*@end @*/
      
      // for Safari
      if (/WebKit/i.test(navigator.userAgent)) { // sniff
          window.__load_timer = setInterval(function() {
              if (/loaded|complete/.test(document.readyState)) {
                  init(); // call the onload handler
              }
          }, 10);
      }
      
      // for other browsers
      window.onload = init;
      
      // create event function stack
      window.__load_events = [];
   }
   
   // add function to event stack
   window.__load_events.push(func);
}

/*************** GET ELEMENT BY CLASSNAME **************/

function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}	else {
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
/*************** RESIZE BLOCS **************/

function ResizeBlocs() {
	var maxHeightIllustration = 0;
	var maxHeightDescription = 0;
	var myList = document.getElementById("conteneur");
	var listIllustration = getElementsByClassName(myList, "div", "illu");
	var listDescription = getElementsByClassName(myList, "div", "content");
		
	// DETECT MAX HEIGHT PIC ILLUSTRATION
	var listHeightIllustration = new Array();
	for (var i=0; i<listIllustration.length; i++) {
		listHeightIllustration.push(listIllustration[i].offsetHeight);
		maxHeightIllustration = Math.max(maxHeightIllustration, listIllustration[i].offsetHeight);
	}
	
	// DETECT MAX HEIGHT TXT CONTENT
	var listHeightDescription = new Array();
	for (var i=0; i<listDescription.length; i++) {
		listHeightDescription.push(listDescription[i].offsetHeight);
		maxHeightDescription = Math.max(maxHeightDescription, listDescription[i].offsetHeight);
	}
	
	// SET MAX HEIGHT PIC ILLUSTRATION
	for (var i=0; i<listIllustration.length; i++) {
		listIllustration[i].style.height = maxHeightIllustration +'px';
	}
	
	// SET MAX HEIGHT TXT CONTENT
	for (var i=0; i<listDescription.length; i++) {
		listDescription[i].style.height = maxHeightDescription +'px';
	}

}	

/******** ONLOAD FUNCTION *************/
addDOMLoadEvent(ResizeBlocs);
