function maj_contact_res(value)
{
	var h1 = document.createElement('h1');
	h1.setAttribute("class","title_success");
	h1.update(value);
	$('formulaire_contact').update();
	$('formulaire_contact').appendChild(h1);
}

function record_contactsimple_CallBack(action,type,result)
{
	maj_contact_res(result);
}

function record_contactwebmaster_CallBack(action,type,result)
{
	maj_contact_res(result);
}

function record_contactprojetweb_CallBack(action,type,result)
{
	maj_contact_res(result);
}

function record_contactprojetlog_CallBack(action,type,result)
{
	maj_contact_res(result);
}

function upload_cdc3_CallBack(file){
	var resultup = PHX_getresultupload(file);
	resultup = resultup.replace("/","");
	if(resultup !="")
	{
		$('msg_formcdc3').update();
		var a = document.createElement('a');
		a.setAttribute("class","msg_succes");
		a.href="javascript:;";
		var span = document.createElement('span');
		span.update("Le fichier à été ajouté avec succés, il sera envoyé avec votre message");
		a.appendChild(span);
		$('msg_formcdc3').appendChild(a);
		$('formcdc3').value=resultup;
	}
	else
	{
		$('msg_formcdc3').update();
		var a = document.createElement('a');
		a.setAttribute("class","msg_erreur");
		a.href="javascript:;";
		var span = document.createElement('span');
		span.update(file.replace("{EXE_FAIL}",""));
		a.appendChild(span);
		$('msg_formcdc3').appendChild(a);
		$('formcdc3').value="";
	}
}

function upload_cdc4_CallBack(file){
	var resultup = PHX_getresultupload(file);
	resultup = resultup.replace("/","");
	if(resultup !="")
	{
		$('msg_formcdc4').update();
		var a = document.createElement('a');
		a.setAttribute("class","msg_succes");
		a.href="javascript:;";
		var span = document.createElement('span');
		span.update("Le fichier à été ajouté avec succés, il sera envoyé avec votre message");
		a.appendChild(span);
		$('msg_formcdc4').appendChild(a);
		$('formcdc4').value=resultup;
	}
	else
	{
		$('msg_formcdc4').update();
		var a = document.createElement('a');
		a.setAttribute("class","msg_erreur");
		a.href="javascript:;";
		var span = document.createElement('span');
		span.update(file.replace("{EXE_FAIL}",""));
		a.appendChild(span);
		$('msg_formcdc4').appendChild(a);
		$('formcdc4').value="";
	}
}
var d_already_clicked =false;
function AJAX_error_handler(err,param)
{
	//Recherche d'erreur fatal on l'affiche
	for(var i=0; i<err.length; i++)
	{
		if(err[i].level=='fatal')
		{
			alert(err[i].msg);
			return false;
		}
	}
	return true;
}

