$(document).ready( function () { 	
  
	//vire les ancres des menu parents
	$("li.page-item-14 a:first").attr('href', 'javascript:void(0);');
	$("li.page-item-19 a:first").attr('href', 'javascript:void(0);');
	$("li.page-item-21 a:first").attr('href', 'javascript:void(0);');
				
				
	/******************************************
	*	
	*	videos home
	*	
	*******************************************/
	
	$('.featured-content').hide();
	
	$('.show-video').click(function() {
		$(this).next().modal();
	
	});
	
	/******************************************
	*	
	*	background	*	
	*******************************************/	
	
	   var theWindow        = $(window),
            $bg              = $("#bg"),
            aspectRatio      = $bg.width() / $bg.height();

        function resizeBg() {

                if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
                    $bg
                        .removeClass()
                        .addClass('bgheight');
                } else {
                    $bg
                        .removeClass()
                        .addClass('bgwidth');
                }

        }

        theWindow.resize(function() {
                resizeBg();
        }).trigger("resize");
	
	/******************************************
	*	
	*	products thumbs home
	*	
	*******************************************/	
	
		
				
  
  	$(".grey-btn").mouseenter(function() {
	 $(".grey-btn").animate({opacity: '0.7'}, "medium");
  }).mouseleave(function() {
    $(".grey-btn").animate({opacity: '1'}, "medium");
  });
  
  
/*
	$(".show-products").mouseenter(function() {
	 $(".show-products").animate({opacity: '0.7'}, "medium");
  }).mouseleave(function() {
    $(".show-products").animate({opacity: '1'}, "medium");
  });

  $('#sails-home').hide();
  $("#sails-home").slideDown("medium");
	 $("#fleche").removeClass('flecheDown').addClass('flecheUp');
  
  $(".show-products").click(function() {
	
 if ($("#sails-home").is(":hidden")) {
	$("#sails-home").slideDown("medium");
	 $("#fleche").removeClass('flecheDown').addClass('flecheUp');

	} else {
	$("#sails-home").slideUp("medium");
	 $("#fleche").removeClass('flecheUp').addClass('flecheDown');
	}
  });
   */
    
  /******************************************
	*	
	*	langue choooser
	*	
	*******************************************/
  
  $('#langueChooser').css('left', function(index) {
  return $('#header').width() -120;
});
  
  $("#langueChooser ul").hide();
  
 
  
  
  	$("#langueChooser").mouseenter(function() {
	 $("#langueChooser ul").slideDown("medium");
  }).mouseleave(function() {
    $("#langueChooser ul").slideUp("medium");
  });

 
	showtab(1);
	
   
} ) ; 


$(window).resize(function() {
 $('#langueChooser').css('left', function(index) {
  return $('#header').width() -120;
});
} ) ; 


 /******************************************
	*	
	*	products tabs
	*	
	*******************************************/

function showtab(index){
		$(".tab-product-content").children().hide();
		$(".tab-product-content div:nth-child("+index+")").fadeIn('slow');
		
		$(".tab-product-onglets").children().removeClass('selected');
		$(".tab-product-onglets li:nth-child("+index+")").addClass('selected');
}

 /******************************************
	*	
	*	riders
	*	
	*******************************************/


function showrider(idRider,lang){
	
	goTo('body');

$.ajax({
   type: "POST",
   url: "http://www.loftsails.com/2012/ajax/controleurajax.php",
   data: "a=getrider&idrider="+idRider+"&lang="+lang,
   success: function(html){
     refreshRiderDetail(html);
   }
 });
}


function refreshRiderDetail(html){
	
$("#top-team-detail").empty();
$("#top-team-detail").append(html);

$("#top-team").animate({height: '280'}, "slow");

$("#top-team-present").fadeOut('slow', function() {
        $("#top-team-detail").fadeIn('slow', function() {
        // Animation complete
      });
   });



}


 function goTo(ancre){
 	var speed     = 300;

 	jQuery('html,body').animate({scrollTop:jQuery(ancre).offset().top},speed,'swing',function(){
            if(ancre != 'body')
                window.location.hash = ancre;
            else
                window.location.hash = '#';
            jQuery(ancre).attr('tabindex','-1');
            jQuery(ancre).focus();
            jQuery(ancre).removeAttr('tabindex');
        });
 }
 

