function delete_from_cart(ref_id,key,ver_id,slide) {
	$.ajax({
		type: "POST",
		url: "_template/ajax/remove_from_cart.php",
		data: "ref_id="+ref_id+"&key="+key+"&ver_id="+ver_id,
		success: function(msg){
			tab_msg = msg.split('|');
			if(tab_msg[0] === 'ok') {
				if(slide == 1) {
					$('#ref_id'+ref_id).animate({height:0, opacity: 0},500,'linear',function(){$('#ref_id'+ref_id).remove();});
				} else {
					$('#ref_id'+ref_id).animate({
						width: 0,
						height: 0,
						marginTop: "32px",
						marginLeft: "97px",
						opacity: 0
					},500,'linear',function(){$('#ref_id'+ref_id).remove();});
				}
				$('#cart_price').html(tab_msg[1]+' €');
			}
		}
	});
}

function add_to_cart(ref_id,ver_id) {
	if($('#finger_'+ref_id).val() != undefined && $('#finger_'+ref_id).val() === 'Taille')
		$('#finger_'+ref_id).parent().parent().find('.choose-opt').slideDown("slow");
	else if($('#opt_id_select'+ref_id).val() != undefined && $('#opt_id_select'+ref_id).val() === "Metal")
		$('#opt_id_select'+ref_id).parent().parent().find('.choose-opt').slideDown("slow");
	else {
		$('#opt_id_select'+ref_id).parent().parent().find('.choose-opt').slideUp("slow");
		$('#finger_'+ref_id).parent().parent().find('.choose-opt').slideUp("slow");
		$.ajax({
			type: "POST",
			url: "_template/ajax/add_to_cart.php",
			data: "ref_id="+ref_id+"&ver_id="+ver_id+"&opt_id="+$('#opt_id_select'+ref_id).val()+"&finger="+$('#finger_'+ref_id).val(),
			success: function(msg){
				var html = '<div style="position:absolute;z-index:950;" class="item-2-cart-temp">';
				html += '<img src="'+$('#product_ref_id'+ref_id+' img').attr('src')+'" />';
				html += '<strong>1 x '+$('#product_ref_id'+ref_id+' .price').html()+'</strong>';
				html += '</div>';
				$('#product_ref_id'+ref_id).prepend(html);
				
				var margleft = '450px';
				if($('#product_ref_id'+ref_id).hasClass('ref-1')) {
					margleft = '730px';
				} else if($('#product_ref_id'+ref_id).hasClass('ref-2')) {
					margleft = '530px';
				} else if($('#product_ref_id'+ref_id).hasClass('ref-3')) {
					margleft = '280px';
				}
				
				$('#product_ref_id'+ref_id+' div:first').animate({
					left: margleft,
					top: '-250px',
					opacity: '0'
					},1000,'',function() {
						$.ajax({
							type: "POST",
							url: "_template/commerce/mini-panier.php",
							success: function(msg){
								$('#shopping-cart').html(msg);
							}
						});
						$(this).remove();
					}
				);
				
			}
		});
	}
}

function add_to_new_cart(ver_id) {
	if($("input:radio[name='rbc']").val() != undefined && $("input:radio[name='rbc']:checked").val() == undefined)
		$('.choose-opt').slideDown("slow");
	else if($('.select-taille').val() != undefined && $('.select-taille').val() === 'Taille')
		$('.choose-opt').slideDown("slow");
	else {
		$('.choose-opt').slideUp("slow");
		ref_id = $('input:radio[name="choose-ref"]:checked').val().substring(3);
		var html = '<img style="position:absolute;z-index:950;width:150px;height:150px;" class="item-2-cart-temp" src="'+$('.zoom-v2').attr('src')+'" />';
		$('.photo-v2').prepend(html);
		
		$('.item-2-cart-temp').animate({
			left: '700px',
			width: '87px',
			height: '87px',
			opacity: '0'
			},1000,'',function() {
				$(this).remove();
			}
		);
		$.ajax({
			type: "POST",
			url: "_template/ajax/add_to_cart.php",
			data: "ref_id="+ref_id+"&ver_id="+ver_id+"&opt_id="+$("input:radio[name='rbc']:checked").val()+"&finger="+$('.select-taille').val(),
			success: function(msg){
				$.ajax({
					type: "POST",
					url: "_template/commerce/mini-panier.php",
					success: function(msg){
						if($('#shopping-cart').length > 0)
							$('#shopping-cart').html(msg);
						else
							$('#marketing-block').before('<div id="shopping-cart">'+msg+'</div>');
					}
				});
			}
		});
	}
}

