
/****************************
Intro	
*****************************/


$(window).load(function() {
$('.secondCol').hide();
$('.countryDetail').hide();

$(".preTopLogo").css(
	{
		"top": (($(".topContainer").height() / 2) - ($(".preTopLogo").height() / 2)) + "px",
		"left": (($(document).width() / 2) - $(".preTopLogo").width()) + "px",
		"margin-left": ($(".preTopLogo").width() / 2) + "px"
	}
);

$(".preTopImage").css(
	{
		"bottom": "0px",
		"left": (($(document).width() / 2) - $(".preTopImage").width()) + "px",
		"margin-left": ($(".preTopImage").width() / 2) + "px"
	}
);

$(".link1").click(function() {
	if($('.secondCol').is(":visible")){
		$('.firstCol').slideDown('fast');
		$('.secondCol').slideUp('fast');
	}else if($('.secondCol').is(":hidden")){
		if($('.firstCol').is(":visible")){
			$('.firstCol').slideUp('fast');
		}else{
			$('.firstCol').slideDown('fast');
		}
	}
});

$(".link2").click(function() {
	if($('.firstCol').is(":visible")){
		$('.firstCol').slideUp('fast');
		$('.grpOne + .countryDetail').slideUp('fast');
		$('.grpTwo + .countryDetail').slideUp('fast');
		$('.grpThree + .countryDetail').slideUp('fast');
		$('.secondCol').slideDown('fast');
	}else if($('.firstCol').is(":hidden")){
		if($('.secondCol').is(":visible")){
			$('.secondCol').slideUp('fast');
		}else{
			$('.secondCol').slideDown('fast');
		}
	}
});

$(".grpOne").click(function() {
	if($('.grpOne + .countryDetail').is(":visible")){
		$('.grpOne + .countryDetail').slideUp('fast');
	}else if($('.grpOne + .countryDetail').is(":hidden")){
		$('.grpOne + .countryDetail').slideDown('fast');
		$('.grpTwo + .countryDetail').slideUp('fast');
		$('.grpThree + .countryDetail').slideUp('fast');
	};
});

$(".grpTwo").click(function() {
	if($('.grpTwo + .countryDetail').is(":visible")){
		$('.grpTwo + .countryDetail').slideUp('fast');
	}else if($('.grpTwo + .countryDetail').is(":hidden")){
		$('.grpTwo + .countryDetail').slideDown('fast');
		$('.grpOne + .countryDetail').slideUp('fast');
		$('.grpThree + .countryDetail').slideUp('fast');
	};
});

$(".grpThree").click(function() {
	if($('.grpThree + .countryDetail').is(":visible")){
		$('.grpThree + .countryDetail').slideUp('fast');
	}else if($('.grpThree + .countryDetail').is(":hidden")){
		$('.grpThree + .countryDetail').slideDown('fast');
		$('.grpOne + .countryDetail').slideUp('fast');
		$('.grpTwo + .countryDetail').slideUp('fast');
	};
});
});


$(window).resize(function(){
$(".preTopLogo").css(
	{
		"top": (($(".topContainer").height() / 2) - ($(".preTopLogo").height() / 2)) + "px",
		"left": (($(document).width() / 2) - $(".preTopLogo").width()) + "px",
		"margin-left": ($(".preTopLogo").width() / 2) + "px"
	}
);

$(".preTopImage").css(
	{
		"bottom": "0px",
		"left": (($(document).width() / 2) - $(".preTopImage").width()) + "px",
		"margin-left": ($(".preTopImage").width() / 2) + "px"
	}
);
});
										

/****************************************************************************************************************
	toolbox & print
****************************************************************************************************************/

$('#print').click(function(){

	window.print();
	$(this).blur();
	return false;
	
});

/****************************************************************************************************************
	diaporama / carousel
****************************************************************************************************************/

