
// JavaScript Document

function popup(url) {

	w = 900 ;
	h = 550 ;
	win = window.open(url, "popup", "left=" + (screen.availWidth-w)/2 + ", top=" + (screen.availHeight-h)/2 + ", width=" + w + ", height=" + h + ", status=0, resizable=0, dependent=1, scrollbars=1") ;
	win.focus() ;
}

function img_open(src) {
	
	document.getElementById('img_div').innerHTML = "<br />Cliquez sur l'image pour fermer</a><br /><br /><a href=\"javascript:;\" onclick=\"img_close(); return false;\"><img src=\"" + src + "\" alt=\"\" /></span>" ;

	document.getElementById('img_div_bg').style.display	= "block" ;
	document.getElementById('img_div').style.display	= "block" ;
}

function img_close() {

	document.getElementById('img_div_bg').style.display	= "none" ;
	document.getElementById('img_div').style.display	= "none" ;
}


function hide_avatar() {
	
	//document.getElementById('avatar').style.display = 'none' ;
	fade('avatar', -0.05) ;
}

function avatar_close() {
	
	set_style("avatar", "display", "none") ;
	set_style("home_video_container", "display", "block") ;
	set_style("home_video_flash_container", "display", "block") ;
	set_style("home_video_flash", "display", "block") ;
}
function avatar_resize(w, h) {
	
	set_style("avatar", "width", w + "px") ;
	set_style("avatar", "height", h + "px") ;
}

var userAgent = navigator.userAgent.toLowerCase() ;
var is_opera  = (userAgent.indexOf('opera') != -1) ;
var is_saf    = ((userAgent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.")) ;
var is_webtv  = (userAgent.indexOf('webtv') != -1) ;
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv)) ;

function get_style(id, param) {
	
	var obj = document.getElementById(id) ;	
	
	if (! obj)				return false ;
	
	if (param == "opacity")	return get_opacity(id) ;
	
	return obj.style[param] ;
	
}

function set_style(id, param, value) {
	
	var obj = document.getElementById(id) ;	
	
	if (! obj)				return false ;
	
	if (param == "opacity")	return set_opacity(id, value) ;
	
	obj.style[param] = value ;
	
	return true ;
	
}

function get_opacity(id) { // return [0.0, 1.0]

	var obj = document.getElementById(id) ;
	var value = 1.0 ;
	
	if (is_ie) {
		var regexp = /alpha\(opacity=([0-9]*)\)/ ;
		if (regexp.exec(obj.style.filter))
			value = RegExp.$1 / 100 ;
	} else if (obj.style.opacity != "undefined") {
		
		if (obj.style.opacity != "")
			value = obj.style.opacity ;
	}
	
	return value ;

}

function set_opacity(id, value) { // value [0.0, 1.0]

	var obj = document.getElementById(id) ;
	
	if (value == 0.0 && obj.style.display != "none")
		obj.style.display = "none" ;
	else if (value > 0.0 && obj.style.display != "block")
		obj.style.display = "block" ;
		
	if (is_ie)
		obj.style.filter = value >= 1.0 ? "" : "alpha(opacity=" + (value * 100) + ")" ;
	else if (obj.style.opacity != "undefined")
		obj.style.opacity = value ;
	
	return true ;
	
}

function _fade(id, value, end, offset, remove) {
	
	var obj = document.getElementById(id) ;
	if (! obj) return ;
	
	if (offset == 0.0)
		return ;
	
	if ((offset > 0.0 && value > end) || (offset < 0.0 && value < end))
		value = end ;
		
	set_opacity(id, value) ;
	
	if (value == end) {		
		if (remove && obj.parentNode)
			obj.parentNode.removeChild(obj) ;
		return ;
	}
		
	value = parseFloat(value) + parseFloat(offset) ;
	
	obj.fade_timer_id = setTimeout("_fade('" + id + "', " + value + ", " + end + ", " + offset + ", " + remove + ")", 10) ;
	
}

function fade(id, offset, remove) {
	
	//alert(remove) ;
	
	remove = (remove == true) ;
	
	var obj = document.getElementById(id) ;
	if (! obj) return ;
	
	if (obj.fade_timer_id)
		clearTimeout(obj.fade_timer_id) ;
	
	var value	= get_opacity(id) ;
	var end		= offset > 0.0 ? 1.0 : 0.0 ;
	
	_fade(id, value, end, offset, remove) ;
	
}

function _move(id, from_x, from_y, to_x, to_y, offset) {
	
	var obj = document.getElementById(id) ;
	if (! obj) return ;
	
	var curr_x = get_style(id, "left") ;
	var curr_y = get_style(id, "top") ;
	
	curr_x = parseInt(curr_x.substr(0, curr_x.search(/px/i))) ;
	curr_y = parseInt(curr_y.substr(0, curr_y.search(/px/i))) ;
	
	if (curr_x == to_x && curr_y == to_y)
		return ;
		
	var offset_x = Math.ceil(Math.sin(Math.PI * Math.abs((curr_x + (from_x < to_x ? 1 : -1) - from_x) / (to_x - from_x))) * offset) ;
	var offset_y = Math.ceil(Math.sin(Math.PI * Math.abs((curr_y + (from_y < to_y ? 1 : -1) - from_y) / (to_y - from_y))) * offset) ;
	
	if (curr_x < to_x && curr_x + offset_x < to_x) {
		set_style(id, "left", (curr_x + offset_x) + "px") ;
	} else if (curr_x > to_x && curr_x - offset_x > to_x) {
		set_style(id, "left", (curr_x - offset_x) + "px") ;
	} else {
		set_style(id, "left", to_x + "px") ;
	}
	
	if (curr_y < to_y && curr_y + offset_y < to_y) {
		set_style(id, "top", (curr_y + offset_y) + "px") ;
	} else if (curr_y > to_y && curr_y - offset_y > to_y) {
		set_style(id, "top", (curr_y - offset_y) + "px") ;
	} else {
		set_style(id, "top", to_y + "px") ;
	}
	
	obj.move_timer_id = setTimeout("_move('" + id + "', " + from_x + ", " + from_y + ", " + to_x + ", " + to_y + ", " + offset + ")", 10) ;
	
}

function move(id, to_x, to_y, offset) {
	
	var obj = document.getElementById(id) ;
	if (! obj) return ;
	
	if (obj.move_timer_id)
		clearTimeout(obj.move_timer_id) ;
	
	var from_x = get_style(id, "left") ;
	var from_y = get_style(id, "top") ;
	
	from_x = parseInt(from_x.substr(0, from_x.search(/px/i))) ;
	from_y = parseInt(from_y.substr(0, from_y.search(/px/i))) ;
	
	_move(id, from_x, from_y, to_x, to_y, offset) ;
	
}


function resizeEncart(encartWidth, encartHeight){
	document.getElementById('home_video_flash_container').style.height = encartHeight+'px';
	document.getElementById('home_video_flash_container').style.width = encartWidth+'px';
}