// JavaScript Document

function popima(id){
	var fond = fond_noir.init();
	var ima = document.createElement('img');
	var div = document.createElement('div');
	ima.src = id.href;
	
	div.style.height = 670+'px';
	div.appendChild(ima);
	div.className="image_centr_top";
	
	fond.attach(div);
	
	fond.aff(true);
	return false;
}


var tw_menu;
var ss_menu_to;
function init_ss_menu(){	
	tw_menu = new Tween(document.getElementById('menu_d'),{'height':0});
	
}

function aff_ss_menu(idd){
	
		clear_to();
		var div_sm =document.getElementById('ss_menu_int');
		var aff_m = false;
		var d = div_sm.firstChild;
		var h = 0;
		do{
			if(d.nodeType == 1 && d.nodeName.toUpperCase()=='DIV'){
				
				aff_m = true;
				
				
				 if(d.id == 'ss_menu_cont_'+idd){
					if(d.innerHTML &&  d.innerHTML != ''){
					  var mdd = document.getElementById('menu_d').style.display;
					  document.getElementById('menu_d').style.display= 'block';
					  d.style.display = 'block';
					  h =d.offsetHeight;
					  document.getElementById('menu_d').style.display= mdd;
					}else{
						d.style.display = 'none';
						aff_m = false;
					}
				  }else{
					  d.style.display = 'none';
				  }
				
				
				
			}
		}while(d = d.nextSibling);
		if(aff_m){
			aff_ss_menu_anim(h);
		}else{
			hide_ss_menu();
		}
		/*
		var divs = div_sm.getElementsByTagName('div');
		var aff_m = false;
		var h = 0; 
		
		if(document.getElementById('ss_menu_cont_'+id)){
			aff_m = true;
		
		
		  for(var t = 0 ; t<divs.length; t++){
			  var d =divs[t];
			  
			  if(d.id == 'ss_menu_cont_'+id){
					
				if(d.innerHTML &&  d.innerHTML != ''){
				  var mdd = document.getElementById('menu_d').style.display;
				  document.getElementById('menu_d').style.display= 'block';
				
				  d.style.display = 'block';
				 
				 
				  h =d.offsetHeight;
				  document.getElementById('menu_d').style.display= mdd;
				}else{
					d.style.display = 'none';
					aff_m = false;
				}
			  }else{
				  d.style.display = 'none';
			  }
		  }
		}
		if(aff_m){
			aff_ss_menu_anim(h);
		}else{
			hide_ss_menu();
		}*/
}


function aff_ss_menu_anim(h){
	//h+=5;
	document.getElementById('menu_d').style.display = 'block';
	tw_menu.moveTo({'height':h},255);
	tw_menu.onComplete = function(){};
}

function clear_to(){
	clearTimeout(ss_menu_to);
}

function hide_ss_menu(){
	ss_menu_to = window.setTimeout(function(){hid_ss_menu()},100);
}
function hid_ss_menu(){
	tw_menu.moveTo({'height':0},250);
	tw_menu.onComplete = function(){	document.getElementById('menu_d').style.display = 'none';};
}

var fond_noir = {
		'fond':false,
		'twin':null,
		'twinC':null,
		'cont':null,
		'cont_int':null,
		'clicClose':true,
		'croixfond':null,
		'croixfondtw':null,
		'_pos':function(){
			
			this.cont.style.top = window_pos()['scroll_v']+'px';
			this.cont.style.height = window_pos()['height']+'px';
		},
		
		'aff' : function(visible){
				this.twin.moveTo({'opacity':(visible)?95:0},250);
				this.twinC.moveTo({'opacity':(visible)?100:0},250);
				
				
				
				if(visible){
					this.fond.style.display = this.cont.style.display = 'block';
					this.twin.onComplete = function(){};
					this._pos();
				}else{
					var laclass = this;
					this.twin.onComplete = function(){laclass.fin();};
				}
				
				if(this.clicClose){
					
				}else{
					
					if(!this.croixfond){
						this.croixfond = document.createElement('div');
						this.croixfond.className = 'croix_fond';
						this.cont.appendChild(this.croixfond);
						this.croixfondtw = new Tween(this.croixfond,{'opacity':40});
						this.croixfond.onclick = function(){fond_noir.aff(false);}
						this.croixfond.onmouseover = function(){fond_noir.croixfondtw.moveTo({'opacity':80},250);}
						this.croixfond.onmouseout  = function(){fond_noir.croixfondtw.moveTo({'opacity':40},250);}
					}else{
						this.cont.appendChild(this.croixfond);
					}
				}
		},		
		'init' : function(){
			if(!this.fond){
				this.fond = document.createElement('div');
				this.fond.className = 'fond_noir';
				this.fond.style.height = taille_elem(document.getElementById('container'))['h']+'px';
				var bdy = document.getElementsByTagName('body')[0];
				bdy.appendChild(this.fond);
				
				
				this.cont = document.createElement('div');
				this.cont.className = 'cont_top';
				var bdy = document.getElementsByTagName('body')[0];
				bdy.appendChild(this.cont);
				
				
				this.twin = new Tween(this.fond, {'opacity':0});
				this.twinC = new Tween(this.cont, {'opacity':0});
				
				this.fond.onclick=  function(){
					fond_noir.aff(false);	
				}
				this.cont.onclick=function(){
					if(fond_noir.clicClose){
						fond_noir.aff(false);	
					}
				}
				
				this.fond.style.display = this.cont.style.display = 'none';
			}
			return this;
		},
		'attach' : function(elem){
			this.cont.innerHTML = '';
			this.cont_int = elem;
			this.cont.appendChild(this.cont_int);
			setTimeout(function(){fond_noir.verticalAlign();},5);
			
		},
		'verticalAlign'  : function(){
			var h_cont = taille_elem(this.cont_int)['h'];
			var haut = window_pos()['height'];
			if(h_cont){				
				var top = (haut/2)-(h_cont/2);
			}else{
				var top = 0;	
			}
			
			this.cont_int.style.marginTop = top+'px';
			
		},
		'fin' : function(){
			this.fond.style.display= this.cont.style.display  = 'none';
			this.onComplete();
			this.cont.innerHTML = '';		
		},
		'onComplete':function(){}
		
};

function taille_elem(obj){
	if(obj.offsetHeight){
		return {'w':obj.offsetWidth, 'h':obj.offsetHeight};
	}else if(obj.style.pixelHeight){
		return {'w':obj.pixelWidth, 'h':obj.pixelHeight};
	}else{
		return {'w':0, 'h':0};
	}
}

function window_pos(){
	if(document.documentElement){
		return {'scroll_h':document.documentElement.scrollLeft,'scroll_v':document.documentElement.scrollTop, 'width':document.documentElement.clientWidth, 'height':document.documentElement.clientHeight};
	}else if(document.body){		
		return {'scroll_h':document.body.scrollLeft,'scroll_v':document.body.scrollTop, 'width':document.body.clientWidth, 'height':document.body.clientHeight};
	}else{
		return {'scroll_h':0,'scroll_v':0, 'width':0, 'height':0};	
	}
}
