var WbrIsIE6 =(($.browser.msie) && ($.browser.version=='6.0'));

// превью по ховеру { 
/* selector == img */
var WbrHoverPreview_offsetY = 0;
function WbrHoverPreview(selector)
{
	if ($("#index .wbr-over-prewiev").length==0)
	{
		$("#top").append("<div class='wbr-hover-prewiev' style='z-index:9999;position:absolute;display:none;'>\
								<sup class='pngfix'></sup>\
								<div class='img pngfix'></div>\
							</div>");
	}
	
	// вешаем события
	$(selector).hover(function(e)
	{
		WbrHoverPreview_offsetY = 0;
		if ($(this).find('img').length>0)
		{
			coord = mousePageXY_(e);
			photo_ = $(this).find('img').attr('src');
			
			//offset_x = -($(this).find('img').attr('width')-103)/2;
			//offset_y = -($(this).find('img').attr('height')-103)/2;			
			//alert($(this).find('img').attr('myheight'));
			//return 0;
		
			
			WbrHoverPreview_offsetY = (25+1*$(this).find('img').attr('myheight'));
			//alert(WbrHoverPreview_offsetY);
			$(".wbr-hover-prewiev .img")
							.remove("img")
							.height(13+1*$(this).find('img').attr('myheight'));
			$(".wbr-hover-prewiev .img").html("<img src='"+photo_+"'/>");
			$(".wbr-hover-prewiev").css("left",coord[0]-66+'px');
			$(".wbr-hover-prewiev").css("top",coord[1]-WbrHoverPreview_offsetY+'px');
			//if (!$.browser.msie)
				$(".wbr-hover-prewiev img");
							//.css('margin-top',offset_y+'px')
							//.css('margin-left',offset_x+'px');
			$(".wbr-hover-prewiev").show();
		}
	},
	function()
	{
		$(".wbr-hover-prewiev").hide();
	});
	$(selector).mousemove(function(e)
	{
		if (WbrHoverPreview_offsetY==0) return 0;
		coord = mousePageXY_(e);
		
		need_top = coord[1]-WbrHoverPreview_offsetY-getBodyScrollTop();
		
		if (need_top<0)
			d_y = -need_top;
		else
			d_y = 0;
			
		//if (document.getElementsByTagName('html')[0].clientWidth<coord[0]+$(".wbr-hover-prewiev").width()+50)
		//	coord[0] = coord[0] - 40 - $(".wbr-hover-prewiev").width();
		
		$(".wbr-hover-prewiev").css("left",coord[0]-66+'px');
		if (d_y==0)
			$(".wbr-hover-prewiev").css("top",coord[1]-WbrHoverPreview_offsetY+'px');
		else
			$(".wbr-hover-prewiev").css("top",coord[1]+10+'px');
	});
}
function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function mousePageXY_(e)
{
	      var x = 0, y = 0;
		  var arr_ = [];
	     
	      if (!e) e = window.event;
	     
	      if (e.pageX || e.pageY)
	      {
	        x = e.pageX;
	        y = e.pageY;
	      }
	      else if (e.clientX || e.clientY)
	      {
	        x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
			y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	      }
     
		arr_[0]=x;
		arr_[1]=y;
	      return arr_;
}
// превью по ховеру } 

