/***************************************************************************
 *				javascript.js
 *				-------------
 *	Cree le		: 27 Fevrier 2007
 *	Derniere modif.	: 4 Juin 2007
 *	Auteur		: Asselin Benoit Developpement
 *	Email		: contact(a)ab-d.fr
 *
 ***************************************************************************/



var nAvionMoveX = -100;
var nAvionMoveY = 200;
function nAvion(speed) {
	var nAvionId = Doc.id('n-avion');
	if (nAvionId && speed >= 10) {
		nAvionId.style.left = '480px';
		nAvionId.style.top = '30px';
		
	} else if (nAvionId && speed) {
		nAvionMoveX += (0.5 * speed);
		nAvionMoveY -= (0.1 * speed);
		
		if (nAvionMoveX >= 1000) {
			nAvionMoveX = -100;
			nAvionMoveY = 200;
		}
		
		nAvionId.style.left = nAvionMoveX + 'px';
		nAvionId.style.top = nAvionMoveY + 'px';
		
		setTimeout( function() { nAvion(speed); } , 20);
	}
}



function ClassScrollbar(v_id) {
	this.id = Doc.id(v_id);
	this.idContent = Doc.id(v_id + '-content');
	this.idScrollBar = Doc.id(v_id + '-scrollbar');
	this.idScrollButton = Doc.id(v_id + '-scrollbutton');
	this.buttonMove = false;
	this.scrollRatio = 0;
	this.MsIE = (navigator.appName == 'Microsoft Internet Explorer') ? true : false;
	
	this.initialization();
}

ClassScrollbar.prototype = {
	initialization : function() {
		this.idScrollBar.onmousedown = this.scrollMousedown._bindEvent(this);
		this.idScrollBar.onmousemove = this.scrollMousemove._bindEvent(this);
		this.idScrollBar.onmouseup = this.scrollMouseup._bindEvent(this);
		
		if (this.MsIE) {
			this.id.unselectable = true;
			this.idContent.unselectable = true;
			this.idScrollBar.unselectable = true;
			this.idScrollButton.unselectable = true;
		}
		
		if (this.id.addEventListener) {
			document.addEventListener('DOMMouseScroll', this.scrollMousewheel._bindEvent(this), false);
		}
		document.onmousewheel = this.scrollMousewheel._bindEvent(this);
		document.onmousewheel = this.scrollMousewheel._bindEvent(this);
	},
	
	scrollMousedown : function(v_e) {
		if (FixEvent.isLeftClick(v_e)) {
			document.getElementsByTagName('body')[0].onmousemove = this.scrollMousemove._bindEvent(this);
			document.getElementsByTagName('body')[0].onmouseup = this.scrollMouseup._bindEvent(this);
			this.buttonMove = true;
			this.scrollMousemove(v_e);
		}
	},
	scrollMousemove : function(v_e) {
		if (this.buttonMove) {
			var v_fixCursor = (this.MsIE) ? ((Doc.id('container').offsetTop / 2) + 160) : (Doc.id('container').offsetTop + 160);
			var v_min = 0;
			var v_max = this.idScrollBar.offsetHeight - this.idScrollButton.offsetHeight;
			
			var v_top = FixEvent.pointerY(v_e) - v_fixCursor;
			
			
			if (v_top < v_min) { v_top = v_min; }
			if (v_top > v_max) { v_top = v_max; }
			this.buttonStyle(v_top);
			
			this.scrollRatio = v_top / v_max;
			this.contentStyle();
		} else {
			this.scrollMouseup();
		}
		
		FixEvent.stop(v_e);
	},
	scrollMouseup : function(v_e) {
		document.getElementsByTagName('body')[0].onmousemove = null;
		document.getElementsByTagName('body')[0].onmouseup = null;
		this.buttonMove = false;
	},
	
	scrollMousewheel : function(v_e) {
		var v_d = 0;
		if (v_e.wheelDelta) {
			v_d = v_e.wheelDelta / 120; 
		} else if (v_e.detail) {
			v_d = -v_e.detail / 3;
		}
		if (v_d > 0) { 
			this.scrollMousewheelmove(-15);
		} else if (v_d < 0) {
			this.scrollMousewheelmove(+15);
		}
		return false;
	},
	scrollMousewheelmove : function(v_move) {
		var v_min = 0;
		var v_max = this.idScrollBar.offsetHeight - this.idScrollButton.offsetHeight;
		
		var v_top = this.idScrollButton.offsetTop + v_move;
		
		if (v_top < v_min) { v_top = v_min; }
		if (v_top > v_max) { v_top = v_max; }
		this.buttonStyle(v_top);
		
		this.scrollRatio = v_top / v_max;
		this.contentStyle();
	},
	
	moveTo : function(v_pourcent) {
		var v_min = 0;
		var v_max = this.idScrollBar.offsetHeight - this.idScrollButton.offsetHeight;
		
		var v_top = v_pourcent * v_max;
		
		if (v_top < v_min) { v_top = v_min; }
		if (v_top > v_max) { v_top = v_max; }
		this.buttonStyle(v_top);
		
		this.scrollRatio = v_top / v_max;
		this.contentStyle();
		
		return false;
	},
	
	buttonStyle : function(v_top) {
		if (this.idScrollButton) {
			if (this.idContent.offsetHeight > this.id.offsetHeight) {
				this.idScrollButton.style.top = v_top + 'px';
			} else {
				this.idScrollButton.style.top = '0px';
			}
		}
	},
	contentStyle : function() {
		if (this.idContent.offsetHeight > this.id.offsetHeight) {
			var v_height = this.idContent.offsetHeight - this.id.offsetHeight;
			this.idContent.style.top = -(v_height * this.scrollRatio) + 'px';
		} else {
			this.idContent.style.top = '0px';
		}
	}
}



