
var action_print=0;
$(document).ready(function(){
	
	
	jQuery("#print_page").click(function(){
	    window.print();
	    return false;
	});
	
	jQuery("#aside .reservation").text('');
	
	//galerie photo
	
	var actuelHtml = jQuery("#photoMax").html();
	
	jQuery("#photosMin a").mouseover(function(){		
		jQuery("#photoMax img").replaceWith(jQuery(this).find('span').html());
	}).mouseout(function(){
		jQuery("#photoMax img").replaceWith(actuelHtml);
	
	});

	jQuery("#photosMin a").click(function(){
		jQuery("#photoMax img").replaceWith(jQuery(this).find('span').html());
		actuelHtml = jQuery("#photoMax").html();
		return false;
	});
	
	
	if(jQuery('div#photoJs').length){
		jQuery('div#photoJs').attr('class','photoJs');
	}
	
	if(jQuery('div.tx-irfaq-pi1').length){
		jQuery('.faq-reponse').hide();
	}
	
	//zoom du texte
	var count = 5;
	jQuery("#text-zoom").click(function(){
	  	 if(count>=10) return false; 
	  jQuery('#contenuTexte p,#contenuTexte li,#blocGauche p.texte,#contenuTexte label,#contenuTexte h3, #contenuTexte h4').removeClass('taille'+count);
	  count++;      
      jQuery('#contenuTexte p,#contenuTexte li,#blocGauche p.texte,#contenuTexte label,#contenuTexte h3, #contenuTexte h4').addClass('taille'+count);      
	 
	  if(jQuery("#text-dezoom").is(':hidden')) jQuery("#text-dezoom").show();
	  return false;
	});
	
	//dezoom du texte
	jQuery("#text-dezoom").click(function(){
	   if(count<=0) return false;
      jQuery('#contenuTexte p,#contenuTexte li,#blocGauche p.texte,#contenuTexte label,#contenuTexte h3, #contenuTexte h4').removeClass('taille'+count);
	   count--;
      jQuery('#contenuTexte p,#contenuTexte li,#blocGauche p.texte,#contenuTexte label,#contenuTexte h3, #contenuTexte h4').addClass('taille'+count); 	
	 if(jQuery("#text-zoom").is(':hidden')) jQuery("#text-zoom").show();
	   return false;
	});
	
	//fil d arianne désactivé le lien sur le 2ie élément
	if(jQuery('#blocAriane .second').length){
		var text = jQuery('#blocAriane span.second a').text();
		jQuery('#blocAriane span.second a').remove();
		jQuery('#blocAriane span.second').text(text);		
	}
	
	//lien zoom sur sur toute l image
	if(jQuery('.zoom_sur_accueil').length){
		var href = jQuery('.plus a').attr('href');
		var title = jQuery('.plus a').attr('title');
		//var img = jQuery('.zoom_sur_accueil h1').html();
		jQuery('.zoom_sur_accueil h1 img').wrap('<a href="'+href+'" title="'+title+'"></a>');
		jQuery('.zoom_sur_accueil img.imgLeft').wrap('<a href="'+href+'" title="'+title+'"></a>');
	}
	
	//rollover fce reservation
	jQuery(".lienNav a").hover(
      function () {
        var parent = jQuery(this).parent();
		parent.find('a').addClass('hover');
      }, 
      function () {
        var parent = jQuery(this).parent();
		parent.find('a').removeClass('hover');
      }
    );

	//menu last derniere element fond bleu	
	 
	 jQuery('#menu ul li').hover(
		 function () {			
			jQuery(this).find('ul').removeAttr('style');
			jQuery(this).find('ul li').removeAttr('style');
		}, 
      function () {						
			jQuery(this).find('ul').css( 'background','transparent');
			jQuery(this).find('ul li').css( 'background','none');
      }
	 );
	 
	 if(jQuery('#menu #lastmenu').length){ 	
			jQuery('#menu').css('background','transparent url(fileadmin/template_site/img/fond_menu_actif_last.png) repeat-x scroll 0 0' );
	}
	
	jQuery('#menu ul li.last').hover(
		 function () {
			jQuery('#menu').css( 'background','transparent url(fileadmin/template_site/img/fond_menu_actif_last.png) repeat-x scroll 0 0' );
		}, 
      function () {
			if(!jQuery('#menu #lastmenu').length)
       		jQuery('#menu').removeAttr('style');
      }
	 );
	 
	 //impression
	// alert(action_print);
	 if(action_print==1){window.print();history.back();}
	 
	 //annuaire etablissement
	function hideCriteres() {
		jQuery('.select select').html(listOpt)
      var n = jQuery("input:checked").attr('value');
		
	  jQuery('#theme option').each(function () {	
			if(jQuery(this).attr('class')!=n && jQuery(this).attr('class')!=''){
				jQuery(this).remove();
			}			
        });     
    }	
	function hideCritereLocalisation(){
	
		if(jQuery("#restaurant, #hebergement , #loisirs").is(':checked'))	{
			jQuery("#select_localisation_annuaire").show();
		}
		else {
			jQuery("#select_localisation_annuaire").hide();
		}
	}
	if(jQuery('#menu #lastmenu').length){	
		 var listOpt= jQuery('.select select').html();
		 hideCriteres();
		 hideCritereLocalisation();		 
		 
		 jQuery("#blocAnnuaire .radio input").click(hideCriteres);
		 jQuery("#blocAnnuaire .radio input").click(hideCritereLocalisation);
	}
	
	//pagination annuaire
	if(jQuery('.paginationJS .lien_page a').length){
		jQuery('.paginationJS').show();
		var pageAnActif=1;
		var oldAnPage=0;
		showPageAnnuaire(1);		
		var totalAnPage=jQuery('.paginationJS .lien_page a').length;
		jQuery('.paginationJS .lien_page a').click(function () {		
			//suppression des crochet du text
			jQuery('.paginationJS .l'+oldAnPage+' a').text(oldAnPage);
			//affiche les 10 bloc de la page choisie
			
			showPageAnnuaire(jQuery(this).text());
			 return false;
		});
		
		jQuery('.paginationJS .prev a').click(function () {				
			jQuery('.paginationJS .l'+oldAnPage+' a').text(oldAnPage);
			
			showPageAnnuaire(pageAnActif-1);
			 return false;
		});
		
		jQuery('.paginationJS .next a').click(function () {				
			jQuery('.paginationJS .l'+oldAnPage+' a').text(oldAnPage);
			
			showPageAnnuaire(parseInt(pageAnActif)+1);
			 return false;
		});
		
	}
	function showPageAnnuaire(nPage){	
		pageAnActif=nPage;
		oldAnPage=nPage;
		if(pageAnActif<=totalAnPage) jQuery('.paginationJS .prev').show();
		if(pageAnActif<=1) jQuery('.paginationJS .prev').hide();		
		if(pageAnActif>=1) jQuery('.paginationJS .next').show();	
		if(pageAnActif>=totalAnPage) jQuery('.paginationJS .next').hide();		
		
		jQuery('.bloc').hide();
		jQuery('.bloc_hr').hide();	
		
		jQuery('.paginationJS .l'+nPage+' a').text('['+nPage+']');
		
		var fin=nPage*10;
		var deb=fin-10+1;
		for(var i=deb;i<=fin;i++){
			jQuery('.r'+i).show();
		}
	}
	
    //########PLAN INTERACTIF##########//
	//menu
	jQuery('#menuPlan ul li ul').hide();
	jQuery('#menuPlan ul li a.on').parent().find('ul').show();
	jQuery('#menuPlan ul li a.lvl1').click(function(){
		jQuery('#menuPlan ul li ul').hide('normal');
		jQuery(this).parent().find('ul').show('normal');
	   return false;
	});

	//supression des targets
	 jQuery('a').each(function () {	
			if(jQuery(this).attr('target')){
				jQuery(this).removeAttr('target');
				jQuery(this).attr('onclick','window.open(this.href); return false;');				
			}			
        });    
	
});

