// JavaScript Document
window.addEvent('domready', init);

function init(){
	
	//menu = new DropMenu('menu',{ mode:'vertical' });
	
	/*
		Radius settings:
			radius
			topleft
			topright
			bottomleft
			bottomright
	*/
	//GoodCorners.round( $$('.round'), {radius: "15px",bottomright:'',topright:''});

	GoodCorners.round( $$('#home a, #li_145'), {radius: "5px",bottomright:'',topright:''});
	GoodCorners.round( $$('#a_1268,#li_1268'), {radius: "5px",bottomleft:'',topleft:''});
	
	SqueezeBox.assign($$('.boxed'), { parse: 'rel' });
	
	 var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
//	 infos = infos.substring(0,infos.indexOf("#"))+"&"
//	 console.log('infos=-'+infos+'-')
	
	//empecher que le script ne se charge pr la page d'accueil
	var currentLocation =  document.location.href;
	if( currentLocation!='http://www.sources-lac-annecy.com/accueil/861-1327,accueil.html#diaporama' && infos!='ajaxPopup&'){
		//console.log(location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&");
		new vlaDatePicker('exampleIV-B', { style: 'apple_widget', offset: { x: 3, y: 1 }, filePath:jsPath+'inc/' });
		
		$$('.vlaCalendarPicker apple_widget').setStyle({ 
		  display: 'block',
		  opacity: '100',
		  visibility: 'visible'
		});
	
	
	
	// FORMULAIRE HEBERGEMENT TRAITEMENT
	  // menu par defaut a afficher
            var aff=1394;
            $('type_recherche').set('value',1394);

            // fonction affichant un block
            function affiche_block_recherche(element){
                //alert('fct'+element);
				var a_cacher = $$('.block_select')[0];
                // on cache l element afficher
                if(a_cacher){ 
					//alert(a_cacher);
					a_cacher.removeClass('block_select');
                }
				 // on affiche celui selectionne
                element.addClass('block_select');
            }


            // on test si le formulaire existe
            if($('form_recherche')){
                var i=0;
				// on selectionne tous les block (voir doc mootools pour les differentes fonctions)
                $$('.block_recherche').each(function(element){
                    // on recupere l'id'
                    var id=element.get('myId');
					element.set('id', 'block_recherche_'+id);
					// ici on test le block a afficher par defaut
                    if(id.toString()==aff.toString() && i==0){
						affiche_block_recherche(element);
						i++;
                    }
                    //element.set('id', 'block_recherche_'+id);
                });

                // on met l'ecouteur sur type_recherche
                $('type_recherche').addEvent('change',function(){
                    var idBlock = $('type_recherche').get('value');
                    affiche_block_recherche($('block_recherche_'+idBlock));
                });

            }

            // on valide l action de la recherche sur le bouton
            $('form_recherche').addEvent('submit',function(e){
                // on stop la validation du formulaire
                new Event(e).stop();
                // on supprime les formulaires inutiles
                var idBlock = $('type_recherche').get('value');
                $$('.block_recherche').each(function(element){
                    if(idBlock!=element.get('myId')){
                        element.destroy();
                    }
                });
                // on envoie la page
                $('form_recherche').submit();
            })
			
			
			}
	
}

/// TRAITEMENT AFFICHAGE COMMUNES
			
			function type_h (type,lang){
				//alert('stop_type_h');
				Open ('lieu_hebergement', '../choix_villes_accueil.php', 'type_hebergement='+type+'&lang='+lang);
			}
			
			function type_l (type,lang){
				//alert('stop_type_l');
				Open ('lieu_loisir', '../../../choix_loisir.php', 'type_loisir='+type+'&lang='+lang);
			}
