
var alreadydo = new Array();
var old_color ='';
var old_content = '';

$(document).ready(function(){
	
	$('.switch_image').click(function(){
		$('#box-fiche-prd-media-high li').hide();
		$('.'+$(this).attr('name')).show();
	});
	
	$('#form-tem input, #form-tem textarea').focus(function(){
		if( !alreadydo[$(this).attr('name')] ){
			$(this).val('');
		}
		alreadydo[$(this).attr('name')]=true;
		
	});
	
	$('.color-visu-img').click(function(){
		;
		$('#thumb_color_1').prev().val($(this).prev().val());
		$('#thumb_color_1').css('background-color','white');
		$('#thumb_color_1').html($(this).html());
	});
	// $('.color-visu-img').hover(function(){
		// if(old_content == '' && old_color == ''){
			// old_color = $('#thumb_color_1').css('background-color');
			// old_content = $('#thumb_color_1').html();
			
			// $('#thumb_color_1').html($(this).html());
		// }
	// });
	// $('.color-visu-img').mouseout(function(){
		// if(old_content != '' )
			// $('#thumb_color_1').html(old_content);
		// else if(old_color != ''){
			// $('#thumb_color_1').css('background-color',old_color);
			// $('#thumb_color_1').html('');
		// }
		// old_color =''; 
		// old_content ='';
			
	// });
	
	// Mise à jour du prix du produit avec les options
	$('.options-checkbox').click(function(){
		total = parseInt($('#js-prd-price').text());
		optCheckbox = $(".options-checkbox input[type='checkbox']");
		var i;
		for(i = 0; i<optCheckbox.length ; i++)
		{
			if($(optCheckbox[i]).is(':checked')) {
				total = total + parseInt($('span.js-option-price',$(optCheckbox[i]).parent()).text());
			}
		}
		$('#price-bottom .price-current').html(($('#price-bottom .price-current').html().replace(/\d+/g,total)));
	});
	
	$('.color-label input[type=radio]').change(function(){
		total = parseInt($('#js-prd-price').text());
	
		if( $(this).is(':checked') ){
			var tmp = $(this).next().html();
			
			var reg = /.*\( /g; 
			tmp = tmp.replace(reg, '');
			
			tmp = tmp.substring(0,3);
			
			total =  parseInt( tmp );
			
			$('#price-bottom .price-current').html(($('#price-bottom .price-current').html().replace(/\d+/g,total)))
		}
	});
});

var old_color = '';

/** cette fonction permet le changement de la couleur choisi
*/
function hover_select_color(hexa, id){
	old_color = $('#thumb_color_'+id).css('background-color');
	old_content = $('#thumb_color_'+id).html();
	$('#thumb_color_'+id).html('');
	$('#thumb_color_'+id).css('background-color',hexa);
}
/** cette fonction permet le changement de la couleur choisi
*/
function unhover_select_color(id){
	if( old_content != '' ) {
		$('#thumb_color_'+id).html(old_content);
		$('#thumb_color_'+id).css('background-color','white');
	}
	else if( old_color != '' ) 
		$('#thumb_color_'+id).css('background-color',old_color);
		
	old_content='';
	old_color='';
}

/** cette fonction permet le changement de la couleur choisi
*/
function select_color(hexa, id, grp_id){
	$('#thumb_color_'+grp_id).css('background-color',hexa);
	$('#thumb_color_'+grp_id).html('');
	old_content='';
	old_color='';
	$('#thumb_color_'+grp_id).prev().val(id);
}
