//////////////////////////////////////////////////////////////////
//						Variables globales						//
//////////////////////////////////////////////////////////////////
var mouseX;
var mouseY;
var bloc=new Array();
var ready=false;
//Ajout des listeners
addEvent (document, 'mousemove', getMouseXY, false);
addEvent (window, 'load', initialize, false);
//document.getElementById('loading_bar').style.display='block';

//////////////////////////////////////////////////////////////////
//						Creation des objets						//
//////////////////////////////////////////////////////////////////
function createBloc (id, zD, dX, dY){
	//Proprietes
	this.name=id;
	this.zDepth=zD;
	this.deltaX=dX;
	this.deltaY=dY;
	this.xPos=0;
	this.yPos=0;
	this.isBackground=false;
	this.isVisible=true;
	if (dX==null){ //C'est un background
		this.deltaX=-50;
		this.deltaY=-50;
		this.isBackground=true;
	}
	//Methodes
	this.move = move_bloc;
}
/////////////////////////Methodes//////////////////////////////
function move_bloc(){
	var pageW = window.innerWidth;
	var pageH = window.innerHeight;
	var deltX=((mouseX-(pageW/2))/pageW)*100;
	var deltY=((mouseY-(pageH/2))/pageH)*100;
	this.xPos=deltX*this.zDepth+this.deltaX;
	this.yPos=deltY*this.zDepth+this.deltaY;
	var object_style=document.getElementById(this.name).style;
	if (this.isBackground){//S'il s'agit d'un fond centre
		object_style.right=-100-this.xPos+'%';
		object_style.bottom=-100-this.yPos+'%';
	}
	object_style.left=this.xPos+'%';
	object_style.top=this.yPos+'%';
}
//////////////////////////////////////////////////////////////////
//						Fonction utiles							//
//////////////////////////////////////////////////////////////////
//Event listener
function addEvent (obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    //alert("Handler could not be attached");
  }
}
//Recuperer les coordonnees souris
function getMouseXY(e) {
	if (!ready)	return false; //Si l'init n'est pas faite, quitter
	var tempX = 0;
	var tempY = 0;
	tempX = e.pageX;
	tempY = e.pageY;
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	mouseX = tempX;
	mouseY = tempY;
	//Déplacer le blocs
	move_page_elements();
	return true;
}

//////////////////////////////////////////////////////////////////
//					Actions sur les blocs						//
//////////////////////////////////////////////////////////////////
//Déplacer les blocs
function move_page_elements() {
	for (var i=0;i<bloc.length;i++){
		 bloc[i].move();
	}
}
//////////////////////////////////////////////////////////////////
//						Initialisation							//
//////////////////////////////////////////////////////////////////
function initialize(){
	var k=0;
	bloc[k] = new createBloc('bloc_index_logo',.2,0,0);
	k++;
	bloc[k] = new createBloc('bloc_index_fond_logo',.1,0,0);
	k++;
	bloc[k] = new createBloc('bloc_index_fond_tagline',-.1,0,0);
	k++;
	bloc[k] = new createBloc('bloc_index_tagline',-.2,0,0);
	k++;
	ready=true;//Variable définissant la fin de l'initialisation
}
