function str_pad (input, pad_length, pad_string, pad_type) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // + namespaced by: Michael White (http://getsprink.com)
    // +      input by: Marco van Oort
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: str_pad('Kevin van Zonneveld', 30, '-=', 'STR_PAD_LEFT');
    // *     returns 1: '-=-=-=-=-=-Kevin van Zonneveld'
    // *     example 2: str_pad('Kevin van Zonneveld', 30, '-', 'STR_PAD_BOTH');
    // *     returns 2: '------Kevin van Zonneveld-----'

    var half = '', pad_to_go;

    var str_pad_repeater = function (s, len) {
        var collect = '', i;

        while (collect.length < len) {collect += s;}
        collect = collect.substr(0,len);

        return collect;
    };

    input += '';
    pad_string = pad_string !== undefined ? pad_string : ' ';
    
    if (pad_type != 'STR_PAD_LEFT' && pad_type != 'STR_PAD_RIGHT' && pad_type != 'STR_PAD_BOTH') { pad_type = 'STR_PAD_RIGHT'; }
    if ((pad_to_go = pad_length - input.length) > 0) {
        if (pad_type == 'STR_PAD_LEFT') { input = str_pad_repeater(pad_string, pad_to_go) + input; }
        else if (pad_type == 'STR_PAD_RIGHT') { input = input + str_pad_repeater(pad_string, pad_to_go); }
        else if (pad_type == 'STR_PAD_BOTH') {
            half = str_pad_repeater(pad_string, Math.ceil(pad_to_go/2));
            input = half + input + half;
            input = input.substr(0, pad_length);
        }
    }

    return input;
}
var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;

var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
var dsoctop=document.all? iebody.scrollTop : pageYOffset;

$(document).ready(function(){
	
	
	$('.product').hover(function(){
		$(this).css('cursor','pointer');
		$('.prd-link a', this).css('text-decoration','underline');
		$(this).click(function(){
			window.location.href = $('.prd-link a',this).attr('href');
		});
	},function(){
		$('.prd-link a', this).css('text-decoration','none');
	});
	
	// Gestion visionneuse
	$("#hc-visus ul li").each(function(i){
		$(this).attr('id','hc-visu-'+i);
	});
	
		
	nbItems = $("#hc-visus ul li").length;
	if(nbItems>1) {
		i = 0;
		for(i=0;i<nbItems;i++) {
			classStr = '';
			if(i==0)
				classStr = 'selected';
			$("#hc-buttons-go-wrapper").append('<button class="'+classStr+'" id="hc-but-go-'+i+'"></button>&nbsp;')
		}
		
		buttons = new Array();
		$("#hc-buttons-go-wrapper button").each(function(i){
			$(this).attr('id',"hc-but-go-"+i);
			buttons.push("#hc-but-go-"+i);
		});
		
		$("#hc-buttons").after('<button id="hc-but-prev"></button><button id="hc-but-next"></button>');
		
		$("#hc-visus").jCarouselLite({
			auto: 8000,
			speed: 500,
			visible: 1,
			circular:true,
			pauseOnHover:"#home-carousel",
			btnPrev: "#hc-but-prev",
			btnNext: "#hc-but-next",
			btnGo:buttons,
			beforeStart:function(a,b) {
			},
			afterEnd: function(a) {
				idNext = a.attr('id').replace(/.*(\d+)/,"$1");
				$('#hc-buttons-go-wrapper button').removeClass('selected');
				$('#hc-buttons-go-wrapper #hc-but-go-'+idNext).addClass('selected');
			}
		});
	}
	
	

	function resetPubNav(){
		$(this).css('opacity','1');
		$(this).css('display','none');
	}
	
	$('.catalogue_cat_haut').hover(
		function(){
			$('.catalogue_cat_plus a img',this).attr('src','images/btn-plus-on.gif');
		},
		function(){
			$('.catalogue_cat_plus a img',this).attr('src','images/btn-plus-off.gif');
		}
	);
	elementInNewsletterEmailDefault = 'Votre e-mail';
	elementInNewsletterEmail = $('#in-newsletter');
	elementInNewsletterEmail.each(function(){
		$(this).focus(function() {
			if($(this).val()== elementInNewsletterEmailDefault)
				$(this).val('');
		}).blur(function() {
			if ($(this).val() == '') {
				$(this).val(elementInNewsletterEmailDefault);
			}
		});
	});
	
	$('#newsletter-footer').submit(function(){
		if(validEmail($('#in-newsletter',this).val()))
			return true;
		else {
			alert('Veuillez indiquer un email valide.');
			return false;
		}
	});
	
	$('#temoignages-body').cycle({ 
		fx:     'fade', 
		speed:  1000, 
		timeout: 5000,
		cleartype: true, 
		cleartypeNoBg: true
	});	
	
	$('#temoignages-body .temoignage-body').hover(
		function(){
			$(this).css('cursor','pointer');
			$(this).find('.lnk-more').css('text-decoration','underline');
			
			$(this).click(function(){
				window.location.href = $(this).find('.lnk-more').attr('href');
			});
		}, function(){
			$(this).find('.lnk-more').css('text-decoration','none');
	});
			
	
	if(!$.browser.msie) {
		$('#home-carousel').hover(function() {
			var fade = $('#hc-but-prev',this);
			var fades = $('#hc-but-prev,#hc-but-next',this);
			// if the element is currently being animated (to fadeOut)...
			if (fade.is(':animated')) {
				// ...stop the current animation, and fade it to 1 from current position
				fades.stop().fadeTo(500, 1);
			} else {
				fades.fadeIn(500);
			}
			
		}, function () {
			var fade = $('#hc-but-prev',this);
			var fades = $('#hc-but-prev,#hc-but-next',this);
			if (fade.is(':animated')) {
				fades.stop().fadeTo(500, 0, resetPubNav);
			} else {
				fades.fadeOut(500, resetPubNav);
			}
		});
	}
	
	if($.browser.msie && $.browser.version.substr(0,1)<7) {
		$(window).scroll(function() {
			dsocleft = document.all? iebody.scrollLeft : pageXOffset;
			dsoctop = document.all? iebody.scrollTop : pageYOffset;
			$('#zoom').css('top',dsoctop);
		});
	}

});

var mouseX = mouseY = 0;

$(document).mousemove(function(e){
	mouseX = e.pageX; 
	mouseY = e.pageY;
   }); 
