
/*  =================================================================
/*  =Liens
/*  ================================================================*/

document.observe("dom:loaded", function()
{
    $(document.body).observe('contextmenu', Event.stop); //no right click
    
    /* retour en haut de page */
	if ($('back_to_top')) {
		$('back_to_top').observe("click",function(evt){
			Event.stop(evt);
			new Effect.ScrollTo( $('top'));			
		});
	}
	
	/* masque element */
	$$('.hideOnLoad').each(function(s)
	{               
		s.hide();                           
		s.removeClassName('hideOnLoad');
	});
	
	/* affichage aide slideflow, mentions legales */
	$$('.showHide').each(function(s)
		{ 
			s.observe("mouseover",function(evt){
					Effect.Appear(s.up().next('.more'), { duration:0.4 });
			});
			s.observe("mouseout",function(evt){
					Effect.Fade(s.up().next('.more'), { duration:0.4 });
			});
		
		});
	
	/* popup print */
	$$('.blank').each(function(lien)
	{
		lien.observe('click',function(evt)
		{
			window.open(lien.href,"Print", 'scrollbars=yes,toolbar=yes,location=no,directories=no,menubar=yes,resizable=no,status=yes,width=695,height=480,screenX=0,screenY=0,top=20,left=20');
			evt.stop();
		});
	});
	
	// scroll recrutement
	if ($('scrollRecrut')) {
		$('scrollRecrut').observe("click",function(evt){
			Event.stop(evt);
			new Effect.ScrollTo( $('form_cand') );		
		});
	}

	// affiche-masque filtre par localisations
	if ($('show_list')) {
		$('show_list').observe("click",function(evt){
			if (this.hasClassName('to_open')) {
				Event.stop(evt);
				Effect.Appear(this.up().next('.liste'), { duration:0.4 });						
				new Effect.Highlight(this, {
							startcolor: "#000000",
							endcolor: "#2b2929",
							restorecolor: "#2b2929",
							duration: 0.4
				})
				this.addClassName('to_close');	
				this.removeClassName('to_open');
			}
			
			else if (this.hasClassName('to_close')) {
				Event.stop(evt);
				Effect.Fade(this.up().next('.liste'), { duration:0.4 });						
				new Effect.Highlight(this, {
                        startcolor: "#2b2929",
                        endcolor: "#000000",
                        restorecolor: "#000000",
                        duration: 0.4
             	})
				$('show_list').removeClassName('to_close');
				$('show_list').addClassName('to_open');
			}
		});
	}
	
});

// -----------------------------------------------------------------------------------
//
//	Anatips v0.1
//	by Christophe Gimenez - http://www.anaema.com
//	Last Modification: 10/2/2008
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//      - Free for use in both personal and commercial projects
//      - Attribution requires leaving author name, author link, and the license info intact.
//	
// -----------------------------------------------------------------------------------

if(!ANAEMA) var ANAEMA = {};

ANAEMA.Anatips = Class.create({
	objTip:   undefined,
	tipsArray:  [],

	// Constructor runs on completion of the DOM loading. 
	initialize: function() {	
		this.tipsArray = [];		
		objBody = $$('body')[0];
		this.objTip = objBody.appendChild(Builder.node('div',{id:'anatips_tip'}));
		this.setupTooltips();		
	},	
	
	// Scans the DOM to find all elements with an 'anatips' class attribute and bind them to the 3 events handlers
	setupTooltips: function() {
		me = this;
		cnt = 0;
		$$('.anatips').each(function(el){				
			if(el.title && el.title.length > 0) {				
				el.observe('mouseover', (function(event) { event.stop; me.handleMouseOver(event) }).bind(this));
				el.observe('mousemove', (function(event) { event.stop; me.handleMouseMove(event) }).bind(this));
				el.observe('mouseout',  (function(event) { event.stop; me.handleMouseOut(event) }).bind(this));
				me.tipsArray[cnt] = el.title;
				el.tip_num = cnt++;
				el.removeAttribute('title');
			}
		})		
	},		
	
	// Called when mouse enters the target : setup and show container
	handleMouseOver: function(event){
		target = event.findElement('.anatips');
		if (target) {
			this.objTip.innerHTML = this.tipsArray[target.tip_num];
			this.objTip.style.visibility = "visible";
			image = event.findElement('.anatips img'); // Disable inner images's alt attribute (prevents IE auto alt tooltips)
			if(image) image.alt = '';
		}
	},
	
	// Called when mouse moves over the target : move the tip container
	handleMouseMove: function(event){
		target = event.findElement('.anatips');
		if (target) {
			this.objTip.style.left = (event.pointerX() + 20) + 'px';
			this.objTip.style.top = (event.pointerY() + 20) + 'px';
		}
	},
	
	// Called when mouse leaves the target : hide the tip container
	handleMouseOut: function(event){
		this.objTip.style.visibility = "hidden";
	}
	
});

