function long(chaine) {
	var i = 0, a = 0;

	while (chaine[i++]) {
		a++;
	}
	
	return a;
}


$(document).ready(function() {
                 $('#domtab2 ul').tabs();
                 $('#over_matieres_all').hide();
                 $("#link_perso_prod").live("click", function()
                 {
                    $('#overlay').show();
                    $('#over_matieres_all').show();
                });
                
                $('#close_overlay').live("click", function()
                {
                    $('#overlay').hide();
                    $('#over_matieres_all').hide();
                    return false;
                });
                
                var htmlStr = $('.normal_price').html();
                $('.bloc-price-2').each(function()
                    {
                        $(this).text(htmlStr);
                    });

                $('.survol_vignette').live("click", function()
                {
                        
                        rel_image = $(this).attr("rel_image");
                        rel_name = $(this).attr("rel_name");
						rel_price = $(this).attr("rel_alteration_price");
                        $('#coloris_choisi').html('<h3>Mati&egrave;re / Coloris</h3><div class="image"><img src="images/products_couleurs_values/'+rel_image+'" alt="'+rel_name+'" /></div><p>'+rel_name+'<span class="nouvelle_alteration_prix">'+rel_price+'</span></p>');
                });
				$('div#popup_informations_sur_personalisation').each(function(){
					$('div#popup_informations_sur_personalisation').die('click');
					$('div#popup_informations_sur_personalisation').live('click',function(){
						$(this).hide();
					});
					$('input#add-to-cart').live('click',function(){
						$('div#popup_informations_sur_personalisation').show();
						var fonction_return_it = function(){
							$('div#popup_informations_sur_personalisation').hide();
						};
						setTimeout(fonction_return_it,4000);
						return false;
					});
					$('a#link_perso_prod').live('click',function(){
						$('input#add-to-cart').die('click');
					});
				});
				$('div.the_good_revelator').click(function(){
					$(this).addClass('the_target');
					$(this).parent().find('div.opt-product').each(function(){ $(this).toggle(); });
					if($(this).find('span.the_revelator_status').hasClass('the_revelator_status_revelated')){
						$(this).find('span.the_revelator_status').removeClass('the_revelator_status_revelated');
					}else{
						$(this).find('span.the_revelator_status').addClass('the_revelator_status_revelated');
					}
					$('div.the_good_revelator').each(function(){
						if($(this).hasClass('the_target')){
							$(this).removeClass('the_target');
						}else{
							$(this).parent().find('div.opt-product').each(function(){ $(this).hide(); });
						}
					});
				});
				
				counter_edr = 0;
				$('div.the_good_revelator').each(function(){
					if(counter_edr !== 0){
						$(this).parent().find('div.opt-product').each(function(){ $(this).toggle(); });
						if($(this).find('span.the_revelator_status').hasClass('the_revelator_status_revelated')){
							$(this).find('span.the_revelator_status').removeClass('the_revelator_status_revelated');
						}else{
							$(this).find('span.the_revelator_status').addClass('the_revelator_status_revelated');
						}
					}
					counter_edr++;
				});
				
				$('input.my_radio_checker').live("click", function()
                {
						do_not_show_him = 0;
						master_element = $(this);
						nouvelle_alteration_prix = master_element.parent().find('span.mini_info_price').html().replace('[','').replace(']','');
						nouvelle_finition_label = master_element.parent().find('input.infos_to_show_on_click').val();
						nouvelle_finition_just_choice = master_element.parent().find('input.just_the_choice').val();
						id_tempo = $(this).parent().find('input.infos_to_show_on_click').attr('id');
                        rendu_to_show = '<h3>Options / Finitions</h3>';
						$('#finitionss_choisies').find('p').each(function(){							
							console.log(id_tempo+' === '+$(this).attr('id'));
							if($(this).attr('id') === id_tempo ){
								do_not_show_him = 1;
								rendu_to_show+="<p id='"+id_tempo+"'>"+nouvelle_finition_label+"<span class='nouvelle_alteration_prix'>"+nouvelle_alteration_prix+"</span></p>";
							}else{
								rendu_to_show+="<p id='"+$(this).attr('id')+"'>"+$(this).html()+"</p>";
							}
						});
						if(do_not_show_him === 0){							
							rendu_to_show+="<p id='"+id_tempo+"'>"+nouvelle_finition_label+"<span class='nouvelle_alteration_prix'>"+nouvelle_alteration_prix+"</span></p>";
						}
                        $('#finitionss_choisies').html(rendu_to_show);
						
						if(long(nouvelle_alteration_prix) > 0)
							nouvelle_alteration_prix = "["+nouvelle_alteration_prix+"]";
							
						$(this).parent().parent().parent().find('div.group-option-title').find('div.info').html(nouvelle_finition_just_choice+"<strong>"+nouvelle_alteration_prix+"</strong>");
                });
				
                $('#view_matieres_coloris').live("click", function()
                {
                    $('#domtab ul').tabs('select', 0); // switch to third tab
                    return false;
                });
                $('#view_finitions_options').live("click", function()
                {
                    $('#domtab ul').tabs('select', 1); // switch to third tab
                    return false;
                });
                $('#second_step').hide();
                $('#close_matieres_coloris_bloc').live("click", function()
                {
                    $('#overlay').hide();
                    $('#over_matieres_all').hide();
                    
                    $('#first_step').hide();
                    $('#second_step').show();
                    return false;
                });
                 
           	});