function getMousePosition(event)
{
    var e = event || window.event;
    var scroll = new Array((document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft,(document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop);;
    return new Array(e.clientX + scroll[0] - document.body.clientLeft,e.clientY + scroll[1] - document.body.clientTop);
}

function mouseIn(event,domobj)
{
	var mouse_pos = getMousePosition(event);
	var c_pos = domobj.cumulativeOffset();
	var c_dim = domobj.getDimensions();
	if(mouse_pos[0]<c_pos[0] || mouse_pos[0]>(c_pos[0]+c_dim.width) || mouse_pos[1]<c_pos[1] || mouse_pos[1]>(c_pos[1]+c_dim.height))
	{
		return false;
	}
	return true;
}
var modele_site = 0;
function init_modele()
{
	modele_site = $('modele_site').value;
}
/************************************
 * Animation des différents services
 ************************************/
var s_pos_h = -230;
var s_pos_b = 394;
var s_pos_h_dest = 0;
var s_pos_b_dest = 112;
var s_duration = 0.8;
var s_current=-1;
var s_delay = 8000;
var s_interval="";
var s_active = true;
function s_next_id()
{
	var tab_service = $('animation_service').select('a');
	var next = s_current+1;
	if(next>=tab_service.length)
		next=0;
	return tab_service[next].id;
}

function s_current_id()
{
	var tab_service = $('animation_service').select('a');
	return tab_service[s_current].id;
}

function s_appear(s_id)
{
	var service = s_id.replace("service_","");
	var img_h = $("haut_" + service);
	var img_b = $("bas_" + service);
	var texte = $("text_" + service);
	var ctn = $("ctn_" + service);
	var btn = $(s_id);
	if(img_h && img_b)
	{
		//Init des valeur par défaut	
		img_h.style.display = "none";
		img_h.style.top = s_pos_h + "px";
		img_b.style.display = "none";
		img_b.style.top = s_pos_b + "px";
		ctn.style.display="";
		img_h.style.display = "block";
		img_b.style.display = "block";
		
		//Animation
		new Effect.Appear(texte, { duration: s_duration , queue: { position: 'end', scope: 'texte'}});
		new Effect.Parallel([
		  new Effect.Move(img_h, { sync: true, x:0, y: s_pos_h_dest, mode: 'absolute' }), 
		  new Effect.Appear(img_h, { sync: true}) 
		], { 
		  duration: s_duration
		});
		new Effect.Parallel([
		  new Effect.Move(img_b, { sync: true, x:0, y: s_pos_b_dest, mode: 'absolute' }), 
		  new Effect.Appear(img_b, { sync: true}) 
		], { 
		  duration: s_duration,
		  queue: { position: 'end', scope: 'appear'},
		  afterFinish : function(){ 
	 		s_active=true;
	 		}
		});
		s_current = parseInt(service);
	}
}

function s_fade(s_next)
{
	s_active=false;
	var s_id = s_current_id();
	if(!s_next)
		s_next = s_next_id();
	
	var service = s_id.replace("service_","");
	var img_h = $("haut_" + service);
	var img_b = $("bas_" + service);
	var texte = $("text_" + service);
	var ctn = $("ctn_" + service);
	var btn = $(s_id);
	var btn_next = $(s_next);

	if(img_h && img_b)
	{
		//btn class name
		btn_next.className += " menu_service_current";
		btn.className = btn.className.replace(" menu_service_current","");

		//Animation
		new Effect.Fade(texte, { duration: s_duration , queue: { position: 'end', scope: 'texte'}});
		new Effect.Parallel([
			  new Effect.Move(img_h, { sync: true, x:0, y: s_pos_h, mode: 'absolute' }), 
			  new Effect.Fade(img_h, { sync: true}) 
			], { 
			  duration: s_duration
			});
			new Effect.Parallel([
			  new Effect.Move(img_b, { sync: true, x:0, y: s_pos_b, mode: 'absolute' }), 
			  new Effect.Fade(img_b, { sync: true}) 
			], { 
			  duration: s_duration,
			  queue: { position: 'end', scope: 'fade'},
			  afterFinish : function(){ 
				ctn.style.display="none";
				s_appear(s_next);
				s_active = true;
			  }
		});
	}
}


/************************************
 * Récuperation des demos
 ************************************/
var d_path ='front/demo/';
function d_get_tpl(demo)
{
	var tpl = d_path + demo + "/index";
	phxAjaxCall(true,urlaff,'tpl='+tpl,d_get_tpl_callback,AJAX_error_handler);
}

function d_get_tpl_callback(response)
{
	var ctn = $('popup_content');
	ctn.update(response);
	p_init();
}

/************************************
 * Animation du popups des demos
 ************************************/
var p_size_rond = 40;
var p_duration_move = 1;
var p_duration_appear = 0.5;
var p_duration_morph = 0.8;
var p_duration_spring = 0.4;
var p_refresh_int="";
var p_height_morph = 8;
var p_width_morph = 8;
var p_max_width = 980;
var p_max_height = 750;

function p_get_max_height()
{
	var bg = $('fond_popup');
	var full_site = $('demo');
	var dim_ovp = document.viewport.getDimensions();
	var dim_site = full_site.getDimensions();
//	if(dim_ovp.height>=dim_site.height)
	return dim_ovp.height;
//	return dim_site.height;
}

function p_refresh_size()
{
	var bg = $('fond_popup');
	bg.style.height=p_get_max_height()+"px";
}

function p_start_refresh()
{
	p_refresh_size();
	p_refresh_int = setInterval('p_refresh_size()',100);
}

function p_stop_refresh()
{
	clearInterval(p_refresh_int);
}

function p_init()
{
	//Get Elements
	var ctn = $('popup_content');
	var bg = $('fond_popup');
	var popup = $('popup');
	var demo = $('demo_content');
	var fake = $('fake_popup');
	var p_close = $('close_popup');
	
	//Animation veritcal
	var max_h = p_get_max_height();
	popup.style.top=(max_h- p_size_rond-20)+"px";
	var p_morph_end = ((max_h- p_size_rond)/2);
	p_start_refresh();
	bg.style.display="";
	Behaviour.apply();

	//Get size popup
	var p_paddingb = parseInt(ctn.style.paddingBottom.replace("px",""));
	var p_width_end = parseInt(demo.style.width.replace("px",""));
	var p_height_end = parseInt(demo.style.height.replace("px","")) + (p_size_rond/2);

	if(p_width_end>p_max_width)
		p_width_end=p_max_width;

	if(p_height_end>p_max_height)
		p_height_end=p_max_height;

	var p_top_end = ((max_h - p_height_end - p_size_rond - p_paddingb)/2);

	//Animation
	new Effect.Move(popup, {x:0, y: p_morph_end, mode: 'absolute',duration: p_duration_move,afterFinish : function(){ 
		new Effect.Morph(popup, {style: 'height:' + p_height_morph + 'px; width: ' + p_width_morph + 'px', duration: p_duration_spring, transition: Effect.Transitions.spring,afterFinish : function(){ 
			new Effect.Morph(popup, {style: 'width: ' + p_width_end + 'px', duration: p_duration_morph, transition: Effect.Transitions.linear,afterFinish : function(){ 
				fake.style.height="auto";
				new Effect.Morph(popup, {style: 'height: ' + p_height_end + 'px;top:' + p_top_end + 'px', duration: p_duration_morph, transition: Effect.Transitions.linear,afterFinish : function(){ 
					new Effect.Appear(p_close,{duration:p_duration_appear,afterFinish:function(){
						d_already_clicked=false;
					}});
					}}); 
			}});
		}});
	}});
}

function p_close()
{
	var bg = $('fond_popup');
	var popup = $('popup');
	var fake = $('fake_popup');
	var p_close = $('close_popup');
	var max_h = p_get_max_height();
	var p_morph_end = ((max_h- p_size_rond)/2);
	
	var bg = $('fond_popup');
	new Effect.Fade(bg,{duration:s_duration,afterFinish : function(){
		var ctn = $('popup_content');
		ctn.update();
		bg.style.display="none";
		p_close.style.display="none";
		fake.style.height="0";
		popup.style.height="0";
		popup.style.width="0";
		geo_init=false;
	}});
/*
 
	
	new Effect.Parallel([
		new Effect.Morph(popup, { sync: true,style: 'height:0; width:0; top:'+ p_morph_end + 'px'}),
		new Effect.Move(popup, { sync: true,x:0, y: p_morph_end, mode: 'absolute'}),
		new Effect.Fade(bg, { sync: true}), 
	], { 
	  duration: p_duration_morph,
		afterFinish : function(){
		var ctn = $('popup_content');
		ctn.update();
		bg.style.display="none";
		p_close.style.display="none";
		fake.style.height="0";
	}});
	* */	  
}

/************************************
 * Animation des couleurs de fond;
 ************************************/
var bg_color = new Array("46D519","E06A20","097E87","CB0100");
var bg_duration=0.8;
var bg_interval=5000;
var bg_current=0;
var bg_init=false;

function bg_change_color(site)
{
	new Effect.Morph(site, {style: 'background-color:#' + bg_color[bg_current] + ";",duration: bg_duration});
	bg_current++;
	if(bg_current>=bg_color.length)
		bg_current=0;
}

/************************************
 * Animation de la page référence
 ************************************/

var r_current = 0;
var r_time= 800;
var r_interval="";
var r_slide_duration=0.8;
var r_bounce_duration=0.1;
var r_hauteur=20;
var r_zoom_x = 2;
var r_zoom_duration = 0.5;
var r_start_w = 47.5;
var r_start_h = 25;
var r_puce_add="";
var r_inited=false;

var r_size_img = new Array();
var r_pos_img = new Array();
var r_current_www="";

function r_init()
{
	var dim = $("puced_1").getDimensions();
	if(dim.width==0)
		r_puce_add = "c";
	else
		r_puce_add = "d";
	
	//Init size
	for(var i =1 ; i<=3 ; i++)
	{
		var tab = $$(".puce"+ r_puce_add + i);
		if(tab.length>0)
		{
			var dim = tab[0].getDimensions();
			r_size_img[i] = Array(dim.width,dim.height);
		}
	}
	
	//Init Top Left of each puce
	var tab = $$(".puce"+ r_puce_add);
	for(var i =0;i<tab.length;i++)
	{
		var pos = tab[i].positionedOffset();
		tab[i].style.left = pos[0] + "px";
		tab[i].style.top = pos[1] + "px";
		r_pos_img[tab[i].id] = pos;
	}
}

function r_stop_anim()
{
	clearInterval(r_interval);
}

function r_bounce(www,ind)
{

	var pos_start_x = r_pos_img[www.id][0];
	var pos_start_y = r_pos_img[www.id][1];
	var dest = (pos_start_y -(r_hauteur/ind));
	var time = r_bounce_duration/ind;

	new Effect.Move(www, {x: pos_start_x, y:dest, mode: 'absolute',
	  transition: Effect.Transitions.linear,
	  duration:r_bounce_duration,
	  queue:{position:"end",scope:(www.id)},
	  afterFinish:function(){
		new Effect.Move(www, {x:pos_start_x, y: pos_start_y, mode: 'absolute',duration:r_bounce_duration,transition:Effect.Transitions.linear,queue:{position:"end",scope:(www.id)},afterFinish:function(){
			if((r_hauteur/ind)>2)
				r_bounce(www,ind+1);
		}});
	  }
	});
}

function getSize(www)
{
	//Init de l'indice
	if(www.className.indexOf("puce"+ r_puce_add +"1")>-1)
	{
		var ind = 1;
	}
	else if(www.className.indexOf("puce"+ r_puce_add +"2")>-1)
	{
		var ind = 2;
	}
	else if(www.className.indexOf("puce"+ r_puce_add +"3")>-1)
	{
		var ind = 3;
	}
	return r_size_img[ind];
}

function r_zoom(www,sens)
{
	//Get size and dimension
	var t = getSize(www);
	var pos_start_y = r_pos_img[www.id][0];
	var pos_start_x = r_pos_img[www.id][1];
	r_start_w = t[0];
	r_start_h = t[1];
	var w = (r_start_w*sens);
	var h = (r_start_h*sens);
	
	if(sens==2)
	{
		var l = pos_start_y + ((r_start_w - w)/2);
		var t = pos_start_x + ((r_start_h - h)/2);
	}
	else
	{
		var l = pos_start_y;
		var t = pos_start_x;
	}
	
	var queue = Effect.Queues.get(www.id);
	queue.each(function(effect){effect.cancel();});
	//Set position
	new Effect.Parallel([
		  new Effect.Move(www, { sync: true, x:l, y: t, mode: 'absolute' }), 
		  new Effect.Morph(www, { sync: true,style: 'width:' + w + 'px;height:'+ h +'px'})
		], { 
		  duration: r_zoom_duration,
		  queue:{position:"end",scope:("zoom_" + www.id)},
		  afterFinish:function(){
			if(sens==1)
			{
				var queue = Effect.Queues.get("zoom_" + www.id);
				queue.each(function(effect) { effect.cancel(); });
			}
		  }
	});
}

function r_cat_in(puce_id,hover)
{
	if(r_current_www!=puce_id)
	{
		var www = $("puce"+r_puce_add+"_" + puce_id);
		var cat = $("lstpuce_" +puce_id);

		if(cat){
			if(cat.className.indexOf("puce_hover")==-1)
			{
				if(www && cat)
				{

					if(hover)
						r_zoom(www,2);
					else
						r_bounce(www,1);

					cat.className = cat.className + " puce_hover";

					if(!hover)
						r_current = puce_id;
				}
			}
		}
	}
}

function r_cat_out(puce_id,hover,forced)
{
	if(r_current_www!=puce_id || forced)
	{
		var www = $("puce"+r_puce_add+"_" + puce_id);
		var cat = $("lstpuce_" +puce_id);
		if(cat)
		{
			if(hover)
				r_zoom(www,(1));
			cat.className = cat.className.replace(" puce_hover","");
		}
	}
}

function r_cat_change()
{
	r_cat_out(r_current);
	var r_next = r_current+1;
	var tab_puce = $$('.puce' + r_puce_add);
	if(r_next>tab_puce.length)
		r_next = 1;
	r_cat_in(r_next);
}

function r_cat_click(puce_id,param)
{
	r_stop_anim();
	if(r_current_www!="")
		r_cat_out(r_current_www,true,true);
	else
		r_cat_out(r_current,true);
	r_current_www = puce_id;
	r_cat_in(puce_id);
	//Récuperation des demos
	var tpl = 'front/reference/article_reference_'+r_puce_add;
	var params = "&" + param + "=" + puce_id;
	var ctn = $('ctn_reference');
	new Effect.Fade(ctn,{duration:r_slide_duration,afterFinish:function(){
		phxAjaxCall(true,urlaff,'tpl=' + tpl + params,r_cat_click_callback,AJAX_error_handler);
	}});
}

function r_cat_click_callback(response)
{
	var ctn = $('ctn_reference');
	ctn.update(response);
	var imgs = $$('.ref_img');
	new Effect.SlideDown(ctn,{duration:r_slide_duration});

	//Draggable items
	imgs.each(function(item){
		new Draggable(item,{onEnd:function(ctn,item)
		{
			var e = ctn.element;
			var ctn = $(e.id.replace("ref_img_","site_"));
			var dim = ctn.getDimensions();
			var l = e.style.left.replace("px","");
			var t = e.style.top.replace("px","");
			if(l>(dim.width-20) ||l<((e.width-20)*-1) || t>(dim.height-20)|| t<((e.height-20)*-1))
			{
				e.style.left = "0";
				e.style.top = "0";
			}
		}
		});
	});

	//Execute animation for corporate
	if(r_puce_add=="c")
	{
		ref_init_fct();
		ref_stop();
		ref_start();
	}
}

/************************************
 * Changement des références dans le site corporate
 ***********************************/
var ref_init = false;
var ref_current=0;
var ref_current_img=0;
var ref_interval_time=5000;
var ref_interval="";
var ref_tab = new Array();
var ref_running = false;
function get_hide_indice(next_id,sens)
{
	var h = next_id+(2*sens);
	if(h<0)
		h = 5+h;
	return h;
}


function ref_stop()
{

	if(ref_running)
	{
		clearInterval(ref_interval);
		ref_running = false;
	}
}

function ref_start()
{
	var tab = $$('.src_ref');
	if(!ref_running && tab.length>=2)
	{
		ref_interval = setInterval(function(){ref_change()},ref_interval_time);
		ref_running = true;
	}
}

function ref_load(next_id)
{
	//Get indice to change
	var img_hide = $('ref_img_'+get_hide_indice(next_id,-1));
	if(img_hide)
	{
		
		//Get next indice
		var tab = $$('.src_ref');
		var next_img = ref_current_img+1;
		if(next_img>=tab.length)
			next_img=0;
		
		new Effect.Morph(img_hide, {style: 'width:0px;margin-left:0px;',afterFinish:function(){
			if(img_hide)
			{
				//Deplacement de l'image
				ref_setimg(img_hide,3);
				ref_moveimg(img_hide,"bottom");
				ref_current = next_id;
				ref_current_img = next_img;
			}
		}});
	
		ref_change_texte(next_img);
	}
}

var ref_text_duration = 0.5;
function ref_change_texte(indice)
{
	indice++;
	new Effect.Move($('ref_bloc_move'), {
	  x: 0, y:120, mode: 'relative',
	  duration:ref_text_duration,
	  afterFinish:function(){
	  	if($('src_texte_'+indice))
	  	{
		  	$('ref_texte').update($('src_texte_'+indice).innerHTML);
		  	$('ref_titre').href =  $('src_lien_'+indice).value;
		  	$('ref_titre').update($('src_titre_'+indice).value);
			new Effect.Move($('ref_bloc_move'), {
			  x: 0, y:-120, mode: 'relative',
			  duration:ref_text_duration
			});
	  	}
	}});
}

function ref_change()
{
	var tab = $$('.src_ref');
	var next = ref_current + 1;
	if(next>=5)
		next=0;
	ref_load(next);
}

function ref_moveimg(img,position)
{
	var child = $('ref_img_move').removeChild(img);
	child.style.width="560px";
	child.style.marginLeft="80px";
	if(position=="top")
		Element.insert( $('ref_img_move'),{'top':child});
	else
		Element.insert( $('ref_img_move'),{'bottom':child});
}

function ref_setimg(img,rel_ind)
{
	//Recuperation de l'indice de l'image suivante
	var next = ref_current_img + rel_ind;
	var tab = $$('.src_ref');
	if(next>=tab.length)
		next = next%tab.length;
	if(next<0)
		next = tab.length + next;
	//Recuperation de l'indice de la zone suivante
	img.src=$('src_img_' + (next+1)).value;
}

function ref_init_fct()
{
	//reste default value
	ref_current=0;
	ref_current_img=0;

	//Change the second and last image
	ref_setimg($('ref_img_1'),1);
	ref_setimg($('ref_img_2'),2);
	ref_setimg($('ref_img_3'),-2);
	ref_setimg($('ref_img_4'),-1);
}


/************************************
 * Animation du menu
 ***********************************/
var m_duration=0.6;
var m_rested = true;

function get_dest(menu_id)
{
	var md = $("menu_masque_d");
	var mg = $("menu_masque_g");
	var li = $("menu_" + menu_id);
	var menu = $("menu");
	var pos = li.positionedOffset();
	var dim = li.getDimensions();
	var dim_d = md.getDimensions();
	var m_w = dim_d.width;
	var left = pos[0];
	var width = (dim.width - m_w);
	return Array(left,width);
}

function m_select(menu_id)
{
	//Get left and width
	var m = $("menu_masque");
	var mg = $("menu_masque_g");
	var dest = get_dest(menu_id);

	//Set position
	m.style.left = dest[0] + "px";
	m.style.width = (dest[1] + 4) + "px";	
	mg.style.width = dest[1] + "px";
	m.style.display="";
	
}

function m_in(dest_id)
{
	m_rested = false;
	//Get left and width
	var m = $("menu_masque");
	var mg = $("menu_masque_g");
	var dest = get_dest(dest_id);
 	var t = parseInt(m.style.top.replace("px",""));
	//Set position
	var queue = Effect.Queues.get('menu_queue');
	queue.each(function(effect) { effect.cancel(); });
	if(BrowserDetect.browser=="Explorer")
	{
		m.style.left= dest[0] + "px";
		m.style.width = (dest[1] + 4) + "px";	
		mg.style.width= dest[1] + "px";	
		if(m_rested)
			m_out();
	}
	else
	{
		new Effect.Parallel([
			  new Effect.Move(m, { sync: true, x:dest[0], y:t, mode: 'absolute' }), 
			  new Effect.Morph(m, {style:"width:" + (dest[1]+4) +"px;",  sync: true}),
			  new Effect.Morph(mg, {style:"width:" + dest[1] +"px;",  sync: true}) 
			], { 
		  duration: m_duration,
		  queue:{ position: 'end', scope: 'menu_queue' },
		  transition: Effect.Transitions.spring,
		  afterFinish: function(){
			if(m_rested)
				m_out();
		  }
		});
	}
}

function m_out()
{
	//Annul les effet dans la queue
	var queue = Effect.Queues.get('menu_queue');
	queue.each(function(effect) { effect.cancel(); });

	//Selectionne le menu par défaut
	var tab = $$('.item_current');
	var tabid = tab[0].id.split("_");
	var menu_id = tabid[1];
	m_select(menu_id);
}

function record_pattern_CallBack(action, type, param)
{
	window.location.replace(param);
}

/************************************
 * Changement des formulaires de contact
 ***********************************/

var f_duration = 1;

function f_change(form)
{
	var tab = $$('.c_from');
	tab.each(function(item){
		if(item.style.display!="none")
		{
			new Effect.Fade(item,{duration:f_duration});
		}
	});
	new Effect.Appear($("form_" + form),{duration:f_duration});
}

var myrules = {
	"body" : function(b)
	{
		init_modele();
		b.onmousemove = function(e)
		{
			var nav = $('bubble_nav');
			var mouse_pos = getMousePosition(e);
			if(!nav)
			{
				var menu = $('menu');
				var m_pos = menu.cumulativeOffset();
				var m_dim = menu.getDimensions();
				if(mouse_pos[0]<m_pos[0] || mouse_pos[0]>(m_pos[0]+m_dim.width) || mouse_pos[1]>(m_pos[1]+m_dim.height))
				{
					if(!m_rested)
					{
						m_out();
						m_rested = true;
					}
				}
			}
			else
			{
				var nav_pos = nav.cumulativeOffset();
				var nav_dim = nav.getDimensions();
				if(mouse_pos[0]<nav_pos[0] || mouse_pos[0]>(nav_pos[0]+nav_dim.width) || mouse_pos[1]<nav_pos[1] || mouse_pos[1]>(nav_pos[1]+nav_dim.height))
				{
					if(!nav_rested)
					{
						nav_out();
						nav_rested = true;
					}
				}
			}
	
			//start stop cat corpo
			if($('ctn_reference') && $('ref_img'))
			{
				if(mouseIn(e,$('ctn_reference')))
					ref_stop();
				else
					ref_start();
			}
			
			
		}
	},
	'#animation_service': function(select)
	{
		var first = s_next_id();
		var btn_first = $(first);
		btn_first.className += " menu_service_current";
		s_appear(first);
		s_interval=setInterval('s_fade()',s_delay);
	},
	'.menu_service': function(btn)
	{
		btn.onclick = function()
		{
			if(btn.className.indexOf('menu_service_current')==-1 && s_active)
			{
				s_active = false;
				clearInterval(s_interval);
				s_fade(btn.id);
			}
		}
	},
	'.btn_demo' : function(btn)
	{
		btn.onclick = function()
		{
			if(!d_already_clicked)
			{
				d_already_clicked=true;
				var demo = btn.id.replace("demo_","");
				d_get_tpl(demo);
			}
		}		
	},
	".change_color" : function(bg)
	{
		if(!bg_init)
		{
			bg_init=true;
			bg_change_color(bg);
			setInterval(function(){bg_change_color(bg)},bg_interval);
		}
	},
	"#popup" : function(popup)
	{
		popup.onclick = function(event)
		{
			var event = event || window.event;
			//Stop propagation click
		   if(event.stopPropagation)
			{
				// this code is for Mozilla and Opera
				event.stopPropagation();
			}
			else if(window.event)
			{
				// this code is for IE
				window.event.cancelBubble = true;
			}
		}
	},
	'#close_popup' : function(btn)
	{
		btn.onclick = function()
		{
			p_close();
		}		
	},
	"#fond_popup" : function(popup)
	{
		popup.onclick = function(e)
		{
			if(!d_already_clicked)
				p_close();
		}
	},
	".cat_action" : function(puce)
	{
		if(!r_inited)
		{
			r_inited = true;
			r_init();
			r_cat_change();
			r_interval = setInterval('r_cat_change()',r_time);
		}
		puce.onmouseover = function(e)
		{
			var tabid = puce.id.split("_");
			r_cat_in(tabid[1],true);
		},
		puce.onmouseout = function(e)
		{
			var tabid = puce.id.split("_");
			r_cat_out(tabid[1],true);
		},
		puce.onclick = function(e)
		{
			var tabid = puce.id.split("_");
			r_cat_click(tabid[1],'cat');
		}
	},
	".rub_action" : function (puce)
	{
		puce.onclick = function(e)
		{
			var tabid = puce.id.split("_");
			r_cat_click(tabid[1],"rub");
		}
	},
	".item_current" : function(menu)
	{
		var tabid = menu.id.split("_");
		m_select(tabid[1]);
	},
	".menu_animation" : function(menu)
	{
		menu.onmouseover = function(e)
		{
			var tabid = menu.id.split("_");
			m_in(tabid[1]);
		}
	},
	".change_form":function(select)
	{
		select.onchange = function()
		{
			var tab = select.value.split("_");
			f_change(tab[1]);
		}
	},
	'.upload_file' : function(zone)
	{
		zone.onchange = function()
		{
			var field = "fake"+zone.id;
			$(field).value=zone.value.replace("C:\\fakepath\\","");
		}
	},
	'.change_cal' : function(select)
	{
		select.onchange = function()
		{
			if(select.value==2)
				new Effect.BlindDown($("selectdate_"+select.name));
			else
				new Effect.BlindUp($("selectdate_"+select.name));
		}
	},
	'.plus_texte' : function(plus)
	{
		plus.onclick = function()
		{
			var ctn = plus.id.replace("plus_","content_");
			var ajout = plus.id.replace("plus_","ajout_");
			if($(ctn) && $(ajout))
			{
				new Effect.Fade(plus,{afterFinish:function(){
					Element.insert($(ctn),{'bottom':$(ajout).innerHTML});
				}});
			}

//			new Effect.BlindDown($("selectdate_"+select.name));
		}
	},
	'.auto_ajout' : function(bloctexte)
	{
		var ctn = bloctexte.id.replace("ajout_","content_");
		if($(ctn))
		{
			Element.insert($(ctn),{'bottom':bloctexte.innerHTML});
		}
	}
};

// *******************************************
//
// REGLES COMPORTEMENT ENREGISTREMENT
//
// *******************************************

Behaviour.register(myrules);
