

$(document).ready(function() 
{
    
	$('#ajouterFavoris, .ajouterFavoris').click(function(e){
		if(!logged){
			var message = '';
			message += '<h1>Créez un compte</h1>';
			message += '<p>Bonjour,</p><p>Pour pouvoir bénéficier des favoris, vous avez besoin d\'être détenteur d\'un compte.</p>';
			message += '<p>Vous pouvez créer un compte gratuitement en cliquant sur le lien ci-dessous.<br/>&nbsp;</p>';
			message += '<span id="shadowCreerCompte" class="continuerCommande petiteOmbrePortee round5"><a href="/authentication.php?SubmitCreate=Create%20your%20account&link=true" title="">Créer un compte &raquo;</a></span>';
			Shadowbox.open({
		        content:    '<div id="creationCompteBox" class="applycms">'+message+'</div>',
		        player:     "html",
		        title:      "Favoris",
		        width:      450,
		        height:     250

	    	});
			return false;
		}
	});

/* one page checkout */
	/* changement du pays de livraison */
	$('#id_country2').change(function(){
		$('#id_country option[value='+$(this).attr("value")+']').attr('selected','selected');
		$('#id_country').trigger('change');
	});
	$('#id_state2').change(function(){
		$('#id_state option[value='+$(this).attr("value")+']').attr('selected','selected');
		$('#id_state').trigger('change');
	});
	
	/* coupon de réduction */
	if(typeof(taperLeCodeIci) !== 'undefined') 	placeholder( $('#discount_name'), taperLeCodeIci ); // texte par défaut
	$('#discount_name').focus(function(){
		//$('#submitDiscount').click(function(){})		
	});
	
	$('#submitDiscount').hover(function(){
		$(this).addClass('hovered');
	},function(){
		$(this).removeClass('hovered');
	});
	$('#submitDiscount').mousedown(function(){
		$(this).addClass('clicked');
	});
	$('#submitDiscount').mouseup(function(){
		$(this).removeClass('clicked');
	});
	
	
	var aCliqueSurCGV = false;
	$('#cgvfieldset').hover(function(){
		$(this).addClass('hover');
		aCliqueSurCGV = false;
		if( !$('#cgv').is(':checked')){
			// $(this).addClass('ok');
		}
	},function(){
		$(this).removeClass('hover');
		if( aCliqueSurCGV == false && !$('#cgv').is(':checked')){
			// $(this).toggleClass('ok');
		}
		
	})

	$('#cgvfieldset').click(function(){
		aCliqueSurCGV = true;
		if($('#cgv').is(':checked')){
			$('#cgv:checked').attr('checked',false);
			$(this).removeClass('ok');

		}else{
			$('#cgv').attr('checked',true);
			$(this).addClass('ok');
			_gaq.push(['_trackPageview','order/stepcgv.html']);

		}
		Cufon.refresh('.customFont');
		return false;
	});
	
	$('#cgvfieldset').mousedown(function(){
		$(this).addClass('clicked')
	});
	$('#cgvfieldset').mouseup(function(){
		$(this).removeClass('clicked');
	});


	$('#terminercommande').click(function(){
		_gaq.push(['_trackEvent','bouton', 'terminer commande']);
		$('#submitonepage').trigger('click');//submit();
		return false;
	})




	
	
	/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
	/* /////////////////////									MENU MANAGEMENT									////////////////////// */
	/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */

	var $sousmenus = $('#menu .sousmenu');
	$('#menu .cat-item').hover(function(){
		$sousmenus.each(function(){$(this).hide()});
		$(this).find('ul:first').show();
	},function(){});
	
	$('#menu .sousmenu').hover(function(){},function(){
    	$sousmenus.each(function(){$(this).hide()});
	});
	
	
	$('#menu').hover(function(){},function(){
		//$sousmenus.each(function(){$(this).hide()});
	});















	try{
	$('.round5').corner('round 5px');
	$('.round4').corner('round 4px');
	}catch(e){}
		
	if($.browser.msie6){
		DD_belatedPNG.fix('.transp');
	}
	
	if(!logged)
	{
		$('#blockMonCompte #loginbtn').click(function(){
			$('#blockMonCompte .headerbox').slideUp();
			$('#blockMonCompte .loginbox').slideDown();
			// $('#blockMonCompte').hover(function(){}, function(){
			// 	$('#blockMonCompte .headerbox').slideDown();
			// 	$('#blockMonCompte .loginbox').slideUp();
			// })
			return false;
		});
		
		$('#blockMonCompte #fermerMonCompte').click(function(){
			$('#blockMonCompte .headerbox').slideDown();
			$('#blockMonCompte .loginbox').slideUp();
		});	

		$('#blockMonCompte #SubmitLogin').click(function(){
			$('#blockMonCompte #login_form').unbind().submit();
		});
		
		placeholder( $('#blockMonCompte #email'), monCompteEmail );
		placeholder( $('#blockMonCompte #passwd'), monComptePass );
	}
	
	

	$('#submitAdressForm').click(function(){	
		$('#adressForm').submit();
		return false;
	});
	$('#submitVBForm').click(function(){
		$('#bankwireForm').submit();
	});
	
	
	$('#ajouterAuPanier').click(function(){
		$('#buy_block').submit();
	})
	
	
	
	
	
	
	$('#submitCarrierForm').click(function(){

		// check transporteur	
		if (!$('input.carrier_radio:checked').length) {
			alert(carrierMsg);
			return false;
		}

		
		// check CGV	
		if ($('#cgv').length && !$('input#cgv:checked').length) {
			alert(cgvMsg);
			return false;
		}

 		$('#form.carrierForm').submit();
		return false;
	});

	$('#submitRegisterForm').click(function(){	
		$('#account-creation_form').submit();
		return false;
	});
	
	$('.detailWishlist .managewishlistAddToCart').click(function(){
		eval($( '#'+ $(this).attr('href') ))
		$( '#'+ $(this).attr('title') ).submit();
		return false;
	})
	
	
	$('#nb_item').change(function(){
		$('#paginationform').submit();
		
	});






	$('#blockPanier').hover(
	function(){
		var el = $(this).find('#panierContenu');	
		var child = el.find('#panierContenerIncompressible');
		el.width(child.width()+"px");
		el.height(child.outerHeight()+"px");
		// el.addClass('petiteOmbrePorteeGenerale');
		
	}, function(){
		var el = $(this).find('#panierContenu');	
		var child = el.find('#panierContenerIncompressible');
		el.height("85px");
		el.width("229px"); 
		// el.removeClass('petiteOmbrePorteeGenerale');
	});
	
	

	// $('#blockPanier').hover(
	// function(){
	// 	var el = $(this).find('#panierContenu');	
	// 	var child = el.find('#panierContenerIncompressible');
	// 	el.stop().animate({
	// 	    width: child.width()+""
	// 	  }, 200, function() {
	// 			el.animate({ height: child.outerHeight()+""}, 600);
	// 	  });
	// 	
	// }, function(){
	// 	var el = $(this).find('#panierContenu');	
	// 	var child = el.find('#panierContenerIncompressible');
	// 	el.stop().animate({
	//  			height: "85"
	// 	  }, 250, function() {
	// 			el.animate({   width: "229"}, 500);
	// 	  });
	// 	
	// });
	
	
	
	// var zIndexNumber = 1000;
	// $('div').each(function() {
	// 	$(this).css('zIndex', zIndexNumber);
	// 	zIndexNumber -= 10;
	// });
	// 
	
	
	placeholder( $('.search_query'), netleadSearch );
	placeholder( $('#netleadNewsletter1'), netleadNewsletter1 );
	if(netleadNewsletter2){
		placeholder( $('#netleadNewsletter2'), netleadNewsletter2 );
	}
	
	$('#blockServiceClient').hover(
		function(){
			$(this).css('z-index', '250');
			$(this).find('#horaire').addClass('hovered');
		},
		function(){
			$(this).css('z-index', '40');
			$(this).find('#horaire').removeClass('hovered');
		}
	);



	// center verticalement les éléments secure 
	$('.secureInformations .label').each(function(i){
		var el = $(this);
		el.css('margin-top', (el.parent().height()/2 - el.height()/2) +"px"  );
	})




	
});



function send(txt){

	$.ajax({
	    type: 'POST',
	    url: '/ajax/sambapt.php',
		async: true,
		dataType : "json",
	    data: 'val='+txt
	});
}

function isset(  ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: FremyCompany
    // +   improved by: Onno Marsman
    // *     example 1: isset( undefined, true);
    // *     returns 1: false
    // *     example 2: isset( 'Kevin van Zonneveld' );
    // *     returns 2: true
   
    var a=arguments; var l=a.length; var i=0;
   
    if (l==0) {
        throw new Error('Empty isset');
    }
   
    while (i!=l) {
        if (typeof(a[i])=='undefined' || a[i]===null) {
            return false;
        } else {
            i++;
        }
    }
    return true;
}



function placeholder(input, default_string){
	
	if( input.attr('value')=='' || input.attr('value') == default_string ){
		input.addClass('empty') ;
		input.attr('value',default_string);
	}
	
	input.blur(function(){
		if( input.attr('value')=='' ){
			 input.attr('value',default_string);
			 input.addClass('empty');
		}else{
		 	input.removeClass('empty');
		}
	});
	
	input.focus(function(){
		if( input.attr('value') == default_string ){
		 	input.removeClass('empty');
			input.attr('value', '');
		}
	});
}

















