$(document).ready(function()
	{
	$(function () {
				
//////////open links in external window
		$('A[rel="external"]').click( function() {
			window.open( $(this).attr('href') );
			return false;
   		 });
   		 
///////////////////custom training tips
		$('.trainingTips:first').css("margin-top", "10px");
		$('.trainingTips:last').css("border-bottom", "none");
		
//////////product details photo galery
		$(function() {
		$(".image").click(function() {
			var image = $(this).attr("rel");
			$('#product-detail-image').hide();
			$('#product-detail-image').fadeIn('slow');
			$('#product-detail-image').html('<img src="' + image + '"  alt="Product image" />');
			return false;
			});
		});
					
//////////When you pass over me, I'm shining like the sun
		$('#mainMenu li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(450, 0);
			});
		});
		/*
		$('.sproduct').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(250, 1);
			}, function () {
				$img.stop().fadeTo(250, 0);
			});
		});
		*/
		$('#printandresize li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(250, 1);
			}, function () {
				$img.stop().fadeTo(250, 0);
			});
		});
		$('#btnTop').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('#Activis').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('#shoppingmenu li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(250, 1);
			}, function () {
				$img.stop().fadeTo(350, 0);
			});
		});
		$('#advsearch li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('.btn-readmore').find('a').each(function () {
			var $img = $('.hover', this).css("opacity", "0");
			var $img = $('.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('.btn-sendNewsletter li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('.btn-findlocator li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('#staytuned-btn li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('#footerSubMenu li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('.btnNav').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('.btn-join-us-on-facebook').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('.btn-clearContatcForm').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('.btn-sendContatcForm').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		
//////////The last one doesn't get a piece of cake
		$("ul").find("li:last").each(function(){
			$(this).css({"border":"none"});
		});
		
		
		
////////////////////////
$(" #mainMenu ul ul ").css('opacity', 0);
$(" #mainMenu ul ul ").css({display: "none"}); // Opera Fix
$(" #mainMenu li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).animate({ 
        "height": "toggle",
        opacity: 1      
      }, 300 );
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"}).animate({ 
        "height": "toggle",
        opacity: 0      
      }, 200 );
		});


		
//////////When you look at me ... I completely disappear
		$("#top").find("input").each(function(){
			$(this).focus(function () {
				$(this).val("");
			});
		});
		
//////////Make me bigger or smaller, I don't care

		function setCookie(value){
			document.cookie = "textSize="+value+"; expires=; path=/";
		}
		function getCookie(c_name){
			if (document.cookie.length>0){
			  c_start=document.cookie.indexOf(c_name + "=");
				  if (c_start!=-1){ 
				    c_start=c_start + c_name.length+1; 
				    c_end=document.cookie.indexOf(";",c_start);
				    if (c_end==-1) c_end=document.cookie.length;
				    return unescape(document.cookie.substring(c_start,c_end));
			    } 
			}
		return "";
		}
		
		
		function getActualSize(){
			var actualSizePx = $(".reseizableText").css("font-size");
			var actualSize = actualSizePx.substr(-0,2);
			//alert(actualSize);
		return actualSize;
		
		
		}

		/*
		getSize = getCookie("textSize");
		if(getSize!=null && getSize!=""){
			$("body").css({"font-size":""+getSize+""});
			getActualSize();	
		};
*/
		$("a#minus").click(function(){
			showSize = getActualSize();
			parseSize = parseInt(showSize,10);
			var newSize = parseSize - 1;
			$(".reseizableText").css({"font-size":newSize + "px"});
			setCookie(""+ newSize + "px");
			getActualSize();
			//alert(newSize);
		});
		$("a#plus").click(function(){
			showSize = getActualSize();
			parseSize = parseInt(showSize,10);
			var newSize = parseSize + 1;
			$(".reseizableText").css({"font-size":newSize + "px"});
			setCookie(""+ newSize + "px");
			getActualSize();
			//alert(newSize);		
		});
		
		
		
