	//
	// Copyright © 2001-2007, ECILIA SARL, Francis PALLINI
	//

	/*
	 * Animation de défilement
	 */

	var scrolls = new Array()

	function scroll(container_id, content_id) {
		this.bounce_period    = 2000
		this.period           = 40
		this.position         = 0
		this.speed            = 1
		this.direction        = -this.speed
		this.upward           = true
		this.active           = true
		this.disabled         = false
		this.container        = $(container_id)
		this.content          = $(content_id)
		this.container_height = this.container.offsetHeight
		this.content_height   = this.content.offsetHeight
		this.upward_max       = this.container_height - this.content_height
		this.downward_max     = 0

		scrolls.push(this)
		this.index = scrolls.length - 1

		this.start   = scroll_start
		this.suspend = scroll_suspend
		this.resume  = scroll_resume
	}

	function scroll_start() {
		if( this.container_height == 0
			|| this.content_height == 0
			|| this.container_height > this.content_height
			|| this.content_height - this.container_height < .05 * this.container_height )
			this.disabled = true
		if( ! this.disabled )
			this.active = true
		setTimeout("scroll_step(" + this.index + ")", this.bounce_period)
	}

	function scroll_suspend() {
		this.active = false
	}

	function scroll_resume() {
		this.active = true
	}

	function scroll_step(index) {
		var self = scrolls[index]
		var period = self.period
		if( ! self.disabled && self.active ) {
			self.position += self.direction
			self.content.style.top = self.position + "px";
			if( self.upward && self.position <= self.upward_max ) {
				self.upward = false
				self.direction = self.speed
				period = self.bounce_period
			} else if( ! self.upward && self.position >= self.downward_max ) {
				self.upward = true
				self.direction = -self.speed
				period = self.bounce_period
			}
		}
		setTimeout("scroll_step(" + self.index + ")", period)
	}

	/*
	 * Animation d'apparition
	 */

	var fades = new Array()

	function fade(container_id) {
		this.period    = 40
		this.duration  = 2000
		this.container = $(container_id)

		fades.push(this)
		this.index = fades.length - 1

		this.start = fade_start
	}

	function fade_start(from_color, to_color) {
		var steps = Math.floor(this.duration / this.period)

		var rf = parseInt(from_color.substr(1, 2), 16)
		var gf = parseInt(from_color.substr(3, 2), 16)
		var bf = parseInt(from_color.substr(5, 2), 16)
		var rt = parseInt(to_color.substr(1, 2), 16)
		var gt = parseInt(to_color.substr(3, 2), 16)
		var bt = parseInt(to_color.substr(5, 2), 16)

		for(var i = 0; i < steps; i++) {
			var r = Math.floor(rf + (rt - rf) / steps * i)
			var g = Math.floor(gf + (gt - gf) / steps * i)
			var b = Math.floor(bf + (bt - bf) / steps * i)
			var color = rgb_to_hex(r, g, b)

			setTimeout("fade_step(" + this.index + ", '" + color + "')", i * this.period)
		}
	}

	function fade_step(index, color) {
		fades[index].container.style.backgroundColor = color
	}

	function create_fade(container_id, from_color, to_color) {
		if( ! $(container_id) )
			return
		var object = new fade(container_id)
		object.start(from_color, to_color)
		return object
	}

	/*
	 * Contour de boîte (basé sur le travail de Gilbert HYATT : http://pajaj.sourceforge.net/)
	 */

	function init_octopus() {
		classTree    = new Array(2);
		classTree[0] = ["north", "east", "south", "west", "ne", "se", "sw", "nw"]
		classTree[1] = ["east", "south", "ne", "se", "sw"]
		classNames   = ["border1", "border2"]

		tempdivs = []
		divs = document.getElementsByTagName("div")
		for(i = 0; i < divs.length; i++) {
			for(j = 0; j < classNames.length; j++) {
				cdiv = divs[i]
				if( cdiv.className.indexOf(classNames[j]) > -1 ) {
					tempinner = cdiv.innerHTML
					cdiv.innerHTML = ""
					prevdiv = cdiv
					for(a = 0; a < classTree[j].length; a++) {
						tempdivs[a]           = document.createElement("div")
						tempdivs[a].className = classTree[j][a]
						prevdiv.appendChild(tempdivs[a])
						prevdiv = tempdivs[a]
					}
					prevdiv.innerHTML = tempinner
				}
			}
		}
	}

	/*
	 * Misc.
	 */

	function rgb_to_hex(r, g, b) {
		r = r.toString(16); if( r.length == 1 ) r = '0' + r;
		g = g.toString(16); if( g.length == 1 ) g = '0' + g;
		b = b.toString(16); if( b.length == 1 ) b = '0' + b;
		return "#" + r + g + b;
	}

	function loadAnimation() {
			init_octopus()

			if( $("news_scroll") ) {
				var news_scroll = new scroll("news_scroll", "news_content")

				Event.observe("news_scroll" , "mouseover", function() { news_scroll.suspend() })
				Event.observe("news_scroll" , "mouseout",  function() { news_scroll.resume()  })

				news_scroll.start()
			}

			if( $("error_fade") ){
				create_fade("error_fade", "#FFFFFF", "#FFDDDD")
			}
	}

	Event.observe(window, "load", loadAnimation)