


$.log = function(msg) {
	if (console && console.log) {
		console.log(msg);
	}
};

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



function razerr() {
	 $(".erreur").each(function(i){
		 document.getElementById(this.id).innerHTML="";
 	});
	$(".err_form").each(function(i){
		 $("#"+this.id).hide();
 	});
}

function showerr(id,msg) {
	document.getElementById(id).innerHTML=msg;
}

function showcache(div_cache){
	var f    = document.createElement("iframe");
	var d    = document.getElementById(div_cache);
	
	with(f.style){
		position= "absolute";
		width    = d.offsetWidth+"px";
		height= d.offsetHeight+"px";;
		top= d.offsetTop+"px";
		left= d.offsetLeft+"px";
		zIndex= "1000";
	}
	document.body.appendChild(f);
}


function gopagecible(page,cible) {
	if (cible=="" || cible=="_self") {
		document.location.href= page;
	} else {
		window.open(page);
	}
}


function checkemail(email){
	var filter=/^.+@.+\..{2,3}$/
	if (filter.test(email)) {
		return true
	} else {
	 return false
	}
}

function checkchiffres(chaine) { 
	var reg = new RegExp('[^0-9]+', 'g');
	if (reg.test(chaine)) {
		return false
	} else {
	 return true
	}
}



jQuery.extend({
	random: function(X) {
	    return Math.floor(X * (Math.random() % 1));
	},
	randomBetween: function(MinV, MaxV) {
	  return MinV + jQuery.random(MaxV - MinV + 1);
	}
});



// Lightbox Overlay
  // ------------------------------------------------------------
  
  $.fn.image_overlay = function(options) {
    
    var defaults = {
      opacity: 0.5,
      animation_speed: 500,
      class_name: 'overlay-image'
    };
    
    var options = $.extend(defaults, options);
    
    return this.each(function() {
      var img  = $(this);
      var link = $(this).parent();
      var bg   = $("<span class='"+ options.class_name +"'></span>").appendTo(link);
  		
		bg.css("opacity", 0)

  		link.bind('mouseenter', function() {
  		  var margin_top     = parseInt(img.css("margin-top"));
  		  var margin_bottom  = parseInt(img.css("margin-bottom"));
  		  var padding_left   = parseInt(img.css("padding-left"));
  		  var padding_top    = parseInt(img.css("padding-top"));
  		  var padding_right  = parseInt(img.css("padding-right"));
  		  var padding_bottom = parseInt(img.css("padding-bottom"));
  		  var border_left    = parseInt(img.css("border-left-width"));
  		  var border_top     = parseInt(img.css("border-top-width"));
  		  var border_right   = parseInt(img.css("border-right-width"));
  		  var border_bottom  = parseInt(img.css("border-bottom-width"));
  			var width    = img.width() + padding_left + padding_top + border_left + border_right;
  			var height   = img.height() + margin_top + margin_bottom + padding_top + padding_bottom + border_top + border_bottom;
  			var position = img.position();
  			bg.css({ width:width, height:height, top:position.top, left:position.left });
			
  		});

	  
	 link.hover(function(){
		img.stop().animate({ opacity: options.opacity }, options.animation_speed);
		bg.stop().animate({ opacity: options.opacity }, options.animation_speed);
	}, function() {
		img.stop().animate({ opacity: 1 }, options.animation_speed);
		bg.stop().animate({ opacity: 0 }, options.animation_speed);
	});
	  
    });
}

