// JavaScript Document

var maxzi = 2;
var smenus = new Array();
var numero = 0;
var baniere;

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

function init(){
	var divs = document.getElementsByTagName('div');
	var ii;
	for(ii in divs){
		if(divs[ii].className == 'sous_menu'){
			smenus[numero] = new menu_d(divs[ii], numero);
			numero++;
		}
	}
	baniere = new photo_baniere();
}


function menu_d(elem, id){
	this.id = id;
	this.elem = elem;
	this.tw_pos;
	this.tw_opa;;
	this.to;
	
	this.lien = document.getElementById('lien_'+elem.id);
	
	this.lien.laclass = this;
	this.elem.laclass = this;
	laclass = this;
	
	this.init = function(){
		laclass.tw_pos = new tween(laclass.elem, 'top', 0);
		laclass.tw_opa = new tween(laclass.elem, 'opacity', 100);
	}
	
	
	this.hover = function(){
		this.set_z(maxzi+1);
		this.tw_pos.setMove(25,500);
		this.tw_opa.setMove(100,500);
		this.tw_opa.onComplete = function(){};
		clearTimeout(this.to);
		this.lien.style.color = "#e3001f";
	}
	
	this.out = function(){
		this.tw_opa.setMove(0,500);
		this.lien.style.color = null;
		laclass = this;
		this.tw_opa.onComplete = function(){				
				var tt;
				for(tt in smenus){
					smenus[tt].set_z(2);
				}
				laclass.set_z(0);	
				laclass.init();
		}
	}
	
	
	
	this.set_z = function(val){
		this.elem.style.zIndex = val;
		maxzi = val;
	}
	
	this.setTo = function(){
		var idd = this.id;
		laclass = this;
		this.to = window.setTimeout(function(){laclass.cacher(idd)}, 100, this);
	}
	
	this.cacher = function(idd){
		smenus[idd].out();
	}
	
	
	// ------------------------------------------------------------  EVENTS
	
	this.lien.onmouseout = this.elem.onmouseout = function(){
			this.laclass.setTo(); 
	}
	
	this.lien.onmouseover = function(){
		this.laclass.hover();
	}
	
	this.elem.onmouseover = function(){
		this.laclass.hover();
	}
	
	this.init ();
}

// ------------------------------------------------------------  photots Baniere


function photo_baniere(){
	this.div_fond = document.getElementById('baniere_image');
	this.div_img = document.createElement('div');
	this.div_img.className = 'ban_img_int';
	this.div_fond.appendChild(this.div_img);
	this.tw_opa;
	this.num_img = 1;
	this.arr_img = new Array();
	this.img_def = 0;
	
	this.preload = function(){
		var ima = base+'graph/banieres/'+photos_baniere[this.num_img];
		if(!this.arr_img[this.num_img]){
			this.arr_img[this.num_img] = new Image();
			this.arr_img[this.num_img].src = ima;
		}
	}
	
	this.nextImage = function(){
		this.div_img.style.backgroundImage = 'url('+this.arr_img[this.num_img].src+')';
		this.tw_opa.setMove(100,250);
		
		
		this.num_img++;
		if(this.num_img >= photos_baniere.length){
			this.num_img = 0;
		}
		this.preload();
		
	}
	
	this.recharge = function(){
		if(this.div_img.style.backgroundImage){
			this.div_fond.style.backgroundImage = this.div_img.style.backgroundImage;
		}else{
			this.div_fond.style.backgroundImage = 'url('+ base+'graph/banieres/'+photos_baniere[this.img_def] +')';
		}
		this.div_img.style.backgroundImage = '';
		this.tw_opa = new tween(this.div_img, 'opacity', 0);
		zeclass = this;
		this.tw_opa.onComplete = function(){
			zeclass.recharge();
		}
	}
	
	
	zeclass = this;
	this.div_fond.style.cursor = 'pointer';
	this.div_fond.onclick = function(){
		zeclass.nextImage();
	}
	
	
	this.recharge();
	this.preload();
	
}