function deplier(id) {
	var timeMs = 100;
	
	if (Doc.id(id + '-').className == 'deplier') {
		Doc.id(id + '-').className = 'de-replier';
		Doc.id(id).style.display = '';
		setTimeout( function(){ deplier(id); }, timeMs);
	} else if (Doc.id(id + '-').className == 'de-replier') {
		Doc.id(id + '-').className = 'replier';
		Doc.id(id).style.display = 'none';
		
	} else if (Doc.id(id + '-').className == 'replier') {
		Doc.id(id + '-').className = 're-deplier';
		Doc.id(id).style.display = 'none';
		setTimeout( function(){ deplier(id); }, timeMs);
	} else if (Doc.id(id + '-').className == 're-deplier') {
		Doc.id(id + '-').className = 'deplier';
		Doc.id(id).style.display = '';
	}
}

var deplierMode = 0;
function deplierTout() {
	deplierMode++;
	if (deplierMode > 2) { deplierMode = 0; }
	
	var inc = 0;
	while (Doc.id('liaison-texte-' + inc)) {
		if (deplierMode == 0) {
			Doc.id('liaison-texte-' + inc + '-').className = 'replier';
			Doc.id('liaison-texte-' + inc).style.display = 'none';
			if (Doc.id('liaison-commentaire-' + inc)) {
				Doc.id('liaison-commentaire-' + inc + '-').className = 'deplier';
				Doc.id('liaison-commentaire-' + inc).style.display = '';
			}
		} else if (deplierMode == 1) {
			Doc.id('liaison-texte-' + inc + '-').className = 'deplier';
			Doc.id('liaison-texte-' + inc).style.display = '';
			if (Doc.id('liaison-commentaire-' + inc)) {
				Doc.id('liaison-commentaire-' + inc + '-').className = 'replier';
				Doc.id('liaison-commentaire-' + inc).style.display = 'none';
			}
		} else if (deplierMode == 2) {
			Doc.id('liaison-texte-' + inc + '-').className = 'deplier';
			Doc.id('liaison-texte-' + inc).style.display = '';
			if (Doc.id('liaison-commentaire-' + inc)) {
				Doc.id('liaison-commentaire-' + inc + '-').className = 'deplier';
				Doc.id('liaison-commentaire-' + inc).style.display = '';
			}
		}
		inc++;
	}
	
	return false;
}



function noSpam(mt1,mt2,mt3) {
	var link = 'mailto:' + mt1 + '@' + mt2 + '.' + mt3;
	location.href = link;
	return false;
}


