﻿$(function(){
  /*****************/
  /*GESTION MENU*/
  /*****************/
  $('#layout-navigation').stickyPanel({
      topPadding: 0,
      afterDetachCSSClass: "",
      savePanelSpace: false
  });
  
  //Cufon.replace('h1 a');
  //Cufon.replace('.line .box span');
  //Cufon.replace('#welcome');
  
  /*****************/
  /*CENTRAGE VERTICAL*/
  /*****************/
  $('.centerXY').verticalAlign();
  $('.centerY').verticalAlign();
  
  
  /*****************/
  /*SLIDER DE NEWS*/
  /*****************/
  $('.news-slider:not(.divid)').each(function(){
    	var slider = $(this).bxSlider({
    	  controls:false,   
          infiniteLoop: false
        });
      
      $('.slider-next', $(this).parent().parent().parent()).click(function(){
        slider.goToNextSlide();
        return false;
      });
      
      $('.slider-prev', $(this).parent().parent().parent()).click(function(){
        slider.goToPreviousSlide();
        return false;
      });
  });
  
  /*****************/
  /*POPIN NEWS*/
  /*****************/  
  $('.colorbox').colorbox({
	title: true,
	/*scrolling: false,*/
	height: '80%',
	opacity: 0.6,
    	current:"actu {current} sur {total}",
	onComplete: function(){
          /*$('#cboxLoadedContent').jScroller({
            position: {
              orientation: 'vertical',
              side: 'right'
            }
          });*/
	}    	
  });
  
  /*****************/
  /*Sur plusieurs colonnes (s'il faut)*/
  /*****************/
 /* $('.columnize').columnize({
    width: 300,
    height: 300,
    buildOnce: true
  });*/
 
  
  /*****************/
  /*GESTION DU MENU*/
  /*****************/
  function updateMenu(){
  //alert($(window).height());
		var pos = $(window).scrollTop();
		
		if (pos <=0){
			unbindLocalScroll();
		} else {
			rebindLocalScroll();
		}
		
		var name = '';
		$('a[name]').each(function(){
			if ($(this).offset().top>=(pos+150)){
				if ($(this).offset().top < pos+$(window).height())
				{
					name=$(this).attr('name');
					return false;
				}
			}
		});
		
		$('.menu li').removeClass('current');
		$('.menu a[href="#'+name+'"]').parent().addClass('current');
		
  }
  
		
	function rebindLocalScroll(){
		$('.menu a').unbind();
		$.localScroll({
			axis: 'y',
			offset: {
				top: -160,
				left:0
			},
			margin:true
		});	
	}
  
    function unbindLocalScroll(){
		$('.menu a').unbind();
		 $.localScroll({
				axis: 'y',
				offset: {
					top: -285,
					left:0
				},
				onAfter: function(){
					//Hack because the first, it did not scroll as i want
					rebindLocalScroll();
				},
				margin:true
		});	
	}
	
  $(window).scroll(function(){
	updateMenu();   
  });
  
  updateMenu();

  /*****************/
 
  /*****************/
  /*GESTION DU PARALLAX*/
  /*****************/  
   
  var $pxs_container	= $('#pxs_container');
  $pxs_container.parallaxSlider({
	speed: 1500
  });
  
  $pxs_container.imagesLoaded( function(){
	    $(window).trigger('resize');     
	 //Trick to update the navigation bar	    
   });

   $('a[name="images"]').click(function(e){
		e.preventDefault();
		$('#layout-main').html('');
   });
  /*****************/

  
  /*****************/
  /*GESTION VIDEO*/
  /*****************/
 /* $('#jquery_jplayer_1').jPlayer({
    ready: function(){
      $(this).jPlayer('setMedia', {
        flv: $(this).attr('rel'),
        poster: "http://kmc92.fr/Resource/ResizeImage?url=%2FCms_Data%2FContents%2FKravMaga%2FMedia%2FPhotos%2FHome%2FPatchwork%2Fimage024_tn.jpg&width=250&height=250"
      });
    },
    supplied: "flv",
    errorAlerts: true,
    warningAlerts: true,
    swfPath:'/Cms_Data/Sites/KravMaga/Scripts',
    size: {
              width: "640px",
              height: "360px"
    }    
  });*/
  
  /*flowplayer('player', '/Cms_Data/Sites/KravMaga/Scripts/flowplayer-3.2.7.swf', {
    clip: {
      autoPlay: false
    }
  });
    */
  $('.colorbox-iframe').colorbox({
	title: true,
	/*scrolling: false,*/
        iframe: true,
        height: '650px',
        width: '1024px',
	opacity: 0.6,
    	current:"videos {current} sur {total}",
	onComplete: function(){
          //$.colorbox.resize()
	}    	
  });
  /*****************/
  /*GESTION IE*/
  /*****************/
  if ($.browser.msie) {
	$('.line').addClass('line-msie');
	$.scrollTo(1); //hack to place the .line
  }
  
  /*****************/
  /*GESTION FAQ (si il y a)*/
  /*****************/  
  $(".faq" ).accordion({
    collapsible: true
  });
  
  /*****************/
  /*SUIVI Google Analytics Ajax*/
  /*****************/
  
  /*****************/
  /*SUIVI Google Analytics Ajax*/
  /*****************/
//  $.fn.track.defaults.debug = true;
  $.trackPage('UA-21526154-1');
  $('a[class*="gatrack"]').track({
    category:function(element){      
      var c = /gatrack-([^ ]+)/.exec(element.attr('class'));
      if (c != null && c.length == 3)
        return c[2];
      
      return "general";      
    }
  });
  
  //$('.scroll-pane').jScrollPane();
});
