$(function(){
	
    var root = location.protocol + '//' + location.host;
		
    /* Tooltip */
	 
    $('.tip').tooltip({
        effect: 'slide'
    });
    $('.tip-orange').tooltip({
        effect: 'slide',
        tipClass:'tooltip-orange',
        offset:[-15, 0]
    });
       


	
    /* Missions */
	
    $('.page_missions #choix li')
    .fadeTo('fast',.5)
    .hover(function(){
        $(this).stop().fadeTo('fast',1).siblings().stop().fadeTo('fast',.5);
    },function(){
        $(this).siblings().add($(this)).stop().fadeTo('fast',.5);
    });
	
    $('.page_missions #choix_small li:not(.active)')
    .fadeTo('fast',.5)
    .hover(function(){
        $(this).stop().fadeTo('fast',1).siblings(':not(.active)').stop().fadeTo('fast',.5);
    },function(){
        $(this).siblings(':not(.active)').andSelf().stop().fadeTo('fast',.5);
    });
	
    /* Sous-menu références */
	
    $('.page_references #sous_menu li:not(.active)')
    .append('<span></span>')
    .hover(function(){
        $(this).find('span').hide();
    },function(){
        $(this).find('span').show();
    })
    ;
	
    /* Colorbox */
	
    if($('.page_references').size()>0) {
      
    function initColorbox(){
         $('.colorbox').colorbox({
            opacity:0.6,
            onComplete: function(){
                
                $('#cboxContent .page_reference_detail #siblings')
                .css({
                    marginLeft: - $('#cboxContent .page_reference_detail #siblings').width()/2 + 'px', // centre la liste
                    left: '50%'
                });
                initColorbox();



            }
        });
    }
    initColorbox();


                
		
		
    }
	
    if($('.page_societe').size()>0) {
	$('.colorbox2').colorbox({
            opacity:0.6,
            inline:true,
            href:"#map",
            onComplete: function(){
                var longitude = $(this).attr('longitude');
                var latitude = $(this).attr('latitude');
                var titre = $(this).parents('li').find('strong').html();
                //alert(longitude+' '+latitude+' '+titre);

                var elem2 = $(this).parents('li').clone();
                elem2.find('.clear').remove();
                elem2.find('a').remove();
                var content = elem2.html();


                if (!est_charge){
                    initialize(latitude,longitude );
                }
                set_point(latitude,longitude, titre, content);


            }




        });
	
    }
	


    $(".contenu-annonce, .page_missions #contenu, .page_metiers #contenu,  .page_mentions-legales #contenu").jScrollPane();

              

});



var map;
var est_charge = false;
function initialize(latitude,longitude) {
    var myLatlng = new google.maps.LatLng(latitude,longitude);
    var myOptions = {
        zoom: 12,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.HYBRID
    }

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    est_charge = true;


}
function set_point(latitude,longitude, titre, content){
    var myLatlng = new google.maps.LatLng(latitude,longitude);
    map.setCenter(myLatlng);
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title : titre
    });

    var infowindow = new google.maps.InfoWindow(
    {
        content: content
    });
    google.maps.event.addListener(marker, 'mouseover', function() {
        infowindow.open(map,marker);
    });


}