if($('.diaporamaMenu')){
	
	$('.diaporamaMenu').each(function(i){
		
		var myDiaporamaMenuContainer = $(this).children('.diaporamaMenuContainer');
		
		var myUlLength = myDiaporamaMenuContainer.children('ul').children('li').length;
	
		var myLiWidth = myDiaporamaMenuContainer.children('ul').children('li:eq(1)').width() + parseInt(myDiaporamaMenuContainer.children('ul').children('li:eq(1)').css('margin-left')) + parseInt(myDiaporamaMenuContainer.children('ul').children('li:eq(1)').css('margin-right'));
		
		myDiaporamaMenuContainer.children('ul').css('width', (myLiWidth * myUlLength));
		
		if ($(this).hasClass('textDiaporama')) var shownItems = 2;
		else var shownItems = 3;
		
		if (myUlLength < shownItems){
			
			$(this).children('.prevLink').children('a').addClass('off');
			$(this).children('.nextLink').children('a').addClass('off');
				
		}
		
		else{
			
			var clickPermitted = true;
			
			$(this).children('.prevLink').children('a').addClass('off');
			
			$(this).children('.prevLink, .nextLink').click(function(){
				
				if(clickPermitted){
					
					var myLeft = parseInt(myDiaporamaMenuContainer.children('ul').css('left'));
									
					if ($(this).hasClass('prevLink')) {

						if (myLeft != 0) {
							
							var myNewLeft = myLeft + myLiWidth;
		
							if (myNewLeft == 0) $(this).children('a').addClass('off');
							$(this).siblings('.nextLink').children('a').removeClass('off');
							
						}
					}
					else {
						
						if (myLeft != -(myLiWidth * myUlLength - (myLiWidth*(shownItems-1)))) {
							
							var myNewLeft = myLeft - myLiWidth;
							
							if (myNewLeft == -(myLiWidth * myUlLength - (myLiWidth*(shownItems-1)))) $(this).children('a').addClass('off');
							$(this).siblings('.prevLink').children('a').removeClass('off');
						}
					}
					
					if (myNewLeft != undefined){
						
						clickPermitted = false;
						
						myDiaporamaMenuContainer.children('ul').animate({ 
							left: myNewLeft+'px'
						}, 150, function(){ clickPermitted = true; });
	
					}
			
				}
				
				$(this).blur();
				$(this).children('a').blur();
				return false;
				
			});
		}
				
		/* titles rollover */
		
		myDiaporamaMenuContainer.children('ul').children('li').children('a').each(function(j){
			
			$(this).attr('carouselTitle', $(this).attr('title'));
			$(this).attr('title', '');
			
			$(this).bind('mouseover', function(){

				myDiaporamaMenuContainer.parent().siblings('.prodTitle').html($(this).attr('carouselTitle'));
				
			});
			
		});
		
	});
}

/****************************************************************************************************************
	accordion
****************************************************************************************************************/

$('#nav4 .insideNav4').hide();

$('#nav4 li a.accordionLink').each(function(j){

	$(this).attr('valClick','open');

	$(this).bind('click', function(){
								   
		if ($(this).attr('valClick') == 'open'){
			
			$('#nav4 .insideNav4').slideUp("slow");
			$('#nav4 li a').attr('valClick','open');
			
			$(this).siblings('.insideNav4').slideDown("slow");
			$(this).attr('valClick','close');
		
		}
		
		else{
			
			$('#nav4 .insideNav4').slideUp("slow");
			$('#nav4 li a').attr('valClick','open');
			
		}
		
		$(this).blur();
		return false;
		
	});

});

/****************************************************************************************************************
	popin
****************************************************************************************************************/

$('#openPopin').click(function(){

	$('#popin').fadeIn("fast");
	$(this).blur();
	return false;
	
});

$('#closeButton').click(function(){

	$('#popin').fadeOut("normal");
	$(this).blur();
	return false;
	
});

/****************************************************************************************************************
	Skin des scrolls
****************************************************************************************************************/

$('.scroll-pane').jScrollPane({showArrows:true});

/****************************************************************************************************************
	Points de vente
****************************************************************************************************************/

$('.pdvCartouche').bind('mouseover',function(){
	$(this).children('p').show();
});
$('.pdvCartouche').bind('mouseout',function(){
	$(this).children('p').hide();
});

/****************************************************************************************************************
	spam filter / emails
****************************************************************************************************************/

/*$('.emailToLoad').each(function(i){
	
	var myString = $(this).html();
	
	var newString = myString.split('[AT]')[0] + '@' + myString.split('[AT]')[1].split('[DOT]')[0] + '.' + myString.split('[AT]')[1].split('[DOT]')[1];
	
	$(this).html('<a href="mailto:' + newString + '">' + newString +'</a>');
	
});*/

/***************************************************************************************************************
	Faq selector
***************************************************************************************************************/

function setEventFaq(){
	$('#question > li a').bind('click',function(){
		$('#question > li').removeClass('selected');
		var item =$(this).parent().attr('class');
		$('#reponse > li').hide();
		 $('#reponse > li.'+item).show(); 
		$('.contntSide').jScrollPane({showArrows:true});
		$(this).parent().addClass('selected');
		if($(this).parent().height()<38){
			$(this).css("height", 19);
		}		
	});
}

