var tpl_ = "<div class='wbr-gallery'>\
				<div class='blend'></div>\
				<div class='content'></div>\
			</div>";

/* 
	элемент должен иметь аттрибут - img_detail=%большая картинка%
	или же быть ссылкой на большую картинку и содержать в себе малую
*/
function WbrLoadGallery(selectors,main_conteiner)
{
	if ($(selectors).length>0)
	{
		$(main_conteiner).prepend(tpl_);
		
		$(selectors).click(function(){
			if (typeof $(this).attr("img_detail")=='string')
			{
				imgbig = $(this).attr("img_detail");
			}
			else
			{
				imgbig = $(this).attr('href');
			}

			$(".wbr-gallery").prepend('<div class="spinner"></div>');
			$(".wbr-gallery .content").html("<img src='"+imgbig+"'/>");

			//if ($.browser.msie)
			//	$(".wbr-gallery").show();
			//else
			$(".wbr-gallery").animate({opacity: 1},250);

			$(".wbr-gallery .blend").height($(main_conteiner).height());
			$(".wbr-gallery .blend").css("display","block").animate({opacity: 0.5},250);
			
			if ($.browser.msie && $.browser.version=='6.0')
				$(".wbr-gallery").height($('#index').height());
			
			$(".wbr-gallery").css("left","0");
			var h_ = $(".wbr-gallery img").height();
			if (h_>50)
			{
				WbrLoadGallery_showjpg();
			}
			else
			{
				$(".wbr-gallery img").load(function()
				{
					WbrLoadGallery_showjpg();
				});
			}
			
			return false;
		});
		
		$(".wbr-gallery .blend,.wbr-gallery b").click(function()
		{
			$(".wbr-gallery").animate({opacity: '0'},250);
			$(".wbr-gallery .blend").css("display","none");
			$(".wbr-gallery .content").css("left","-200%");
			$(".wbr-gallery").css("left","-200%");
		});
	}
}
function WbrLoadGallery_showjpg()
{
	var h_ = $(".wbr-gallery img").height();
		var w_ = $(".wbr-gallery img").width();
		ch_ =  !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
		if (h_>ch_) 
		{			
			w_ = w_*(0.8*ch_)/h_;
			h_ = 0.8*ch_;
			$(".wbr-gallery img").width(w_);
			$(".wbr-gallery img").height(h_);
		}

		$(".wbr-gallery .spinner").remove();
		
			if ($.browser.msie)
				$(".wbr-gallery .content").animate({opacity: 1},1);

			$(".wbr-gallery .content").css("margin",-h_/2+"px 0 0 -"+w_/2+"px");
			$(".wbr-gallery .content").height(h_);
			$(".wbr-gallery .content").width(w_);

			$(".wbr-gallery .content").css("left","50%");
			$(".wbr-gallery .content").css("cursor","default");	
			$(".wbr-gallery").removeClass("loaded");		
			
}
