// JavaScript Document

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

var BoxHeights = {

	maxh: 0,
	maxb: 0,
	boxes: Array(),
	num: 0,

	equalise: function() {
		this.num = arguments.length;
		for (var i=0;i<this.num;i++) if (!$(arguments[i])) return;
		this.boxes = arguments;
		this.maxheight();
		for (var i=0;i<this.num;i++) $(arguments[i]).style.height = this.maxh + "px";
	},
	
	baseline: function() {
		this.num = arguments.length;
		for (var i=0;i<this.num;i++) if (!$(arguments[i])) return;
		this.boxes = arguments;
		this.findBase();
		for (var i=0;i<this.num;i++) $(arguments[i]).style.height = (this.maxb - $(arguments[i]).offsetTop) + "px";
	},
	
	findBase: function() {
		var bottoms = new Array();
		for (var i=0;i<this.num;i++) {
			if (navigator.userAgent.toLowerCase().indexOf('opera') == -1) {
				bottoms.push($(this.boxes[i]).offsetTop + $(this.boxes[i]).scrollHeight);
			} else {
				bottoms.push($(this.boxes[i]).offsetTop + $(this.boxes[i]).offsetHeight);
			}
		}
		bottoms.sort(this.sortNumeric);
		this.maxb = bottoms[this.num - 1];
	},

	maxheight: function() {
		var heights = new Array();
		for (var i=0;i<this.num;i++) {
			if (navigator.userAgent.toLowerCase().indexOf('opera') == -1) {
				heights.push($(this.boxes[i]).scrollHeight);
			} else {
				heights.push($(this.boxes[i]).offsetHeight);
			}
		}
		heights.sort(this.sortNumeric);
		this.maxh = heights[this.num-1];
	},

	sortNumeric: function(f,s) {
		return f-s;
	}
}

function resizeMyColumns() {
	BoxHeights.baseline("menu_column", "main_column", "maincontainer");
	BoxHeights.baseline("sommaire_float", "couv_float");
	BoxHeights.baseline("sellerie_float", "stages_float");
}
addLoadEvent(resizeMyColumns);
