function $(id){
	return document.getElementById(id);
}

function getXhr() {
  var xhr=null;

  if(window.XMLHttpRequest)
       xhr=new XMLHttpRequest();
  else if(window.ActiveXObject){
       try{
		   xhr=new ActiveXObject("Msxml2.XMLHTTP");
	   }
       catch(e){
		   xhr=new ActiveXObject("Microsoft.XMLHTTP");
	   }
  }
  else{
	  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	  xhr=false;
  }
  return xhr;
}

function ajaxPage(url,id){
  var xhr=getXhr();
  xhr.onreadystatechange=function(){
	  if(xhr.readyState==4 && xhr.status==200){
		  $(id).innerHTML=xhr.responseText;
	  }
  }

  xhr.open("GET",url,true);
  xhr.send(null);
}

function calculeOffsetLeft(obj){
	return calculeOffset(obj,"offsetLeft");
}

function calculeOffsetTop(obj){
	return calculeOffset(obj,"offsetTop");
}

function calculeOffset(obj,attr){
	var offset=0;
	while(obj){
		offset+=obj[attr];
		obj=obj.offsetParent
	}
	return offset;
}

function getWindowWidth(){
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}

function getWindowHeight(){
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  		
  	return height;
}

function addEvent(obj,event,fct){
	if(obj.attachEvent)
		obj.attachEvent('on' + event,fct);
	else if(obj.addEventListener)
		obj.addEventListener(event,fct,true);
	else{
		event="on"+event;
		obj.event=fct;
	}
}

function removeEvent(obj,event,fct){
	if(obj.detachEvent)
		obj.attachEvent('on' + event,fct);
	else if(obj.removeEventListener)
		obj.removeEventListener(event,fct,false);
	else{
		event="on"+event;
		obj.event=null;
	}
}

function changeThumbnail(src,sexe){
	var str=$("thumbnail").src;
	
	if(sexe="girl" && str.substring(str.length-13)=="photo_boy.jpg")
		addImage("thumbnail",src,true);
	else if(sexe="boy" && str.substring(str.length-14)=="photo_girl.jpg")
		addImage("thumbnail",src,true);
}

function addImage(id,src,fadein,margin){
	var newImg=$(id);

	if(typeof(margin)!="undefined")
		newImg.style.marginTop=margin+"px";
	else
		newImg.style.marginTop=0;
	
	if(fadein==true){
		setOpacity(newImg,0);
		newImg.onload=function(){fadeIn(newImg, 0)};
	}

	newImg.src=src;
}

function loadIllustration(){
	newImg=$('illustration'+cpt);
	if (!newImg) return;
	simg.onload=loadIllustration;
	simg.src=imglist[ci];
	cpt++;	
}

function addLoader(id){
	var element=$(id);
	var margin=($(element.parentNode.id).clientHeight-16)/2;
	
	addImage(id,"img/loader.gif",false,margin);
}

function setOpacity(element,val){
	if(element.filters){
		try {
			element.filters.item("DXImageTransform.Microsoft.Alpha").opacity=val;
		}
		catch(e){
			element.style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity='+val+')';
		}
	} 
	else{
		element.style.opacity=val/100;
	}
}

var containerTop=0;

function resizeWindow(){
	resizeContainer();
	resizeSlide();
	resizeModal();
}

function resizeModal(){

}

function resizeSlide(){

}

function resizeContainer(){
	var left=window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
	var top=window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
	var obj=$("container");
	
	obj.style.left=Math.max((left + (getWindowWidth() - obj.offsetWidth) / 2), 0) + "px";
	containerTop=Math.max((top + (getWindowHeight() - obj.offsetHeight) / 2), 0);
	obj.style.top=containerTop + "px";
}

function init(){
	resizeWindow();
	
	addEvent(window,"resize",resizeWindow);
	
	if (document.all)
		document.documentElement.onscroll = resizeWindow;
}

