// Delay Plugin for jQuery
// - http://www.evanbot.com
// - copyright 2008 Evan Byrne
/*
 * Jonathan Howard
 * jQuery Pause
 * version 0.2
 * Requires: jQuery 1.0 (tested with svn as of 7/20/2006)
 * Feel free to do whatever you'd like with this, just please give credit where
 * credit is do.
 * pause() will hold everything in the queue for a given number of milliseconds,
 * or 1000 milliseconds if none is given.
 */
// Wait Plugin for jQuery
// http://www.inet411.com
// based on the Delay and Pause Plugin
 (function($) {
    $.fn.wait = function(option, options) {
        milli = 1000; 
        if (option && (typeof option == 'function' || isNaN(option)) ) { 
            options = option;
        } else if (option) { 
            milli = option;
        }
        // set defaults
        var defaults = {
            msec: milli,
            onEnd: options
        },
        settings = $.extend({},defaults, options);

        if(typeof settings.onEnd == 'function') {
            this.each(function() {
                setTimeout(settings.onEnd, settings.msec);
            });
            return this;
        } else {
            return this.queue('fx',
            function() {
                var self = this;
                setTimeout(function() { $.dequeue(self); },settings.msec);
            });
        }

    }
})(jQuery);


$(document).ready(function(){

	/* SLIDER HOME */
	
	$('#sliderImages').bxSlider({
		mode: 'fade',
		speed: 1000,
		pause: 5000,
		auto: true,
		controls: false,
		auto_direction: 'right',
		//width: 938,
		wrapper_class: 'example3_container'
	});	
	
	/* MENU GLOBAL */
	
	$("ul.subnav").parent().append("<span>+</span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	
	$("#menu ul.topnav li span").click(function() { //When trigger is clicked...
	
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
	
		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});
	
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	/* LANGUE */
	var closeLangue = function() {
		$("#menu ul.topnav li:not(.langues) a").unbind('mouseover', closeLangue);
		$("#menuLangue").slideUp('slow');
	};
	$("#menu ul.topnav li.langues").click(function() {
		$("#menuLangue").slideDown('fast');
		$("#menu ul.topnav li:not(.langues) a").bind('mouseover', closeLangue);
		return false;
	}
	);
	
	/* ENCART HOME */
	$("a.linkVideo").prettyPhoto();
	$("a.linkVideo").mouseover(function() {
		$(this).animate({
			'filter': 'alpha(opacity=90)', 
			'opacity': 0.9
			}, 
			'normal', 
			function() { 
			});
	});	
	$("a.linkVideo").mouseout(function() {
		$(this).animate({
			'filter': 'alpha(opacity=0)', 
			'opacity': 0
			}, 
			'normal', 
			function() { 
			});
	});	
	/*$("a.linkText span").mouseover(function() {
		$(this).parent().animate({
			'opacity': 0.7
			}, 
			'normal', 
			function() { 
			});
	});	*/
	/*$("a.linkText span").mouseout(function() {
		$(this).parent().animate({
			'opacity': 0
			}, 
			'normal', 
			function() { 
			});
	});	*/
	
	/* PAGE ATHLETES */
	$('#sliderAthletes div.sMenu a.off').css('opacity',0.5);
	$('#sliderAthletes div.sMenu a.off').hover(function() {
			$(this).stop(false,true).animate({'opacity':1}, {duration:500});
		},
		function() {
			 $(this).stop(false,true).animate({'opacity':0.5}, {duration:400});	
	});

	
	/* ACCUEIL SHOP */
	//move the image in pixel
		var move = -15;
		
		//zoom percentage, 1.2 =120%
		var zoom = 1.2;
	
		//On mouse over those thumbnail
		$('.item').hover(function() {
			
			//Set the width and height according to the zoom percentage
			width = $('.item').width() * zoom;
			height = $('.item').height() * zoom;
			
			//Move and zoom the image
			$(this).find('img').stop(false,true).animate({'width':width, 'height':height, 'top':move, 'left':move}, {duration:500});
			
			//Display the caption
			$(this).find('div.caption').stop(false,true).fadeIn(500);
		},
		function() {
			//Reset the image
			$(this).find('img').stop(false,true).animate({'width':$('.item').width(), 'height':$('.item').height(), 'top':'0', 'left':'0'}, {duration:400});	
	
			//Hide the caption
			$(this).find('div.caption').stop(false,true).fadeOut(500);
		});
		
	/* SHOP */
	
	$('ul.listproduits img:not(.selected)').css('opacity',0.5);
	$('ul.listproduits li').hover(function() {
			$(this).find('img').stop(false,true).animate({'opacity':1}, {duration:500});
		},
		function() {
		    if ($(this).find('img').attr('class') != 'selected')
		    {
			 $(this).find('img').stop(false,true).animate({'opacity':0.55}, {duration:400});	
		    }
	});
	$('ul.listproduits li a').click(function(event){        event.stopPropagation();    });
    
	
	/*$("a.linkproduit").mouseover(function() {
		$(this).parent().find('img').animate({
			'filter': 'alpha(opacity=100)', 
			'opacity': 1,
			}, 
			'normal', 
			function() { 
			});
	});	
	$("a.linkproduit").mouseout(function() {
		var imgToTo = $(this).parent().find('img');
		var laclass = imgToTo.attr('class');
		if (laclass != 'selected')
		{
			imgToTo.animate({
				'filter': 'alpha(opacity=55)', 
				'opacity': 0.55,
				}, 
				'normal', 
				function() { 
				});
		};
	});*/
	
	$("div.scrollable").scrollable({ 
	        vertical:false,  
	        size: 1 
	    });
						
});