// JavaScript Document
$(document).ready(function()
{
	$("body").removeClass("noscript");


	if($('.madein br').length > 1)
		$('.madein br:eq(0)').hide();
		
	//Colorbox
	if ($("a[rel='example']").length)
		$("a[rel='example']").colorbox({slideshow:false, current:'картинка {current} из {total}'});


	/* Top Menu */
	if($(".topMenu").length)
	{
		$(".topMenu").find(".podmenu").parent().addClass("withPodmenu");
		$(".topMenu .withPodmenu").hover(function(){
			$(this).addClass("hover");
			//$(this).find(".podmenu").show();
		}, function(){
			$(this).removeClass("hover");
			//$(this).find(".podmenu").hide();
		})
	}
	
	if(($(".vacances").length)||($(".review").length))
	{
		$(".vacancesItemList").each(function()
		{
			if(!$(this).hasClass("opened"))
			{
				$(this).hide();
			}
		});
		$(".vacancesItem-body").hide();
		$(".vacancesItem-title").click(function()
		{
			if($(this).parent().hasClass("open"))
			{
				$(this).parent().find(".vacancesItem-body").slideUp().parent().removeClass("open");

			}
			else
			{
				$(this).parent().find(".vacancesItem-body").slideDown().parent().addClass("open").siblings().find(".vacancesItem-body").slideUp().parent().removeClass("open");
				
			};
			return false;
		});
		
		$(".vacances-title a").click(function()
		{
			if(!$(this).hasClass("current"))
			{
				$(this).parent().parent().find(".vacances-body").find(".vacancesItemList").eq($(this).index()).show().addClass("opened").siblings().hide().removeClass("opened");
				$(this).addClass("current").siblings().removeClass("current");
			}
			return false;
		});
	}
	
	/* Content Table Format */
	if($(".content table").length)
	{
		$(".content table").each(function(){
		
			if(!$(this).hasClass("noform"))
			{
				$(this).find("tbody tr:last-child").addClass("last-child");
				$(this).find("tbody tr:first-child").addClass("first-child");
				
				$(this).find("tbody td").hover(function()
				{
					if($(this).attr('rowspan')<=1)
					{
						$(this).parent().find("td").each(function()
						{
							if($(this).attr('rowspan')<=1)
							{
								$(this).css("cursor","pointer").css("background-color","#e8f0f2");
							}
						});
					}
				},
				function()
				{
					$(this).parent().find("td").css("background-color","");
				})
			}
		})
	}
	
	if($(".prodLink").length)
	{
		$(".filterItems").each(function(){
			HeightForRows($(this),$(this).find(".prodLink"), 202);
			//alert($(".trumbnail").length);
		})
	}
	
	/* Product Gallery Tabs */
	if($('.product-gallery').length)
	{
		$('.product-gallery-small a').click(function(){
			$(this).addClass('current').siblings().removeClass('current');
			$(this).parent().parent().find(".product-gallery-big img").eq($(this).index()).removeClass("hide").addClass("visible").siblings().removeClass("visible").addClass("hide");
			return false;
		})
	}

	//фильтр область применения
	if($('#select_use').length) {
		var obj = $('#select_use').text();
		$('.obj_all').hide();
		$('.'+obj).show();
		$('#'+obj).parent().siblings().removeClass('current');
		$('#'+obj).parent().addClass('current');
		return false;
	}
	
});

/* ON RESIZE */
$(window).resize(function(){
	

	
});

/******************/

/* Height Blocks */
function HeightForRows(parentBlock,childBlock, childBlockWidth)
{
	var widthBox = parentBlock.width();
	var widthBlock = childBlockWidth; /* width of small block whith margin and padding */
	var colBlockInRow = Math.floor(widthBox/widthBlock);
	var colRow = Math.ceil((childBlock.length)/colBlockInRow);
	var colElements = childBlock.length;
	//alert(colElements);
	var indexElement = 0;
	var maxHeight;
	childBlock.each(function()
		{
			$(this).css("height","auto");
		});
	
	for(i=1; i<=colElements; i+=colBlockInRow)
	{
		maxHeight = 0;
		for(j=0; j<colBlockInRow; j++)
		{
			indexElement = i+j-1;
			currentHeight = childBlock.eq(indexElement).height();
			if (maxHeight == 0 || currentHeight > maxHeight) 
			{
				maxHeight = currentHeight;
			}
		}
		for(j=0; j<colBlockInRow; j++)
		{
			indexElement = i+j-1;
			childBlock.eq(indexElement).height(maxHeight);
		}
		
	}
}

/* Popups */
function popupOverlay(linkClick,popup,popupArea,closer){
	popup.hide();
	linkClick.click(function()
		{
			popup.show();
			return false;
		});
	popupArea.click(function()
		{
			popup.hide();
			$('body').append('<span id="ok"></span>');
			$("#ok").remove();
			
		});
	closer.click(function()
		{
			popup.hide();
			$('body').append('<span id="ok"></span>');
			$("#ok").remove();
		});
}

/* Detected IE6 */
function detectIE6(){
  var browser = navigator.appName;
  if (browser == "Microsoft Internet Explorer"){
	var b_version = navigator.appVersion;
	var re = /\MSIE\s+(\d\.\d\b)/;
	var res = b_version.match(re);
	if (res[1] <= 6){
	  return true;
	}
  }
  return false;
}

