jQuery(document).ready(function() {
  /* MAIN MENU HOVER */
    // menu preparation
    jQuery('#navigation ul').each(function() {
          var lis = jQuery(this).children('li');
        lis.each(function() {
              if ((lis.index(jQuery(this))+1) == lis.size())
              jQuery(this).addClass('last');
          });
    });
    // menu handler
    jQuery('#navigation li:not(#navigation ul li)').each(function() {
          if (jQuery(this).children('ul').size()) {
              jQuery(this).mouseenter(function() {
                 jQuery(this).addClass('active');
            });
              jQuery(this).mouseleave(function() {
                  jQuery(this).removeClass('active');
              });
         }
       });
         //                 //
        //  FRENCH MENU    //
       //                 //
       // menu preparation
    jQuery('#navigationfr ul').each(function() {
          var lis = jQuery(this).children('li');
        lis.each(function() {
              if ((lis.index(jQuery(this))+1) == lis.size())
              jQuery(this).addClass('last');
          });
    });
    // menu handler
    jQuery('#navigationfr li:not(#navigationfr ul li)').each(function() {
          if (jQuery(this).children('ul').size()) {
              jQuery(this).mouseenter(function() {
                 jQuery(this).addClass('active');
            });
              jQuery(this).mouseleave(function() {
                  jQuery(this).removeClass('active');
              });
         }
       });
       
    /* END MAIN MENU */
    
    /* ATHLETESPAGES*/   
       
  //Main Athletes page tabs
  jQuery('#AthletesTabs').tabs();
  //Athlete page tabs
  jQuery('#AthleteInfoTabs').tabs();
  //Athlete page SlideShow
  jQuery('#AthleteBioSlide').anythingSlider({
				width               : 647,       // if resizeContent is false, this is the default width if panel size is not defined
				height              : 365,       // if resizeContent is false, this is the default height if panel size is not defined
				resizeContents      : true,     // If true, solitary images/objects in the panel will expand to fit the viewport
				autoPlay            : true ,     // This turns off the entire slideshow FUNCTIONALY, not just if it starts running or not
				startStopped : false,
				buildArrows         : false,      // If true, builds the forwards and backwards buttons
				navigationFormatter : function(i, panel){
				  var temp;
				  if (i>9)
				    temp="";
				  else
           temp=0;  
           return '<img src="http://testeu.thenorthface.com/blog/wp-content/uploads/2011/06/thumb-'+jQuery('#AthleteName').html().replace(/ /g,"-").replace("'","")+'-'+temp+i+'.jpg" alt="" />';
          },
        startText : "start",
        stopText : "stop"
			});
jQuery(document).ready(function() {
    //rotation speed and timer                  
    var speed = 5000; 
    //grab the width and calculate left value
    var item_width = jQuery('#AthleteBioMedia .thumbNav li').outerWidth();
    var left_value = item_width * (-1);
    //move the last item before first item, just in case user click prev button
    jQuery('#AthleteBioMedia .thumbNav li:first').before(jQuery('#AthleteBioMedia .thumbNav li:last'));
    //set the default item to the correct position
    jQuery('#AthleteBioMedia .thumbNav').css({'left' : -1});
    //if user clicked on prev button
    jQuery('.ScrollLeft').click(function() {
        //get the right position           
        var left_indent = parseInt(jQuery('#AthleteBioMedia .thumbNav ul').css('left')) + item_width;
        //slide the item           
        jQuery('#AthleteBioMedia .thumbNav').animate({'left' : left_indent}, 200,function(){   
            //move the last item and put it as first item              
            jQuery('#AthleteBioMedia .thumbNav li:first').before(jQuery('#AthleteBioMedia .thumbNav li:last'));          
            //set the default item to correct position
            jQuery('#AthleteBioMedia .thumbNav').css({'left' : left_value});
        });
        //cancel the link behavior           
        return false;
    });
 //if user clicked on next button
    jQuery('.ScrollRight').click(function() {
        //get the right position
        var left_indent = parseInt(jQuery('#AthleteBioMedia .thumbNav ul').css('left')) - item_width;
        //slide the item
        jQuery('#AthleteBioMedia .thumbNav').animate({'left' : left_indent}, 200, function () {
            //move the first item and put it as last item
            jQuery('#AthleteBioMedia .thumbNav li:last').after(jQuery('#AthleteBioMedia .thumbNav li:first'));                 
            //set the default item to correct position
            jQuery('#AthleteBioMedia .thumbNav').css({'left' : left_value});
        });
        //cancel the link behavior
        return false;
    });       
        
});
 


  /*END ATHLETES PAGE*/
  
   /** Event Javascript **/
  //Hide noresults div  
     jQuery('#Results').hide();
       var opzioneCountry = new Array();
       var opzioneType = new Array();
    //AutoFill Country select 
    jQuery('.EventCountry').each(function(index) {
      opzioneCountry[index]=jQuery(this).text();                                                
      return opzioneCountry[index];
    });
    //Will check for the Uniqueness
    function selected(opzione){
     temp = new Array();
     for(i=0;i<opzione.length;i++){
      if(!contains(temp, opzione[i])){
       temp.length+=1;
       temp[temp.length-1]=opzione[i];
      }
     };
     };
    function contains(a, e) {
     for(j=0;j<a.length;j++)if(a[j]==e)return true;
     return false;
    }
    selected(opzioneCountry);    
    for(i=0; i<temp.length; i++){
       jQuery('#CountrySelect').append('<option value="'+temp[i].replace(" ","_")+'">'+temp[i]+'</option>');
    };
    //AutoFill Type select
    jQuery('.EventType').each(function(index) {
      opzioneType[index]=jQuery(this).text();                                                
      return opzioneType[index];
    });
    selected(opzioneType);  
    for(i=0; i<temp.length; i++){
      jQuery('#TypeSelect').append('<option value="'+temp[i].replace(" ","_")+'">'+temp[i]+'</option>');
    };
   //Search for events by Type 
    jQuery('#TypeSelect').change(function(){
        jQuery('#Results').hide();
        jQuery('.Event').hide();
        eventcas=jQuery('#TypeSelect').val();
        countrycas=jQuery('#CountrySelect').val();
        if(jQuery('#TypeSelect').val()=="all"){
           if(jQuery('#CountrySelect').val()=="all")
              jQuery('.Event').show();
           else jQuery('.Event').filter('.'+countrycas).show();
         }else{ 
         if(jQuery('#CountrySelect').val()=="all")
           jQuery('.'+eventcas).show();
         else  
         jQuery('.'+eventcas).filter('.'+countrycas).show();
        }
         if( jQuery(".Event:visible").length === 0)
             jQuery('#Results').show();
    });
   //Search for events by Country 
    jQuery('#CountrySelect').change(function(){
        jQuery('#Results').hide();
        jQuery('.Event').hide();
        eventcas=jQuery('#TypeSelect').val();
        countrycas=jQuery('#CountrySelect').val();
        if(jQuery('#CountrySelect').val()=="all"){
          if(jQuery('#TypeSelect').val()=="all")
              jQuery('.Event').show();
          else jQuery('.Event').filter('.'+eventcas).show();
         }else{    
         if(jQuery('#TypeSelect').val()=="all")
           jQuery('.'+countrycas).show();
         else  
         jQuery('.'+countrycas).filter('.'+eventcas).show();
        }       
        if( jQuery(".Event:visible").length === 0)
             jQuery('#Results').show();
    });    

/* SHOP PAGE Javascript */
      
      //Shop Page SlideShow
      jQuery('#HP-SlideShow').anythingSlider({
				width               : 970,       // if resizeContent is false, this is the default width if panel size is not defined
				height              : 411,       // if resizeContent is false, this is the default height if panel size is not defined
				resizeContents      : true,     // If true, solitary images/objects in the panel will expand to fit the viewport
				autoPlay            : true,     // This turns off the entire slideshow FUNCTIONALY, not just if it starts running or not
				startStopped : false,
				delay:    5000,
				buildNavigation : true,
				toggleControls : true,
				toggleArrows : true,
				buildArrows : true,
        startText : "start",
        stopText : "stop"
			});
});    