document.observe('dom:loaded', function () { ANAEMA.tips = new ANAEMA.Anatips(); });

// -----------------------------------------------------------------------------------
// menu deroulant cases à cocher, nb pièces

var defaultfocuscp="";
var defaultfocusinput = "";
var opennodes = new Array();

function getParentWithClass(el,pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.className == pTagName)
		return el;
	else
		return getParentWithClass(el.parentNode, pTagName);
}
var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);

if(typeof HTMLElement!="undefined" && !isIE){
		HTMLElement.prototype.__defineGetter__("innerText", function () {
		   var r = this.ownerDocument.createRange();
		   r.selectNodeContents(this);
		   return r.toString();
		});
		
}

function BuildSummary(o) {
	var txt = '';
	var etplus = '';
	var o = document.getElementById(o);

if (o) {
		allInput = o.getElementsByTagName("input");
		for (i=0; i<allInput.length;i++) {
			if (allInput[i].checked) {
				if (i==6) { etplus = ' et +'; }
				txt=txt+allInput[i].innerText+i+etplus+', ';
			}
		}
	}
	
	o = o.getAttribute("name")
	if (o) {
	o=document.getElementById(o+"Text");
	//if (txt.length>0) {
	
		if (o!=null) {
			txt=String(txt).substring(0,txt.length-2);
			
			if (o.tagName=="INPUT") 
				o.value=txt;
			else
				o.innerHTML=txt;
		}		
	}		
	//}
}

 function initDropdown() {
		var navRoot = document.getElementById("miniSearch");
		var allInput = navRoot.getElementsByTagName("input");
			for (i=0; i<allInput.length;i++) {
				node = allInput[i];
				
				if (node.getAttribute("type")=="checkbox") {
					node.onchange=function() {
						setTimeout('BuildSummary("'+getParentWithClass(this,"searchchoix").id+'")',10);
					}
					node.onclick=function() {
						setTimeout('BuildSummary("'+getParentWithClass(this,"searchchoix").id+'")',10);
					}

				}
			}
			var subnodes = navRoot.getElementsByTagName("DIV");
			for (i=0; i<subnodes.length; i++) {
				node = subnodes[i];
				if (node.nodeName=="DIV" && node.className=="searchchoix") {
						setTimeout('BuildSummary("'+node.id+'")',10);
						node.onmouseover=function() {
								o = document.getElementById(this.getAttribute("name")+"Liste");
								if (o) o.className+=" over";
								ClearOpenNodes();
								opennodes.push(o);
				  	}
	  				node.onmouseout=function() {
	  					o = document.getElementById(this.getAttribute("name")+"Liste");
						  ClearOpenNodes();
						  
	   				}
   			}
   			else if (node.nodeName=="DIV" && node.className=="dropdown") {
   				node.onmouseout=function() {ClearOpenNodes();}
   			}
  }
}

function ClearOpenNodes() {
	
	for (var i=0; i<opennodes.length;i++) {
		var o =opennodes[i];
		if(o)
			o.className=o.className.replace(" over", "");
	}
	opennodes=new Array();
}
