(function($) {

	var browserName=navigator.appName; 
	if (browserName=="Microsoft Internet Explorer")
	{
	  $this = $('h1 > span');
      var letter = $this.text().substr(0,1);
      var index = $this.html().indexOf(letter,0);

      if( 0 != index )
      {
        var pos1 = $this.html().indexOf('< ',0);
        var pos2 = $this.html().indexOf('>',0);
        while( ( pos1 < index) && ( pos2 > index) )
        {
          
          index = $this.html().indexOf(letter,pos2);
          pos1 = $this.html().indexOf('< ',pos1+1);
          pos2 = $this.html().indexOf('>',pos2+1);        
        }
        index = $this.html().indexOf(letter,pos2);
        $this.html( $this.html().substr(1,index) + '<span>' + $this.html().charAt(0) + '</span>' + $this.html().substr(index+1));
      }
      else 
      {
        $this.html('<span>' + $this.html().charAt(0) + '</span>'+$this.html().substr(1));
      }
	 }
	 else
	 {
    $this = $('h1 > span');
      var letter = $this.text().substr(0,1);
      var index = $this.html().indexOf(letter,0);

      if( 0 != index )
      {
        var pos1 = $this.html().indexOf('< ',0);
        var pos2 = $this.html().indexOf('>',0);
        while( ( pos1 < index) && ( pos2 > index) )
        {
          
          index = $this.html().indexOf(letter,pos2);
          pos1 = $this.html().indexOf('< ',pos1+1);
          pos2 = $this.html().indexOf('>',pos2+1);        
        }
        index = $this.html().indexOf(letter,pos2);
        $this.html( $this.html().substr(2,index) + '<span>' + $this.html().charAt(1) + '</span>' + $this.html().substr(index+1));
      }
      else 
      {
        $this.html('<span>' + $this.html().charAt(1) + '</span>'+$this.html().substr(2));
      }
	}
  function debug($obj) {
    if (window.console && window.console.log)
      window.console.log('lettrine selection count: ' + $obj.size());
  };

})(jQuery);


$(document).ready(function($){

	// Ambiance	
	var idDep;
	function recupIdDep(o){
		idDep = $(o).attr("id");
	};

	$(".ambiance a").click(function(){
		recupIdDep(this);
		$("body").attr('class', idDep);
		$(".ambiance a").removeClass('active');
		$(this).addClass('active');
	});
	
	// lighbox
	$('.list-images a').lightBox();	
	$('a.lightbox').lightBox();
	$('a.lightbox-2').lightBox();
			
	// Chantiers en cours - Navigation vignette
	$('.cycle').cycle({ 
    fx:     'fade', 
    speed:  'slow', 
    timeout: 0, 
    pager:  '#carousel', 
    pagerAnchorBuilder: function(idx, slide) { 
        return '#carousel a:eq(' + idx + ')'; 
    } });
	
	// Chantiers en cours - Carrousel
	$("#carousel").jcarousel({
       wrap: 'last'
    });
	
	// Chantiers en cours - Vignette active
	$("a.activeSlide").parents("li").addClass('active');
	$("#carousel li.active").append('<div class="image-1 thumb-active"></div>');
	$(".thumb a").click(function () {
	  $("#carousel li").removeClass('active');
	  $(this).parents("li").addClass('active');
	  $(".thumb-active").remove();
	  $("#carousel li.active").append('<div class="image-1 thumb-active"></div>');
	 });
	
	// Chantiers en cours - Bulle
	$(".thumb").hover(function(){
	$(this).next("p").fadeIn();
	$(this).parent("div").css("zIndex","100");
	}, function() {
	$(this).next("p").fadeOut();
	$(this).parent("div").css("zIndex","0");
	});
	
	$(".popup").click(function(){ 
    window.open($(this).attr("href")); 
    return false; 
	}); 
});
