Event.observe(window,"load",function() {		
		$$("#listeAvantages img").findAll(function(node){
			return node.getAttribute('alt');
		}).each(function(node){
			   //new Tooltip(node,node.alt);
				
                //element, tool_tip, widthww,deltax, deltay
                var tooltip =  new Tooltip(node,node.alt,0,0,0);
				//tooltip.options.default_css = true;
               $(tooltip.tool_tip).setStyle({display:'block'});
              var width = $(tooltip.tool_tip).firstChild.getDimensions().width + 45;
              $(tooltip.tool_tip).setStyle({display:'none'});
              $(tooltip.tool_tip).setStyle({
  width:  width+'px'});

                node.removeAttribute("alt");
	 });
     
        $$("input[type=text]").each(function(elmt,i){
           elmt.observe("focus", function(event){
                resetInput(elmt);
           });           
       });
     
			initGallery();
			initLastHotels();
            doChangeTooltipDOM();
            initExternal();
});     

function doChangeTooltipDOM(){
    $$(".tooltip").each(function(node){
       var element = node.firstChild;
        var parentNode =   node.parentNode;     
         // parentNode.className = "tooltip_box";
         var title = element.innerHTML;
        var div_bg = $(document.createElement("div")); 
        div_bg.addClassName("bg");
            node.appendChild(div_bg);
        
        var div_bloc = $(document.createElement("div")); 
        div_bloc.addClassName("bloc");
        node.appendChild(div_bloc);
        div_bloc.innerHTML = title;
  
      element.style.display = "none"; /* IE */
    
   });
   
 
}

     

     function initExternal(){
     	var regex = new RegExp("etaphotel.com");
		if(!regex.test(window.document.URL))
			$$('body')[0].className = $$('body')[0].className + ' external';
     }


    
	function initGallery(){
		var thumbs = $$("#thumb li");
		thumbs.each(function(elm,index){
			elm.observe('click', function(event){
				var images = $$("#photoHotel img");
				images.each(function(image,indexImg){
					image.style.display = "none";
					thumbs[indexImg].removeClassName("active");
				});
				images[index].style.display = "block";
				this.addClassName('active');		
			});
		});
	}
	
	
	function EcrireCookie(nom, valeur) {
		var argv=EcrireCookie.arguments;
		var argc=EcrireCookie.arguments.length;
		var expires=(argc > 2) ? argv[2] : null;
		var path= "/";
       // var path=(argc > 3) ? argv[3] : null;
                
		var domain=(argc > 4) ? argv[4] : null;
		var secure=(argc > 5) ? argv[5] : false;
		document.cookie=nom+"="+escape(valeur)+ ((expires==null) ? "" : ("; expires="+expires.toGMTString()))+ ((path==null) ? "" : ("; path="+path))+ ((domain==null) ? "" : ("; domain="+domain))+ ((secure==true) ? "; secure" : "");
	}
		
        
	function getCookieVal(offset) {
		var endstr=document.cookie.indexOf (";", offset);
		if (endstr==-1) endstr=document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
	
    
	function LireCookie(nom) {
		var arg=nom+"=";
		var alen=arg.length;
		var clen=document.cookie.length;
		var i=0;
		while (i<clen) {
			var j=i+alen;
			if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
			i=document.cookie.indexOf(" ",i)+1;
			if (i==0) break;
		}
		return false;
	}


function resetInput(obj) {
	if(obj.value != "" && obj.id != "dateArrival" && obj.id != "tripDateArrival" ) {
		var myValue = obj.value;
		obj.value = "";
	}
	if(myValue) {
	/*	obj.observe("blur", function(event){
			obj.value = myValue;
		});
        */
	}
}




function initLastHotels(){
    /* nb fiche hotel */
    var document_url = document.URL;

				var last_hostels = LireCookie("lastHostels");
         
			var title = $$(".titre h1");
			title = title[0].innerHTML;
			var document_url = document.URL;
			var liste = $("lastSearchHotels_list");

			if(last_hostels != false) { 
        last_hostels = last_hostels.unfilterJSON();
				last_hostels = last_hostels.evalJSON();
				last_hostels = last_hostels.list;
                var found = false;
               
                last_hostels.each(function(item,i) {
                 
                  var reg_nb = new RegExp("[0-9]{4}", "g");
       
                    var get_nb_fichehotel = document_url.match(reg_nb);
                
                    var reg_nb2 = new RegExp("[0-9]{4}", "g");
    
   
                   var lien = item.href;
                 
                   var  nb_fichehotel_cookie = lien.match(reg_nb2)


					if((lien == document_url) || (parseInt(get_nb_fichehotel) == parseInt(nb_fichehotel_cookie))) found = true;
				});
                
                    if(last_hostels.length >= 1) $("lastSearchHotels").style.display = "block";
                    var cookie_value = "{'list':[";
                    if(last_hostels.length >= 5) last_hostels.pop();
                    
                    // nouvel hotel
                    if(found == false){
                        var li_node =  $(document.createElement("li")); 
                        li_node.insert("<a href="+document_url+">"+title+"</a>");
                        liste.appendChild(li_node);	
                        
                        cookie_value += "{'href':'"+document_url+"','title':'"+title+"'},";	
                        
                        //rajoute  dans le cookie
                        EcrireCookie("lastHostels",cookie_value);
                      
                    }

                    /* hotels existants */
                    last_hostels.each(function(item,i) {
                        var li_node =  $(document.createElement("li")); 
                        li_node.insert("<a href="+item.href+">"+item.title+"</a>");
                        liste.appendChild(li_node);	

                        if(i < (last_hostels.length - 1)) {                  
                            cookie_value += "{'href':'"+item.href+"','title':'"+item.title+"'},";
                         }
                        else {
                            cookie_value += "{'href':'"+item.href+"','title':'"+item.title+"'}";
                          }
                      
                    });
                      cookie_value += "]}";  
                        
                        if(found == false){
    
                        //rajoute  dans le cookie
                        EcrireCookie("lastHostels",cookie_value);
                      
                    }                        
			}
			else{
     
				var li_node =  $(document.createElement("li")); 
				li_node.insert("<a href="+document_url+">"+title+"</a>");
				liste.appendChild(li_node);	
				EcrireCookie("lastHostels","{'list':[{'href':'"+document_url+"','title':'"+title+"'}]}");
				$("lastSearchHotels").style.display = "block";
			}
          
		}
		