/**
 * JQUERY IMAGE OMBRE PLUGIN v1.0 :
 * Plugin jQuery d'ombrage d'images.
 * @author Altitude Création
 */

var border_width=1;

var flag_ombre = 0;
  
$(window).resize(function(){		
		$(".ombre").remove();		
});
var extension_img = "";
(function($) {		  
		
		// On teste si le navigateur est IE6 auquel cas on charge des jpg
		var IE6 = $.browser.msie && $.browser.version=="6.0";
		if(IE6){
			extension_img = ".jpg";
		}
		else extension_img = ".png";
		
		//Config
		
		var path_img="includes/js/jquery_img_ombre/img/";
		
		//Preload des images
		var tab_img= new Array("ombre_img_up_left"+extension_img,"ombre_img_up_right"+extension_img,"ombre_img_up_center"+extension_img,"ombre_img_left"+extension_img,"ombre_img_down"+extension_img,"ombre_img_right"+extension_img,"ombre_img_down_left"+extension_img,"ombre_img_down_right"+extension_img);
		var preload_img=new Image();
	
		for(i in tab_img)
		{
			// document.write(tab_img[i]);
		    preload_img.src=path_img+tab_img[i];
		  	document.write("<img style='width:0px;' src='"+path_img+tab_img[i]+"'>");
		}
		
		
		$.fn.imageombre = function(){
			
			if(flag_ombre<=0)
			{				
				var element = this;	
				$(window).resize(function(){
					flag_ombre = 1;
					//alert("dedans");
					$(element).imageombre();
					
				});
			}
			
			this.each(function() {	
				
				// var border = parseInt($(this).css("border").substring(0,1));				
				var decal = 15 ; // Modifier ceci pour ajuster selon taille de l'ombre
				var offset = $(this).offset();				
				var top = offset.top - decal; // offset.top -val ou val correspond au redecalage du top de la classe zoom
				var left = offset.left - decal; // offset.top -val ou val correspond au redecalage du margin-left de la classe zoom
				var height = $(this).height(); // height de l'image en cours
				var width = $(this).width(); // width de l'image en cours				
				
				// On place des div avant que les elements de classe .zoom ne soient placées dans le code
				$(this).before("<div class='ombre' style='background:url("+path_img+"ombre_img_up_left"+extension_img+") no-repeat left top;width:30px;height:30px;position:absolute;z-index:1;border:none;left:"+ left +"px;top:"+ top +"px;'></div>"
								+ "<div class='ombre' style='background:url("+path_img+"ombre_img_up_right"+extension_img+") no-repeat right top;width:30px;height:30px;margin-left:" + $(this).width() + "px;position:absolute;z-index:1;left:"+ (left+border_width)+"px;top:"+ top +"px;'></div>"
								+ "<div class='ombre' style='background:url("+path_img+"ombre_img_up_center"+extension_img+") repeat-x top;height:15px;width:" + ($(this).width()-(decal*2)+border_width) + "px;margin-left:15px;position:absolute;z-index:0;left:"+ (left+decal) +"px;top:"+ top +"px;'></div>"
								+ "<div class='ombre' style='background:url("+path_img+"ombre_img_left"+extension_img+") repeat-y left;width:15px;height:"+($(this).height()-(decal*2)+border_width)+"px;position:absolute;z-index:0;margin-top:15px;left:"+ left +"px;top:"+ (top+decal) +"px;'></div>"
								+ "<div class='ombre' style='background:url("+path_img+"ombre_img_down"+extension_img+") repeat-x top;height:16px;width:" + ($(this).width()-(decal*2)+border_width) + "px;position:absolute;z-index:0;margin-top:" + ($(this).height()+decal) + "px;margin-left:15px;left:"+ (left+decal) +"px;top:"+ (top+border_width) +"px;'></div>"
								+ "<div class='ombre' style='background:url("+path_img+"ombre_img_right"+extension_img+") repeat-y left;height:"+($(this).height()-(decal*2)+border_width)+"px;width:16px;position:absolute;z-index:0;margin-left:" + ($(this).width()+ decal) +"px;margin-top:15px;left:"+ (left+border_width) +"px;top:"+ (top +decal) +"px;'></div>"
								+ "<div class='ombre' style='background:url("+path_img+"ombre_img_down_left"+extension_img+") no-repeat left bottom;width:30px;height:30px;float:left;;margin-top:" + $(this).height() + "px;margin-right:-50px;position:absolute;z-index:1;left:"+ (left) +"px;top:"+ (top+border_width) +"px;'></div>"
								+ "<div class='ombre' style='background:url("+path_img+"ombre_img_down_right"+extension_img+") no-repeat right bottom;width:30px;height:30px;float:left;margin-left:" + $(this).width() +"px;margin-top:" + ($(this).height()+border_width) + "px;position:absolute;z-index:1;left:"+ (left+border_width) +"px;top:"+ top +"px;'></div>");

			});
		
};
	

})(jQuery);
