var bts_menu = new Array();
var base =  document.getElementsByTagName('base')[0].href;

var pub_v = false;
var pub_h = false;

function init_site(){
	init_menu();
	init_pub();
}

function init_pub(){
	
}
var menu_trans = 250;
var menu_d_nums;


function init_menu(){
	var mnu = document.getElementById('menu').getElementsByTagName('div');
	for(u=0; u<mnu.length; u++){
		var div = mnu[u];
		if(div.className == 'menu_div_l'){
			var divi = div.getElementsByTagName('div')[0];
			var divd = div.getElementsByTagName('div')[1];
						
			div.twd = new Tween(divd, {'height':0, 'opacity':0});
			div.tw = new Tween(divi,{'opacity':0});
			divi.style.display="block";
			div.to;
			
			div.ouvrir = function(){
				clearTimeout(this.to);
				var divi = this.getElementsByTagName('div')[1].getElementsByTagName('div')[0];
				if(divi){
					var h =taille_elem(divi);
					h = h.h;
				}else{
					var h = 0;	
				}
				this.tw.moveTo({'opacity':100}, menu_trans);	
				this.twd.moveTo({'height':h, 'opacity':100}, menu_trans*2);	
			}
			div.fermer = function(){
				var lc = this;
				clearTimeout(this.to);
				this.to = setTimeout(function(){lc.fermok()},100);
			}
			
			div.fermok = function(){
				this.tw.moveTo({'opacity':0}, menu_trans);	
				this.twd.moveTo({'height':0,'opacity':0}, menu_trans*2);	
			}
			
			div.onmouseover = function(){
				this.ouvrir();
				this.hov = true;
			}
			
			if(div.id == "rech"){				
				div.inp_foc = false;
				div.hov = false;
				var inp = div.getElementsByTagName('input')[0];
				inp.top = div;
				
				inp.onfocus = function(){
					this.top.inp_foc = true;
				}
				inp.onblur = function(){
					this.top.inp_foc = false;
					if(!this.top.hov){
						this.top.fermer();
					}
				}
				div.onmouseout = function(){
					this.hov = false;
					if(!this.inp_foc){
						this.fermer();
					}
				}
			
			}else{	
				
				div.onmouseout = function(){
					this.fermer();
				}
			}
		}
	}
	menu_d_nums = new mags_menu();
}


function mags_menu(){
		this.bords = 40;
		this.barre = document.getElementById('bande_mag_menu');
		this.width_barre = parseInt(this.barre.style.width);
		this.btg = document.getElementById('ban_d_bt_g');
		this.btd = document.getElementById('ban_d_bt_d');
		this.btg.mult = 1;
		this.btd.mult = -1;
		this.interv;
		this.left = this.bords;
		this.max_boug = (this.width_barre-980)*-1;
		
		var laclass = this;
		this.btg.onmouseover = this.btd.onmouseover = function(){
			clearInterval (laclass.interv);
			var tt = this.mult;
			laclass.interv = setInterval(function(){laclass.bouge(tt)},25);
		}
		this.btg.onmouseout = this.btd.onmouseout = function(){
			clearInterval (laclass.interv);
		}
		
		this.bouge = function(mult){
			this.left += 15*mult;
			this.placer();
			
		}
		
		this.placer = function(){
			if(this.left > 0){
				this.left = 0;
				clearInterval(this.interv);
			}else if(this.left < this.max_boug){
				this.left = this.max_boug;
				clearInterval(this.interv);
			}
			
			if(this.left >=- 200){
				var al = Math.abs(this.left/2);
				alpha(this.btg, al);	
			}
			
			if(this.left <= this.max_boug + 200){
				var al = Math.abs((this.max_boug-this.left)/2);
				alpha(this.btd, al);	
			}
			
			this.barre.style.left = this.left+'px'; 
		}
		this.placer();
}

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};	
	}
}

function alpha(obj, opa){
	
	obj.style.visibility = (opa ==0)?'hidden':'visible';
	
	if(document.all && !window.opera){ 
		 //elem.style.filter = "alpha(opacity=" + opa + ");";
		
		obj.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + (opa) + ')';
		
		if(opa>99){
			obj.style.filter='';
		}
	}else{
		opa = Math.round(opa);
		var Val = opa/100;
		if(isNaN(Val))return;
		
		obj.style.setProperty( "-moz-opacity", Val, "");
		obj.style.setProperty( "-khtml-opacity", Val, "");
		obj.style.setProperty( "opacity", Val, "");
	  
	}
	
}

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 agrandirIma(id){
	var fond = fond_noir.init();
	var ima = document.createElement('img');
	var div = document.createElement('div');
	ima.src = 'images/couvertures/grand/'+id+'.jpg';
	div.style.height = 670+'px';
	div.appendChild(ima);
	div.className="image_centr_top";
	
	fond.attach(div);
	
	fond.aff(true);
}
function init_articles(){
	var as = document.getElementById('contenu').getElementsByTagName('a');
	for(r=0; r<as.length; r++){
		var a=as[r];
		if(a.target == 'photos'){
			a.onclick = function(){return imaArt(this)}
		}
	}
}

var aj_leg;

function imaArt(id){
	var fond = fond_noir.init();
	var ima = document.createElement('img');
	var leg = document.createElement('div');
	var div = document.createElement('div');
	
	var imi = id.getElementsByTagName('img')[0];
	var src = imi.src.match(/([^//_]+)_\d+\.(\w{3})$/);
	
	leg.style.color = '#ffffff';
	
	ima.src = 'images/articles/maxi/'+src[1]+'.'+src[2];
		
	div.style.height = 700+'px';
	div.appendChild(ima);
	div.appendChild(leg);
	div.className="image_centr_top";
	
	fond.attach(div);
	
	aj_leg = new ajax();
	aj_leg.loadvar('ajax/legendes.php?id='+src[1]);
	aj_leg.response = function(val){
		leg.innerHTML = val;
	}
	fond.aff(true);
	return false;
}


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