/* Author: Amiral agence web :: Eric Forgues

*/


$(document).ready(function(){
	//Scrollbar
	var oScroll1 = $('#scrollbar1');
	if(oScroll1.length > 0){
		oScroll1.tinyscrollbar({ sizethumb: 75 });
	}
	//Fin de scroll

	//Sous menu
	$('.sous_nav').hide();
	
	$('#principal li').mouseenter(function(){
		$(this).find('.sous_nav').fadeIn(150);
	})
	$('#principal li').mouseleave(function(){
		$(this).find('.sous_nav').fadeOut(150);
	})
	//Fin sous menu
	
	//Lien boite
	$('.liens_boites').click(function(){
		window.location = $(this).find('a').attr('href');
	})
	//Fin lien boite
	
	
	//Slider
	$('#orthese').attr('nb_slide', $('#orthese .slider_panel .slide').length);
	$('#prothese').attr('nb_slide', $('#prothese .slider_panel .slide').length);
	var locked = false;
	var width = $('#orthese .slider_panel .slide').outerWidth()+10; //10px de margin entre chaque
	if($('#orthese').attr('nb_slide')) {
		$('#orthese').attr('pos', 1);
		$('#prothese').attr('pos', 1);
				
		if($('#orthese').attr('nb_slide') == 1) {
			$('#orthese .go-right').hide();
		}
		if($('#prothese').attr('nb_slide') == 1) {
			$('#prothese .go-right').hide();
		}
		
		$('.go-right').click(function(){
			if(!locked) {
				locked = true;
				$(this).parent().find('.slider_panel').animate({left: '-='+width}, function(){
					locked = false;
				});
				$(this).parent().find('.go-left').fadeIn();
				$(this).parent().attr('pos', parseInt($(this).parent().attr('pos'))+1);
				if($(this).parent().attr('pos') == $(this).parent().attr('nb_slide')) {
					$(this).parent().find('.go-right').fadeOut();
				}
			}
		})
		
		$('.go-left').click(function(){
			if(!locked) {
				locked = true;
				$(this).parent().find('.slider_panel').animate({left: '+='+width}, function(){
					locked = false;
				});
				$(this).parent().find('.go-right').fadeIn();
				$(this).parent().attr('pos', parseInt($(this).parent().attr('pos'))-1);
				if($(this).parent().attr('pos') == 1) {
					$(this).parent().find('.go-left').fadeOut();
				}
			}
		})
	}
	//Fin slider
	
	//Btn orthesistes/prothesistes
	$('#view-orthese').click(function(e){
		$('#prothese').hide();
		$('#orthese').show();
		e.preventDefault();
	})
	$('#view-prothese').click(function(e){
		$('#orthese').hide();
		$('#prothese').show();
		e.preventDefault();
	})
	//Fin Btn orthesistes/prothesistes
	
	//Image thumb
	$('.image .succ img').each(function(){
		var my_actual_width = $(this).width();
		var my_desired_width = $(this).parent().width();
		
		var my_actual_height = $(this).height();
		var my_desired_height = $(this).parent().height();
		
		if(my_actual_width/my_actual_height >= my_desired_width/my_desired_height) {
			$(this).css('height', my_desired_height);
			var diff = $(this).width() - my_desired_width;
			$(this).css('left', -(diff/2));
		}
		else {
			$(this).css('width', my_desired_width);
			var diff = $(this).height() - my_desired_height;
			$(this).css('top', -(diff/2));
		}
		
		
	})
	//Fin Image thumb
	
	//Slider nav
	$('.slider_nav a').click(function(e){
		e.preventDefault();
		
		locked = true;
		
		if($(this).attr('pos') > 0) {
			$('#orthese .go-left').fadeIn();
		}
		else {
			$('#orthese .go-left').fadeOut();
		}
		
		if($(this).attr('pos') == $('#orthese').attr('nb_slide')-1) {
			$('#orthese .go-right').fadeOut();
		}
		else {
			$('#orthese .go-right').fadeIn();
		}
		
		$('#orthese .slider_panel').animate({left: '-'+$(this).attr('pos')*width}, function(){
			locked = false;
		});
		
		$('#orthese').attr('pos', parseInt($(this).attr('pos'))+1);
	})
	//Fin Sleder nav
})






















