// fonction de customisation des checkbox/radio
/*-------------------------------------------------------------------- 
 * jQuery plugin: customInput()
 * by Maggie Wachs and Scott Jehl, http://www.filamentgroup.com
 * Copyright (c) 2009 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 * Article: http://www.filamentgroup.com/lab/accessible_custom_designed_checkbox_radio_button_inputs_styled_css_jquery/  
 * Usage example below (see comment "Run the script...").
--------------------------------------------------------------------*/
// fonction daffichage pour visu produit (fiche produit)
var old_Produit = "";
function showProduit(elem) {
 
    document.getElementById(elem).style.display = "block";
    if (old_Produit != "" && old_Produit != undefined) {
        document.getElementById(old_Produit).style.display = "none";
        
    }

    if (old_Produit == elem) {
        document.getElementById(old_Produit).style.display = "block";
      
    }

    old_Produit = elem;
}
var old_ProduitArticleAssocie = "";
function showProduitArticleAssocie(elem) {
    document.getElementById(elem).style.display = "block";
    if (old_ProduitArticleAssocie != "" && old_ProduitArticleAssocie != undefined) {
        document.getElementById(old_ProduitArticleAssocie).style.display = "none";
    }

    if (old_ProduitArticleAssocie == elem) {
        document.getElementById(old_ProduitArticleAssocie).style.display = "block";
    }

    old_ProduitArticleAssocie = elem;
}
jQuery.fn.customInput = function(){
	jQuery(this).each(function(i){	
		if(jQuery(this).is('[type=checkbox],[type=radio]')){
			var input = jQuery(this);
			
			// get the associated label using the input's id
			var label = jQuery('label[for='+input.attr('id')+']');
			
			//get type, for classname suffix 
			var inputType = (input.is('[type=checkbox]')) ? 'checkbox' : 'radio';
			
			// wrap the input + label in a div 
			jQuery('<div class="custom-'+ inputType +'"></div>').insertBefore(input).append(input, label);
			
			// find all inputs in this set using the shared name attribute
			var allInputs = jQuery('input[name='+input.attr('name')+']');
			
			// necessary for browsers that don't support the :hover pseudo class on labels
			label.hover(
				function(){ 
					jQuery(this).addClass('hover'); 
					if(inputType == 'checkbox' && input.is(':checked')){ 
						jQuery(this).addClass('checkedHover'); 
					} 
				},
				function(){ jQuery(this).removeClass('hover checkedHover'); }
			);
			
			//bind custom event, trigger it, bind click,focus,blur events					
			input.bind('updateState', function(){	
				if (input.is(':checked')) {
					if (input.is(':radio')) {				
						allInputs.each(function(){
							jQuery('label[for='+jQuery(this).attr('id')+']').removeClass('checked');
						});		
					};
					label.addClass('checked');
				}
				else { label.removeClass('checked checkedHover checkedFocus'); }
										
			})
			.trigger('updateState')
			.click(function(){ 
				jQuery(this).trigger('updateState'); 
			})
			.focus(function(){ 
				label.addClass('focus'); 
				if(inputType == 'checkbox' && input.is(':checked')){ 
					jQuery(this).addClass('checkedFocus'); 
				} 
			})
			.blur(function(){ label.removeClass('focus checkedFocus'); });
		}
	});
};

/*--------------------------------------------------------------------*/
// fonction daffichage du verso dun produit (page descente)
function showVerso(elem) {

    
    if (document.getElementById(elem).style.display == "block") {
        document.getElementById(elem).style.display = "none";
        document.getElementById(elem + '_verso').style.display = "block";
    }
    else {
        document.getElementById(elem).style.display = "block";
        document.getElementById(elem + '_verso').style.display = "none";
    }
}

/*--------------------------------------------------------------------*/
function clickScroll() {
    var target = $(this.hash);
    var hash = this.hash;
    if (target.length) {
        var targetOffset = target.offset().top - 0;
        $('html,body').animate({scrollTop: targetOffset}, 600);
        return false;
    }
}

/*--------------------------------------------------------------------*/
$(document).ready(function() {
    $('.previous').click(clickScroll);
    $('.next').click(clickScroll);
}); 

/*--------------------------------------------------------------------*/
// gestion des layer header
function layerHeaderComp(elem) {
	// commande
	$("li.suivi_commande").bind("mouseenter",function(){
		$("div.sous_menu_suivi_commande").css("display","block");
     }).bind("mouseleave",function(){
    	$("div.sous_menu_suivi_commande").css("display","none");
    });
	
	$("li.suivi_commande").find("span.error").each(function(){
		if ($(this).css('display') != 'none') {
			$("div.sous_menu_suivi_commande").show();
		}
	});
	
	// compte
	/*$("li.mon_compte").bind("mouseenter",function(){
		$("div.sous_menu_compte").css("display","block");
     }).bind("mouseleave",function(){
    	$("div.sous_menu_compte").css("display","none");
    });
    */
	
	$("li.mon_compte").find("span.error").each(function(){
		if ($(this).css('display') != 'none') {
			$("div.sous_menu_compte").show();
		}
	});
	
	// panier
	$("li.mon_panier").bind("mouseenter",function(){
		$("div.sous_menu_panier").css("display","block");
     }).bind("mouseleave",function(){
    	$("div.sous_menu_panier").css("display","none");
    });
	
	$("li.mon_panier").find("span.error").each(function(){
		if ($(this).css('display') != 'none') {
			$("div.sous_menu_panier").show();
		}
	});
}

function OpenLayerAccount() {
    $("div.sous_menu_compte").css("display", "block");
}

function CloseLayerAccount() {
    $("div.sous_menu_compte").css("display", "none");
}
