var fadeBoxNbre = 0;
var fadeBoxFct;
if (!fadeBoxFct) fadeBoxFct = function() {
	
	//var fichier = fichier;
	var obj = this;
	
	this.show_fadebox = function (fichier) {
	
		var xhr=null;
			
			if (window.XMLHttpRequest) { 
				xhr = new XMLHttpRequest();
			}
			else if (window.ActiveXObject) 
			{
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			
			xhr.onreadystatechange = function(){
													if (xhr.readyState==4 && xhr.status == 200) 
													{	
														response = xhr.responseText;
														fadeBoxNbre++;
														obj.construct_fadebox(response);
														obj.fadebox.style.backgroundImage='none';
													}
												}
			xhr.open("GET", fichier, true); 
			xhr.send(null);
	}
	this.fadebox = false;
	this.fadebox_close = false;
	this.fadebox_content = false;
	this.construct_fadebox = function (content) {
	if(!this.fadebox)
		{
			
			this.fadebox = document.createElement('div');
			this.fadebox.style.position = 'absolute';
			this.fadebox.style.backgroundImage = 'url(../images/waiting.gif)';
			this.fadebox.style.backgroundRepeat = 'no-repeat';
			this.fadebox.style.backgroundPosition = 'center center';
			this.fadebox.style.border='none';
			this.fadebox.style.top='100px';
			this.fadebox.style.left='50%';
			this.fadebox.style.zIndex='15001';
			this.fadebox.className = 'fadebox';
			this.fadebox.setAttribute('id','fadebox_'+fadeBoxNbre);
			document.body.appendChild(this.fadebox);
			
			this.fadebox_top = document.createElement('div');
			this.fadebox_top.className = 'fadebox_top';
			this.fadebox_top.setAttribute('id','fadebox_top_'+fadeBoxNbre);
			this.fadebox.appendChild(this.fadebox_top)
			
			this.fadebox_box_close = document.createElement('div');
			this.fadebox_box_close.className = 'fadebox_box_close';
			this.fadebox_box_close.setAttribute('id','fadebox_box_close_'+fadeBoxNbre);
			this.fadebox.appendChild(this.fadebox_box_close)
			
			this.fadebox_close = document.createElement('a');
			this.fadebox_close.style.display='block';			
			this.fadebox_close.style.textDecoration='none';		
			this.fadebox_close.style.cursor='pointer';
			this.fadebox_close.className = 'fadebox_close';
			this.fadebox_close.setAttribute('id','fadebox_close_'+fadeBoxNbre);
			this.fadebox_close.onclick = function () {obj.hide_fadebox();};	
			this.fadebox_close.innerHTML = ' ';
			this.fadebox_box_close.appendChild(this.fadebox_close);
			
			this.fadebox_content = document.createElement('div');
			this.fadebox_content.className = 'fadebox_content';
			this.fadebox_content.setAttribute('id','fadebox_content_'+fadeBoxNbre);
			this.fadebox.appendChild(this.fadebox_content);
			
			this.fadebox_bottom = document.createElement('div');
			this.fadebox_bottom.className = 'fadebox_bottom';
			this.fadebox_bottom.setAttribute('id','fadebox_bottom_'+fadeBoxNbre);
			this.fadebox.appendChild(this.fadebox_bottom);
			
			this.fadebox_back = document.createElement('div');
			this.fadebox_back.style.position='absolute';
			this.fadebox_back.style.backgroundColor='#000000';
			this.fadebox_back.style.zIndex='15000';			
			var d = detectMacXFF();
			if (d) {
				//osx ff css opacity + flash wmode transparent doesn't work
				}
				else {
					this.fadebox_back.style.opacity='0.80';
					this.fadebox_back.style.KHTMLOpacity='0.80';
					this.fadebox_back.style.MozOpacity='0.80';
					this.fadebox_back.style.filter='alpha(opacity=80)';
					}
			this.fadebox_back.onclick = function () {obj.hide_fadebox();};
			this.fadebox_back.innerHTML = '&nbsp;';
			document.body.appendChild(this.fadebox_back);
		}
		
		setFade(0,this.fadebox);
		setFade(0,this.fadebox_back);
		this.fadebox.style.display='block';	
		this.fadebox_back.style.display='block';
		this.fadebox_content.innerHTML = content;
		this.get_size_fadebox();
		this.get_size_fadebox_back();
		fade(0,100,this.fadebox);
		fade(0,60,this.fadebox_back);
		window.onscroll = function () {obj.get_size_fadebox_back();};
		window.onresize = function () {obj.get_size_fadebox_back();};	
	}
	/*var getEventClose = function () {
			if(fadebox_close.addEventListener){ 
			  fadebox_close.addEventListener("click", function () {hide_fadebox();}, false); 
			}else if(momoElement.attachEvent){ 
			  fadebox_close.attachEvent("onclick", function () {hide_fadebox();}); 
			}
		}*/
	this.hide_fadebox = function () {	
		this.fadebox_content.innerHTML = '';
		this.fadebox.style.display='none';
		this.fadebox_back.style.display='none';
		}
	this.get_size_fadebox = function () {
		var posLeft;
		var posTop;
		posLeft = ((this.fadebox.offsetWidth)/2);
		posTop = (((this.fadebox.offsetHeight)+15)/2);
		this.fadebox.style.marginLeft='-'+posLeft+'px';
		this.fadebox.style.top='50%';
		this.fadebox.style.marginTop=window.getScrollTop()-posTop+'px';
		}
	
	this.get_size_fadebox_back = function () {	
			this.fadebox_back.style.top=window.getScrollTop()+'px';
			this.fadebox_back.style.left=window.getScrollLeft()+'px';
			this.fadebox_back.style.height=window.getHeight()+'px';
			this.fadebox_back.style.width=window.getWidth()+'px';
		}
	
	var detectMacXFF = function () {
	  var userAgent = navigator.userAgent.toLowerCase();
	  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
		return true;
	  }
	}
	
	
	
	var fade = function (amt,to,obj) {
		var fadeTime;
		if(amt <= to) {
			setFade(amt,obj);
			amt += 10;
			fadeTime = setTimeout(function () {fade(amt,to,obj);}, 60);
		}
		else {
			//clearTimeout(fadeTime);
			}
	}
	
	var setFade = function (amt,obj) {
		//var obj = document.getElementById("calendar");
		
		amt = (amt == 100)?99.999: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;
	}
	
	//return this.show_fadebox();
}