function setEventMenu(){
	$('#sideBarDeco').css("overflow","hidden");
	$('#nav5 > li a').each(function(i,obj){
		$(this).bind('click',function(){
			$('#sideBarDeco .jScrollPaneContainer .scroll-pane').hide();
			$('#sideBarDeco .jScrollPaneContainer').hide();
			$('#nav5 > li').removeClass('on');
			$(this).parent().addClass('on');
			if($($('#sideBarDeco .jScrollPaneContainer .scroll-pane')[i]).length){
				$($('#sideBarDeco .jScrollPaneContainer .scroll-pane')[i]).show();
				$($('#sideBarDeco .jScrollPaneContainer')[i]).show();
				$('.scroll-pane').jScrollPane({showArrows:true});
				}
		});
	})
}
function setEventVisuels(){
	$('#visuelsLeft > ul li a').each(function(i,obj){
		//alert($(this).parent().attr('id').substring(11,12));
		var itemIndex =$(this).parent().attr('id').substring(11,12);
			
		
		$(this).bind('click',function(){
			$('#nav5 > li').removeClass('on');
			$('#nav5 ' + '.items' + itemIndex).addClass('on');
			
			$('#sideBarDeco .jScrollPaneContainer .scroll-pane').hide();
			$('#sideBarDeco .jScrollPaneContainer').hide();
			if($($('#sideBarDeco .jScrollPaneContainer .scroll-pane')[itemIndex]).length){
				$($('#sideBarDeco .jScrollPaneContainer .scroll-pane')[itemIndex]).show();
				$($('#sideBarDeco .jScrollPaneContainer')[itemIndex]).show();
			}
		});
	})
}

function showPopin() {
	if ($('#popinSingleParagraph')) {
		$('#popinSingleParagraph').fadeIn("fast");
		
		return true;
	}
	
	return false;
}

$(document).ready(function(){
	setEventFaq();
	setEventMenu();
	setEventVisuels();
	showPopin();
	$($('#question > li')[0]).addClass('selected');
	$('.scroll-pane').jScrollPane({showArrows:true});
	$('#contentF').jScrollPane({showArrows:true}); 
});
/****************
My custom add
*****************/

$('#openPopinCadeaux').click(function(){

	$('#popinCadeaux').fadeIn("fast");
	displayState();
	$(this).blur();
	return false;
});

$('#closeButtonCadeaux').click(function(){

	$('#popinCadeaux').fadeOut("normal");
	$(this).blur();
	return false;
	
});

$('#openPopinContactLearnMore').click(function(){

	$('#popinContactLearnMore').fadeIn("fast");
	$(this).blur();
	return false;
});


$('#closeButtonContactLearnMore').click(function(){

	
	$('#popinContactLearnMore').fadeOut("normal");
	$(this).blur();
	return false;
	
});

$('#closePopinSingleParagraph').click(function(){

	$('#popinSingleParagraph').fadeOut("normal");
	$(this).blur();
	return false;
	
});

function displayState() {
	var country = document.getElementById("pays").value; 
	if (country == "USA") {
		document.getElementById("state").style.display = "block";
	} else {
		document.getElementById("state").style.display = "none";
	}
}


/****************************************************************************************************************
tooltips pour IE
****************************************************************************************************************/

$('.msie6 .vsSousHome2 a').hover(function(){
	$(this).children('span').css('display','block');
	},function(){
	$(this).children('span').hide();
});


/****************************
Ajout � la selection en AJAX
*****************************/

function addToSelection(url) {

	if (xhr) {
		xhr.open("GET", url, true);
		xhr.send(null);

		xhr.onreadystatechange=function()
     	{
	        if (xhr.readyState == 4) /* 4 : �tat "complete" */
	        {
	           if (xhr.status == 200) /* 200 : code HTTP pour OK */
	           {
	              /*
	              	Traitement de la r�ponse.
	              */
	              var wishListSize = xhr.responseText;
	              
	              if (wishListSize == "1") {
	              	$('#wishList').removeClass('hidden');
	              }

	              $('#wishListSize').html(wishListSize);
	           }
	        }
     	}
	}
}

function whishList(url) {
	var finalUrl = url.replace('.htm', '/-/addToFavourite.htm')
	addToSelection(finalUrl);
}