function add_to_new_new_cart(ref_id,ver_id) {
	if($(".div_ref"+ref_id+" input:radio[name='rbc']").val() != undefined && $(".div_ref"+ref_id+" input:radio[name='rbc']:checked").val() == undefined)
		$('#choose-opt'+ref_id).slideDown("slow");
	else if($('#finger_'+ref_id).val() != undefined && $('#finger_'+ref_id).val() === 'Taille')
		$('#choose-opt'+ref_id).slideDown("slow");
	else {
		$('#choose-opt'+ref_id).slideUp("slow");
		var html = '<img style="position:absolute;z-index:950;width:150px;height:150px;" class="item-2-cart-temp" src="'+$('.zoom-v2').attr('src')+'" />';
		
		if($('.chk_grave').is(':checked')) {
			var d = "&opi_custom="+$('.txt_grave').val();
		} else {
			var d = '';
		}
		$('.photo-v2').prepend(html);
		
		$('.item-2-cart-temp').animate({
			left: '700px',
			width: '87px',
			height: '87px',
			opacity: '0'
			},1000,'',function() {
				$(this).remove();
			}
		);
		$.ajax({
			type: "POST",
			url: "_template/ajax/add_to_cart.php",
			data: "ref_id="+ref_id+"&ver_id="+ver_id+"&opt_id="+$(".div_ref"+ref_id+" input:radio[name='rbc']:checked").val()+"&finger="+$('#finger_'+ref_id).val()+d,
			success: function(msg){
				$.ajax({
					type: "POST",
					url: "_template/commerce/mini-panier.php",
					success: function(msg){
						if($('#shopping-cart').length > 0)
							$('#shopping-cart').html(msg);
						else
							$('#marketing-block').before('<div id="shopping-cart">'+msg+'</div>');
					}
				});
			}
		});
	}
}

function show_this_one(ref_id,certificat,pass,price,gamme) {
	if(!$('.rb'+ref_id).is(':checked')) {
		pass = '4';
	}
	
	if(pass === '4') {
		$('.od-ref').css('border-color','#1A2231');
		$('.div_ref'+ref_id).css('border-color','#FFCC67');
		$('.rb'+ref_id).attr('checked','checked');
		$('.certificat').hide();
		if(certificat != '')
			$('#'+certificat).show();
		$('.od-ref').animate({
			height: '87px'
		},{ queue:false, duration:500 });
		$('.div_ref'+ref_id).animate({
			height: '367px'
		},{ queue:false, duration:500 });
		$('.current-ref').removeClass('current-ref');
		$('.div_ref'+ref_id).addClass('current-ref');
		
	}
}

$(function() {
	$('.od-ref').mouseover(function() {
		if($(this).hasClass('current-ref'))
			$(this).css('border-color','#FFCC67');
		else
			$(this).css('border-color','#A6B5CC');
	}).live('mouseout',function() {
		if($(this).hasClass('current-ref'))
			$(this).css('border-color','#FFCC67');
		else
			$(this).css('border-color','#1A2231');
	});
	
	$('input[name="rbc"]').change(function() {
		if($(this).hasClass('opt-v2-1')) {
			$('.opt-v2-1').attr('checked','checked');
		}
		else if($(this).hasClass('opt-v2-2')) {
			$('.opt-v2-2').attr('checked','checked');
		}
		else if($(this).hasClass('opt-v2-3')) {
			$('.opt-v2-3').attr('checked','checked');
		}
	});
	
	$('.select-taille').change(function() {
		$('.select-taille').val($(this).val());
	});
	
	$('.txt_grave').keypress(function(e) {
		if(e.which < 65 || e.which > 90) {
			$(this).val($(this).val().replace(/[^-a-zA-Z0-9' ]/g,''));
		}
	}).keyup(function(e) {
		if(e.which < 65 || e.which > 90) {
			$(this).val($(this).val().replace(/[^-a-zA-Z0-9' ]/g,''));
		}
	}).blur(function() {
		$(this).val($(this).val().replace(/[^-a-zA-Z0-9' ]/g,''));
	});
});