//#################################################################
// Light box  #####################################################

// Vous devez avoir un DIV avec le id #b_black qui servira de toile de fond semi-transparente
// et un DIV avec le id #b_str qui contiendra votre contenu centré au centre de l'écran

/* Voici le CSS de base pour les deux DIVs

#b_ctr
{
	position: absolute;
	top: 0;
	left: -9000px;
	z-index: 9999;
}

#b_black
{
	background-color: #000;
	position: absolute;
	top: 0;
	left: 0;
	z-index: 9998;
	display: none;
}

*/

$.wt_lightbox = function(image_path)
{
	var b_ctr = $("#b_ctr");
	var b_black = $("#b_black");
	
	var b_loading = $("#b_loading");
	
	var w_height = $(window).height();
	var w_width = $(window).width();
	
	var d_height = $(document).height();
	var d_width = $(document).width();
	
	var pos_x = 0;
	var pos_y = 0;
	
	var box_width = 0;
	var box_height = 0;
	
	b_black.css("width", d_width);
	b_black.css("height", d_height);
	
	b_black.stop(true,true).fadeTo(400, 0.75, function(){
		var l_pos_x =  w_width / 2;
		var l_pos_y = (w_height / 2) + $(window).scrollTop();
		var l_height = b_loading.outerHeight() / 2;
		var l_width = b_loading.outerWidth() / 2;
		b_loading.css({'left' : l_pos_x - l_width, 'right' : l_pos_y - l_height}).fadeIn(300);
	});
	
	pos_x = w_width / 2;
	pos_y = (w_height / 2) + $(window).scrollTop();
	b_ctr.html('<img id="curr_zoom_image" src="'+image_path+'" />');
	
	$("#curr_zoom_image").one("load",function(){
		box_width = b_ctr.outerWidth();
		box_height = b_ctr.outerHeight();
		
		b_ctr.css('opacity', '0');
		
		b_ctr.css("top", pos_y - (box_height/2));
		b_ctr.css("left", pos_x - (box_width/2));
		b_ctr.animate({opacity: 1}, 500, function(){
		
			b_loading.hide();
		
		});
	})
	.each(function(){
		if(this.complete) $(this).trigger("load");
	});
	
	
	
	$("#b_black, #b_ctr").click(function(){
		b_ctr.stop(true,false).animate({opacity:0}, 300, function(){
			$(this).css('left', '-9000px');
			b_black.fadeOut(200);
		});
		
	});
}

$.wt_lightbox_friend = function()
{
	var b_ctr = $("#b_ctr_friend");
	var b_black = $("#b_black");
	
	var w_height = $(window).height();
	var w_width = $(window).width();
	
	var d_height = $(document).height();
	var d_width = $(document).width();
	
	var pos_x = 0;
	var pos_y = 0;
	
	var box_width = 0;
	var box_height = 0;
	
	b_black.css("width", d_width);
	b_black.css("height", d_height);
	
	pos_x = w_width / 2;
	pos_y = (w_height / 2) + $(window).scrollTop();
	

	box_width = b_ctr.outerWidth();
	box_height = b_ctr.outerHeight();
	
	b_ctr.css('opacity', '0');
	
	b_black.stop(true,true).fadeTo(400, 0.75, function(){
		b_ctr.css("top", pos_y - (box_height/2));
		b_ctr.css("left", pos_x - (box_width/2));
		b_ctr.animate({opacity: 1}, 500);
		
		/*console.log('Position image: '+pos_x+' - '+pos_y)
		console.log(test1+' - '+test2)
		console.log('Dimension image: '+box_width+' - '+box_height);
		console.log('Dimension ecran: '+d_width+' - '+d_height);*/
	});
	
	$("#b_black").click(function(){
		b_ctr.stop(true,true).animate({opacity: 0}, 300, function(){
			$(this).css('left', '-9000px');
			b_black.fadeOut(200);
			$("#send_friend_error_box:visible").hide();
		});
		
	});
}
