//dimScreen()
//by Brandon Goldman
jQuery.extend(
{
    	//dims the screen
    	dimScreenproduit: function(speed, opacity, callback,w, h,couleur) 
	{
		var win_width =$(window).width();
	    	var win_height =$(window).height();
		var wleft =((win_width/2 )-(w/2));
		var wtop  =((win_height/2)-(h/2));
		if(jQuery('#__dimScreenproduit').size() > 0) 
			return;
        	if(typeof speed == 'function')
		{
            		callback = speed;
            		speed = null;
        	}
        	if(typeof opacity == 'function') 
		{
            		callback = opacity;
            		opacity = null;
        	}
        	if(speed < 1) 
		{
            		var placeholder = opacity;
            		opacity = speed;
            		speed = placeholder;
        	}
        	if(opacity >= 1) 
		{
            		var placeholder = speed;
            		speed = opacity;
            		opacity = placeholder;
        	}
        	speed = (speed > 0) ? speed : 500;
        	opacity = (opacity > 0) ? opacity : 0.1;
		
		jQuery('<div></div>').attr( {id: '__dimScreenfondproduit',fade_opacity: opacity,speed: speed})
		.css({background: '#000000',top: 0,left: 0,height: win_height,width: win_width, opacity: 0.1,position: 'absolute',zIndex: 100})
		.appendTo(document.body).fadeTo(speed, 0.5, callback);
		
		return jQuery('<div></div>').attr( {id: '__dimScreenproduit',fade_opacity: opacity,speed: speed})
		.css({background: couleur,top: wtop,left: wleft,height: h,width: w,opacity: 0,position: 'absolute',zIndex: 110})
		.appendTo(document.body).fadeTo(speed, 0.5, callback)
		;
	},	// fin de la fonction dimscreen2
	
    	//stops current dimming of the screen
    	dimScreenStopproduit: function(callback) 
	{
        	var x = jQuery('#__dimScreenproduit');
		var x2 = jQuery('#__dimScreenfondproduit');
        	var opacity = x.attr('fade_opacity');
        	var speed = x.attr('speed');
        	x.fadeOut(speed, function() 
		{
            		x.remove();
			x2.remove();
            		if(typeof callback == 'function') 
				callback();
        	});
    	}
}

);

