/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);

/* Author: Gramm Développement - 2011

*/

/*
 * The background must be relative to the rest of the page elements.
 * The background position.left = 0px when the offset.left of the container = 362.
 * The new background position.left is based on the current position of the container.
 */
var beginBackgroundPositionLeft = 362;
function changeBackgroundPosition() {
    var newLeft = jQuery("div#container").offset().left;
    newLeft = (-1 * beginBackgroundPositionLeft + newLeft) + "px";
    jQuery("body").css("background-position", newLeft + " 0px");
 	jQuery("html").css("overflow-x", "hidden");
}

jQuery(window).resize(function(e){
    //console.log(e);
    // Change the position of the background 
    // when resizing the window.
    changeBackgroundPosition();
});

$(document).ready(function() {
/*
	$('.lecons').hover(function(){
		$('div', this).stop(true, true).show();
	}, function(){
		$('.lecons div').stop(true, true).delay(1500).hide();
	});
*/ 
   function show() {
     var menu = $(this);
     menu.children("div").show();
   }
  
   function hide() { 
     var menu = $(this);
     menu.children("div").hide();
   }
 
   $(".lecons").hoverIntent({
     sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
     interval: 50,   // number = milliseconds for onMouseOver polling interval
     over: show,     // function = onMouseOver callback (required)
     timeout: 300,   // number = milliseconds delay before onMouseOut
     out: hide       // function = onMouseOut callback (required)
   });
   
   
   	$('#color a.rouge').click(function(e){
		e.preventDefault();
		$('html').addClass('theme_rouge');
		$("img[src$='images/lire_video.png']").attr('src', 'images/lire_video_rouge.png');
	});

	$('#color a.bleu').click(function(e){
		e.preventDefault();
		$('html').removeClass('theme_rouge');
		$("img[src$='images/lire_video_rouge.png']").attr('src', 'images/lire_video.png');		
	});

	
	url = top.location.pathname;
	
	if (url.match("unify") === null) {
	
		// replace "unify" (above) with the name of your admin folder and call Cufon as you normally would
		if($('#news'.length)){
		
			$('#col_right.actu').css('height','552px');
			$('#col_right.niveau').css('height','552px');
			$('.niveau #news').css('height','570px');
			$('#news').css('height','552px');
			$('#news').css('overflow','hidden');
		
			$('#news').jScrollPane({
				verticalDragMaxHeight: 36
			});
		}
	}

    // Change the position of the background on entering the page..
    // Is needed because we don't know the resolution of the user so it can't be done with css.
    changeBackgroundPosition();

	if($('.ski-enfant').length){
		$(".post a").fancybox();
	}
	
	if($('.ski-adulte').length){
		$(".post a").fancybox();
	}
	
	if($('.snowboard').length){
		$(".post a").fancybox();
	}		
});