// аккордион {
/* контейнер аккордиона, кликабельная область, сам контент */
var WbrAccordionflag = true;
function WbrAccordion(main_obj,helper,content,isclose)
{
	if ($(main_obj).length==0) return false;

	$(main_obj).find(content).css("position","relative").css("overflow","hidden");
	if (isclose)
	{
		$(main_obj).attr("isexpanded","false");
		$(main_obj).find(content).height(0);
	}
	else
	{
		$(main_obj).attr("isexpanded","true");
	}

	$(helper).click(function()
	{
		o = $(this).closest(main_obj); // конктерная обертка
		o_sub = o.find(content); // конкретный контент

		if (WbrAccordionflag)
		{
			if ((o.attr("isexpanded")!="true"))
			{
				
				o2 = $(helper).closest(main_obj+"[isexpanded='true']");
				o_sub2 = o2.find(content);
				
				o_sub2.animate({height: 0},1000,function()
				{
					$(main_obj).attr("isexpanded","false");
				});				
			
				WbrAccordionflag = false;
				var h_ = o_sub.get(0).scrollHeight - o_sub.get(0).clientHeight;
				o_sub.animate({height: h_},1000,function()
				{
					$(main_obj).attr("isexpanded","false");
					o.attr("isexpanded","true");

					WbrAccordionflag = true;
					/*if ($.browser.msie && $.browser.version=='6')
					{
						
					}*/			
				});
			}
			else
			{
				WbrAccordionflag = false;
				var h_ = 0;
				o_sub.animate({height: h_},1000,function()
				{
					$(main_obj).attr("isexpanded","false");
					//o.attr("isexpanded","true");

					WbrAccordionflag = true;
					/*if ($.browser.msie && $.browser.version=='6')
					{
						
					}*/			
				});
			}
		}
		
		return false;
	});
}
// аккордион }

// формы {
/*
(селектор инпута, класс-по-активности)
*/
function  WbrSwitchesInputs(selector,toggle_class)
{
	$(selector).each(function()
	{
		$(this).attr("switchtext",$(this).get(0).value);
		if ($(this).attr("type")=='password')
		{
			$(this).parent().append('<span class="pswrd-label" style="position:absolute;">'+$(this).attr("switchtext")+'</span>');
			$(this).parent().find(".pswrd-label").css("font-size",$(this).css("font-size"));
			$(this).parent().find(".pswrd-label").css("color",$(this).css("color"));
			$(this).attr("value","");
		}
	});

	$(selector).focus(function()
	{
		if ($(this).attr("type")!='password')
		{
			if ($(this).attr("switchtext")==$(this).get(0).value)
			{
				$(this).attr("value","");
				$(this).addClass(toggle_class);
			}
		}
		else
		{
			if ($(this).attr("switchtext")==$(this).parent().find('.pswrd-label').html())
			{
				$(this).parent().find('.pswrd-label').hide();
				$(this).addClass(toggle_class);
			}
		}
	});
	
	$(selector).blur(function()
	{		
		if ($(this).attr("type")!='password')
		{
			if ($(this).get(0).value=='')
			{
				$(this).attr("value",$(this).attr("switchtext"));
				$(this).removeClass(toggle_class);
			}
		}
		else
		{
			if ($(this).get(0).value=='')
			{
				$(this).parent().find('.pswrd-label').show();
				$(this).removeClass(toggle_class);
			}
		}
	});
	$(selector).parent().find('.pswrd-label').click(function()
	{
		$(this).parent().find(selector).focus();
	});
}

// формы }

// колбэк для резайза окна браузера {
var wbr_service_wbrCallbackOfresize_timer_id = 0;
var wbr_service_wbrCallbackOfresize_function;
/* флаг - стартовать ли функцию сразу после вызова?, функция */
function WbrCallbackOfResize(is_start,function_)
{
	if (is_start) function_();
	
	wbr_service_wbrCallbackOfresize_function = function_;
	$(window).resize(function()
	{
		if (wbr_service_wbrCallbackOfresize_timer_id==0)
			wbr_service_wbrCallbackOfresize_timer_id = setTimeout(wbrCallbackOfresize_function, 250);
	});	
}
function wbrCallbackOfresize_function()
{
	wbr_service_wbrCallbackOfresize_function();

	// сбрасываем таймер резайса
	if (wbr_service_wbrCallbackOfresize_timer_id!=0)
	{
		clearTimeout(wbr_service_wbrCallbackOfresize_timer_id); 
		wbr_service_wbrCallbackOfresize_timer_id=0; 
	}
}
// }

// проверка наличия класса у элемента {
function WbrIsClass(selector,class_)
{
	if (typeof selector == 'string')
		return ($(selector).attr("class").indexOf(class_)>-1);
	else
		return (selector.attr("class").indexOf(class_)>-1);
}
// }

// pause {
function WbrSleep(time_ms,function_)
{
	return setTimeout(function_, time_ms);
}
function WbrResetPause(id)
{
	clearTimeout(id);
}
// }
