//dimScreen()
//by Brandon Goldman
jQuery.extend(
{
    	//dims the screen
    	dimScreen2: function(speed, opacity, callback,w, h,couleur,produit) 
	{
		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('#__dimScreen').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;
		if(produit == 0)
		{
			//alert("Produit :"+produit);
			return jQuery('<div></div>').attr( {id: '__dimScreenfond',fade_opacity: opacity,speed: speed})
			.css({background: '#0AA000',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);
		}
		if( produit == 1)
		{
			//alert("Produit :"+produit);
			return jQuery('<div></div>').attr( {id: '__dimScreenfond2',fade_opacity: opacity,speed: speed})
			//.css({background: '#FF00FF', z-Index:120})
			.appendTo(document.body).fadeTo(speed, 0.5, callback);
		}
		return;
		/*jQuery('<div></div>').attr( {id: '__dimScreen',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
    	dimScreenStop: function(callback) 
	{
        	var x = jQuery('#__dimScreen');
		var x2 = jQuery('#__dimScreenfond');
        	var opacity = x.attr('fade_opacity');
        	var speed = x.attr('speed');
        	x.fadeOut(speed, function() 
		{
            		x.remove();
			x2.remove();
            		if(typeof callback == 'function') 
				callback();
        	});
    	}
}

);

