// JavaScript Document
function $(el){
	return document.getElementById(el);
}

var taillefont=68.75;

function gestionFont(action){
	switch (action) { 
	case 'plus':
		if (taillefont<=130) taillefont+=20;
		break;
	case 'default': 
		taillefont=68.75;
		break;
	case 'moins': 
		if (taillefont>=50) taillefont-=10;
		break;
	} 
	
	var body2=document.getElementsByTagName("body");
	body2[0].style.fontSize= taillefont+"%";
}
function imprimer(){
	window.print();
}

//
// Interactives functions
//

function mycarousel_initCallback(carousel){
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
 
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
 
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}

function billboardheader_initCallback2(jc, state) { 
  if (state == 'init') {
    jc.startAutoOrig = jc.startAuto; 
    jc.startAuto = function() { 
      if (!jc.paused) { 
        jc.startAutoOrig(); 
      } 
    } 
    jc.pause = function() { 
      jc.paused = true; 
      jc.stopAuto(); 
    }; 
    jc.play = function() { 
      jc.paused = false; 
      jc.startAuto(); 
    }; 
    $('#billboard-header-control a').bind('click', function() {
        jc.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        jc.pause();
    });
  }
  jc.play();
}

function billboardheader_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
	$('#billboard-header-control a').removeClass("active");
	$('#billboard-header-control a:eq('+(idx-1)+')').addClass("active");
};

function initMobile(){
	//alert(navigator.userAgent);
	if(document.getElementById("annonce_site_mobile")){
		$('#annonce_site_mobile').append('Pour une meilleure navigation, rendez-vous sur<br /><a href="http://m.lyon-france.com">m.lyon-france.com</a>');
		$('#annonce_site_mobile').show();
	}else{
		//window.location = "http://m.lyon-france.com";
	}
}

function initPub(){
	if($("#top-pub-toggle-btn").hasClass('activated')){
		$("#top-pub-toggle-btn").hide();
		$("#top-pub").show();
		$("#top-pub").delay(5000).slideToggle("slow");
		$("#top-pub-toggle-btn").delay(5000).slideDown();
	}else{
		$("#top-pub").hide();
	}
	$("#top-pub-toggle-btn").click(function(){
		$("#top-pub").slideToggle("slow");
	});
}

function initCufon(){
	Cufon.replace('#packages h2', {
		textTransform: 'uppercase',
		fontSize: '36px',
		color: '#FFFFFF'
	});
	Cufon.replace('#packages .subtitle', {
		textTransform: 'uppercase',
		fontSize: '26px',
		color: '#a6a8a9'
	});
	Cufon.replace('#packages .two-col .package-title', {
		textTransform: 'uppercase',
		fontSize: '20px',
		color: '#FFFFFF'
	});
	Cufon.replace('#packages .three-col .package-title', {
		textTransform: 'uppercase',
		fontSize: '16px',
		color: '#FFFFFF'
	});

	Cufon.replace('#paiement h2', {
		textTransform: 'uppercase',
		fontSize: '36px',
		color: '#FFFFFF'
	});
	Cufon.replace('#paiement h3', {
		textTransform: 'uppercase',
		fontSize: '26px',
		color: '#a6a8a9'
	});
}

function initTopMenu(){
	$('#main-menu2 li.headlink').hover(
			function() {
				$('ul', this).css('display', 'block');
				$(this).find("a:first").addClass("hover");
			},
			function() {
				$('ul', this).css('display', 'none');
				$(this).find("a:first").removeClass("hover");
			}
		);
}

function initCarousel(){
    jQuery('#mycarousel').jcarousel({
        vertical: true,
        scroll: 1,
        auto: 5,
        wrap: 'last',
        initCallback: mycarousel_initCallback,
        animation: 1000
    });
    jQuery('#partenaires_carousel').jcarousel({
        scroll: 1,
        auto: 4,
        wrap: 'last',
        animation: 1000
    });
}

function codeAddress() {
    var address = $('#map-address').html();
    var address = address.replace("\n",", ");
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map, 
            position: results[0].geometry.location
        });
      } else {
        alert("Cette adresse n'a pas été trouvée par Google Maps");
      }
    });
  }

function initGoogleMap(){
	  var geocoder;
	  var map;
	  function initialize() {
	    geocoder = new google.maps.Geocoder();
	    var latlng = new google.maps.LatLng(45.757029,4.832976);
	    var myOptions = {
	      zoom: 14,
	      center: latlng,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    }
	    map = new google.maps.Map(document.getElementById("map"), myOptions);
	  }
	  function codeAddress() {
		  	//alert("codeAddress");
		    var address = $('#map-address').html();
		    var address = address.replace("\n",", ");
		    geocoder.geocode( { 'address': address}, function(results, status) {
		      if (status == google.maps.GeocoderStatus.OK) {
		        map.setCenter(results[0].geometry.location);
		        var marker = new google.maps.Marker({
		            map: map, 
		            position: results[0].geometry.location
		        });
		      } else {
		        alert("Cette adresse n'a pas Ã©tÃ© trouvÃ©e par Google Maps");
		      }
		    });
		  }

		//Default Action
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("ongletSelect").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content

		//On Click Event
		$("ul.tabs li.tab_click").click(
	        function(){
	            $("ul.tabs li").removeClass("ongletSelect"); //Remove any "active" class
	            $(this).addClass("ongletSelect"); //Add "active" class to selected tab
	            $(".tab_content").hide(); //Hide all tab content
	            var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
	            $(activeTab).fadeIn(); //Fade in the active content
	            if( $('#tab-map').is(':visible') ) {
	                initialize();
	                //alert("ok");
	                if($('#map-address').html()){
	                        codeAddress();
	                }else{
	                    lat = $('#map-lat').html();
	                    lng = $('#map-lng').html();
	                    //alert(lat + ", " + lng);
	                    point = new google.maps.LatLng(lat, lng);
	                    map.setCenter(point);
	                    var marker = new google.maps.Marker({
	                        map: map,
	                    	position: point
	            		});
	            	}
	            }
	            return false;
	        }
		);

		//$('#tabs').bind('tabsshow');
}