function faqToggle(id_rep,id_quest) {    
	if (jQuery('#'+id_rep).is(':hidden')) {
	   jQuery('#'+id_rep).show('normal'); 	 	 
	 } else {
	    jQuery('#'+id_rep).hide('normal');	 
	 }
}

/*GOOGLE MAP*/


var map = null;
    var geocoder = null;

    function initializeMap(id,co1,co2,ctr) {
	//alert('init');
      
        map = new GMap2(document.getElementById(id));
        map.setCenter(new GLatLng(co1, co2), ctr);
       // map.addControl(new GLargeMapControl()); // outils à gauche
	//map.enableScrollWheelZoom();		
        geocoder = new GClientGeocoder();
      
	//  alert(adresseVillage);
   if(document.getElementById(id)) {  showAddress(adresseMagasin,infoAdresse);}
    }

    function showAddress(address,info) {
	//	alert('show adresse');
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
           
            //  map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
			  
			   var coordonnee=point.toString();
			  coordonnee=coordonnee.replace('(','');
			  coordonnee=coordonnee.replace(')','');
			  coordonnee=coordonnee.replace(' ','');
			  var geocode=address;
			  geocode=geocode.replace(' ','+');
			  var lien='<a href="http://maps.google.fr/maps?&ie=UTF8&ll='+coordonnee+'&z=13&geocode=&q='+geocode+'" onclick="window.open(this.href); return false;" class="zoom_googlemap"><img src="/fileadmin/template_site/img/zoom.gif" alt="Zoom"/>&nbsp;&nbsp;Agrandir la carte</a>';
			  jQuery('#map_plan_lien_zoom').html(lien);
			  
			  if(info!='')
              marker.openInfoWindowHtml(info);
				
          }
        );
      }
    }

	
	//########PLAN INTERACTIF##########//
	//map
	var init = function ()
	{
		google.load("maps", "2");
		google.setOnLoadCallback(initMap);
	}; // init
	
	var initMap = function ()
	{				
	
	var zoom_map=parseInt(zoom);
		var map = new google.maps.Map2(document.getElementById('map'));
		map.setCenter(new GLatLng(48.804432696739134, 2.1398448944091797), zoom_map);
		map.addControl(new GLargeMapControl());
		
	
			// Ajout d'un marqueur pour chacune des stations de metro de Lyon
		for (var i=0 ; i<=markerMap.length ; i++)
		{
			
			map.addOverlay(createMarker(markerMap[i]));
		}
		
	}; // initMap
	
	var createMarker = function(infoPoint)
	{	
	   var point = new GLatLng(infoPoint.lat,infoPoint.lng);   
			  
		var myIcon = MapIconMaker.createMarkerIcon({width: 36, height: 32, primaryColor: color});
		myIcon.shadow ='';
		var markerOptions = {
			icon: myIcon
		};
	 
		var marker = new GMarker(point, markerOptions);
		
		var window = function() {
			marker.openInfoWindowHtml(infoPoint.info);
		};
 
		GEvent.addListener(marker, "mouseover", window);

		
		
		return marker;
	}; // createMarker