
jQuery(document).ready(function($){

	
	  // jqDock
	  var dockOptions =
		{ align: 'middle' // horizontal menu, with expansion UP/DOWN from the middle
		, size: 45  // set the maximum minor axis (horizontal) image dimension to 36px
		, labels: 'tc'  // add labels (override the 'tl' default)
		};
	  // ...and apply...
	  $('#menu').jqDock(dockOptions);	
	
	
	// module de défilement références clients
	(function($){
	  $.fn.list_ticker = function(options){
		
		var defaults = {
		  speed:4000,
		  effect:'slide'
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function(){
		  
		  var obj = $(this);
		  var list = obj.children();
		  list.not(':first').hide();
		  
		  setInterval(function(){
			
			list = obj.children();
			list.not(':first').hide();
			
			var first_li = list.eq(0)
			var second_li = list.eq(1)
			
			if(options.effect == 'slide'){
				first_li.slideUp();
				second_li.slideDown(function(){
					first_li.remove().appendTo(obj);
				});
			} else if(options.effect == 'fade'){
				first_li.fadeOut(function(){
					second_li.fadeIn();
					first_li.remove().appendTo(obj);
				});
			}
		  }, options.speed)
		});
	  };
	  
	  
	})(jQuery);
	
	
	// déclenchement du défilement des références clients
	$('#fade').list_ticker({
			speed:6000,
			effect:'fade'
		});



	//Tooltips : ouverture d'une infobulle au survol (ex. client testimonial)
	$(".tip_trigger").hover(function(){
		tip = $(this).find('.tip');
		tip.show(); //Show tooltip
	}, function() {
		tip.hide(); //Hide tooltip		  
	}).mousemove(function(e) {
		var mousex = e.pageX + 20; //Get X coodrinates
		var mousey = e.pageY + 20; //Get Y coordinates
		var tipWidth = tip.width(); //Find width of tooltip
		var tipHeight = tip.height(); //Find height of tooltip
		
		//Distance of element from the right edge of viewport
		var tipVisX = $(window).width() - (mousex + tipWidth);
		//Distance of element from the bottom of viewport
		var tipVisY = $(window).height() - (mousey + tipHeight);
		  
		if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
			mousex = e.pageX - tipWidth - 20;
		} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
			mousey = e.pageY - tipHeight - 20;
		} 
		tip.css({  top: mousey, left: mousex });
	});
	
	
	
	//tabs : onglets des pages capabilities
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //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
		return false;
	});



	  // slides pour faire défiler horizontalement les screenshots dans les pages capabilities
	  var currentPosition = 0;
	  var slideWidth = 630;
	  var slides = $('.slide');
	  var numberOfSlides = slides.length;	
	  // Remove scrollbar in JS
	  $('#slidesContainer').css('overflow', 'hidden');	
	  // Wrap all .slides with #slideInner div
	  slides
		.wrapAll('<div id="slideInner"></div>')
		// Float left to display horizontally, readjust .slides width
		.css({
		  'float' : 'left',
		  'width' : slideWidth
		});	
	  // Set #slideInner width equal to total width of all slides
	  $('#slideInner').css('width', slideWidth * numberOfSlides);	
	  // Insert controls in the DOM
	  $('#slideshow')
		.prepend('<span class="control" id="leftControl">Clicking moves left</span>')
		.append('<span class="control" id="rightControl">Clicking moves right</span>');	
	  // Hide left arrow control on first load
	  manageControls(currentPosition);	
	  // Create event listeners for .controls clicks
	  $('.control')
		.bind('click', function(){
		// Determine new position
		currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;		
		// Hide / show controls
		manageControls(currentPosition);
		// Move slideInner using margin-left
		$('#slideInner').animate({
		  'marginLeft' : slideWidth*(-currentPosition)
		});
	  });	
	  // manageControls: Hides and Shows controls depending on currentPosition
	  function manageControls(position){
		// Hide left arrow if position is first slide
		if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
		// Hide right arrow if position is last slide
		if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }
	  }	

});
