// JavaScript Document

/*** gestion des hovers sur boutons ***/
function rolloverImage() {
	
	$('.hover').mouseover(function() {
		var source = jQuery(this).attr("src").length;
		var ext = jQuery(this).attr("src").substring(source - 4, source);
        var newsource = jQuery(this).attr("src").substring(0, source - 4) + "_ON" + ext;
       
		
		if ( jQuery(this).attr("src").substr(source-7,source) != "_ON"+ext ) {
      	  jQuery(this).attr("src", newsource);
		}
	});
	$('.hover').mouseout(function() {
		var source = jQuery(this).attr("src").length;
		var ext = jQuery(this).attr("src").substring(source - 4, source);
        var newsource = jQuery(this).attr("src").substring(0, source - 7) + ext;
      	if ( jQuery(this).attr("src").substr(source-7,source) == "_ON"+ext ) {
      	  jQuery(this).attr("src", newsource);
		}
	});
	
}

function showHideDiv(divid) {
	//var fond = $('#bg_popup');
	$('#'+divid).toggle();
}

function showTotalHorsTaxe(){
	$(".tooltip_affiche_HT img, .tooltip_print_HT a").mouseover(function(){
		$(this).next().addClass("tooltip_hover").fadeIn(100);
	});
	$(".tooltip_affiche_HT img, .tooltip_print_HT a").mouseout(function(){
		if ($(this).next().hasClass("tooltip_hover")) {
			$(this).next().removeClass("tooltip_hover").fadeOut(100);
		}
	});
	
	$(".soustotal_HT img").click(function(){
		$("tr.total_HT, .total_HT").show();
		$(".soustotal_HT").removeClass("HT_off");
		$(".total_art:first").html("Total des articles (TTC) :");
		$(".total:first").html("Total de mon panier (TTC) :");
	});	
	
	$(".tooltip_print_HT img").click(function(){
		$("#panier th:first").prepend("<img src='/img/background/bg_th_panier.gif' alt='' class='bg_panier' />");
		window.print();
		return false;
	});	
	
}

function zoomListe() {

	if ( $(".produit-liste").size != 0 ) {
		
		$(".produit-liste").live('mouseenter', function(){
			elem = $(this);
			listeHover( $(this) );
		});
		
		function listeHover(elem){
			$(".zoom_liste strong").text();
			$(".zoom_liste strong").text( elem.find(".descriptif a").text() );
		
			$(".zoom_liste a").attr('href',elem.find('.descriptif a').attr('href'));
			
			var url_image = elem.find("img").attr("src");
			var new_url_img = url_image.substring(0,url_image.length - 9);
			$(".zoom_liste .zoom_liste_image img").attr('alt',elem.find(".descriptif a").text());
						
			var request;
			request = $.ajax({
				type: "HEAD",
				url: new_url_img+'_pdt.jpg',
				success: function () {
					$(".zoom_liste .zoom_liste_image img").attr('src', new_url_img+'_pdt.jpg');
				},
				error: function () {
					$(".zoom_liste .zoom_liste_image img").attr('src','/img/000_zoom_pdt.jpg');
				}
			});
		}
	}
}


// Exemple formulaire
	(function($) {
		//Définition du plugin
   		$.fn.form_exemple = function(userExemple, userGetSpanExemple) {   
       
        	// définition des paramètres par défaut
			var defaults = {
				exemple: "",
				getSpanExemple: false
			};  
			var options = {
				exemple: userExemple,
				getSpanExemple: userGetSpanExemple
			};  

        	var opts = $.extend(defaults, options);
			
			function set_exemple() {
				
				if (opts.getSpanExemple) {
					opts.exemple = $(this).next().text();
					$(this).next().remove();
				}
				
				if ($(this).val() == "" ) {
					$(this).val(opts.exemple);
				}
				
				$(this).bind('focus', function(){
					if ( $(this).val() == opts.exemple ) {
						$(this).val('');
					}
				});
				
					$(this).bind('blur', function(){
						if ( $(this).val() == "" ) {
							$(this).val(opts.exemple);
						}
					});
			}
			$(this).each(set_exemple);   

			// interface fluide
			 return $(this);
    	};   
	})(jQuery);