//////////Little bubble falling from the sky
		$("#bubble").css('opacity', 0);
		$("#soon").hover(function(){
			$("#bubble")
			.css({
				display: "block"
			})
			.animate( { opacity:1 }, { queue:false, duration:500 })
			.animate({top: "0px"},{ queue: false, duration:500});
		}, function(){
			$("#bubble").stop()
			.animate( { opacity:0 }, {duration:500 })
			.animate({top: "-45px"},{duration:1});
		});
		
		$("#bubbleExpand").css('opacity', 0);
		$("#shoppingopenload").hover(function(){
			$("#bubbleExpand")
			.css({
				display: "block"
			})
			.animate( { opacity:1 }, { queue:false, duration:500 })
			.animate({top: "0px"},{ queue: false, duration:500});
		}, function(){
			$("#bubbleExpand").stop()
			.animate( { opacity:0 }, {duration:500 })
			.animate({top: "-45px"},{duration:1});
		});
		
		$("#bubbleConsultPanier").css('opacity', 0);
		$("#consulter-panier").hover(function(){
			$("#bubbleConsultPanier")
			.css({
				display: "block"
			})
			.animate( { opacity:1 }, { queue:false, duration:500 })
			.animate({top: "0px"},{ queue: false, duration:500});
		}, function(){
			$("#bubbleConsultPanier").stop()
			.animate( { opacity:0 }, {duration:500 })
			.animate({top: "-45px"},{duration:1});
		});
		
		$("#bubbleCheckoutPnaier").css('opacity', 0);
		$("#checkout-panier").hover(function(){
			$("#bubbleCheckoutPnaier")
			.css({
				display: "block"
			})
			.animate( { opacity:1 }, { queue:false, duration:500 })
			.animate({top: "0px"},{ queue: false, duration:500});
		}, function(){
			$("#bubbleCheckoutPnaier").stop()
			.animate( { opacity:0 }, {duration:500 })
			.animate({top: "-45px"},{duration:1});
		});
		
//////////The french connection
		$("#connexion").each(function(){
			// options
			var hideDelay = 500;
			var hideDelayTimer = null;
		
			// tracker
			var beingShown = false;
			var shown = false;
			
			$("#connexion,#connectMe")
			.mouseover(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				if (beingShown || shown) {
				return;
				} else {
				beingShown = true;
				
				$("#connectMe")
				.css({
					display: "block"
				})
				.animate({ 
					opacity:1,
					top:0
				},500, "swing", function() {
		          beingShown = false;
		          shown = true;
		        });
		        }
			}).mouseout(function(){
				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					$("#connectMe")
					.animate({ 
						opacity:0,
						top:-45
					}, 500, 'swing', function () {
					shown = false;
					$("#connectMe").css('display', 'none');
					});
					}, hideDelay);
			});
		});

		
//////////Print me me me...
		$("#print").click(function(){
			window.print();
		});
		
		

/////////She's The Form, you have to do what she say...
		$(".post").find(":text").each(function(){
			$(this).addClass("text");
		});
		$(".post").find(":password").each(function(){
			$(this).addClass("password");
		});
		$(".post").find(":checkbox").each(function(){
			$(this).addClass("checkbox");
		});
		$(".post").find(":submit").each(function(){
			$(this).addClass("submit");
		});
		$(".post").find(":button").each(function(){
			$(this).addClass("submit");
		});
		
		
/////////////// THE PRODUCT GALERY
            $("#infinite").scrollable({size: 3}).circular().mousewheel();	
            $("#infinite2").scrollable({size: 6, clickable: false, nextPage: '.next-thumb', prevPage: '.previous-thumb'}).circular().mousewheel();
			
            $("#infinite2 img").click(function() {	
                var index = $("#infinite2 img").index(this);
                if(index <= 5){
                    $("#infinite").scrollable().seekTo(index + 10);	
                }else if(index >= 22){
                    $("#infinite").scrollable().seekTo(index - 18);	
                }else{
                    $("#infinite").scrollable().seekTo(index - 4);	
                };		
            });
            
            $("#infinite2 img").hover(function(){
                $(this).addClass("thumb-over");	
                var $curr = $(this);
                $curr.prev().addClass("thumb-over-left");	
                $curr.next().addClass("thumb-over-right");
            },function () {
                $(this).removeClass("thumb-over");	
                var $curr = $(this);
                $curr.prev().removeClass("thumb-over-left");
                $curr.next().removeClass("thumb-over-right");
            }
            );
			
			$(".product-images img").click(function() {	
                var index = $("#infinite img").index(this);
            });
			
			$(".product-images img").hover(function(){
                $(this).addClass("product-images-highlight");	
				$("#big-frame").css("display", "none");
            },function () {
                $(this).removeClass("product-images-highlight");
				$("#big-frame").css("display", "block");
            }
            );
				

	});	

});