function getWindowInnerSize(pDoc)
{
	var width, height;
	if (!pDoc)
		pDoc = document;

	if (self.innerHeight) // all except Explorer
	{
		width = self.innerWidth;
		height = self.innerHeight;
	}
	else if (pDoc.documentElement && pDoc.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		width = pDoc.documentElement.clientWidth;
		height = pDoc.documentElement.clientHeight;
	}
	else if (pDoc.body) // other Explorers
	{
		width = pDoc.body.clientWidth;
		height = pDoc.body.clientHeight;
	}
	return {innerWidth : width, innerHeight : height};
}

function getWindowScrollPos(pDoc)
{
	var left, top;
	if (!pDoc)
		pDoc = document;

	if (self.pageYOffset) // all except Explorer
	{
		left = self.pageXOffset;
		top = self.pageYOffset;
	}
	else if (pDoc.documentElement && pDoc.documentElement.scrollTop) // Explorer 6 Strict
	{
		left = document.documentElement.scrollLeft;
		top = document.documentElement.scrollTop;
	}
	else if (pDoc.body) // all other Explorers
	{
		left = pDoc.body.scrollLeft;
		top = pDoc.body.scrollTop;
	}
	return {scrollLeft : left, scrollTop : top};
}


jQuery(document).ready(function() {
	$("img").each(function (i) {
        if($(this).attr('border') > 0) 
        {
        	//alert($(this).attr('src'));
        	$(this).css("border-color", "#BFBFBF").css("border-width", $(this).attr('border') + "px").css("border-style", "solid");
        	
        }
      });
    var fild = 1;
 	$(".add_file").click(function () {
		
	       $("#tr" + fild).show();
	       fild = fild +1;
           
           if(fild == 3)
           {
                $(this).hide();
           }
           return false;
           
	});
    
	$(".show_new").click(function () {
		
		var this_id = $(this).attr("id");
		
		$(".tab").hide();
		
		$("#tab" + this_id).show();
		$(".show_new").removeClass('actived');
		$(this).addClass('actived');
	
	});
	$("img").each(function (i) {
        if($(this).attr('border') > 0) 
        {
        	//alert($(this).attr('src'));
        	$(this).css("border-color", "#BFBFBF").css("border-width", $(this).attr('border') + "px").css("border-style", "solid");
        	
        }
      });
	
	
	$(".turnlight").height($("#box").height());
	
	$(".show_tovar").click(function () {
		var id = $(this).attr("alt");
		
		$(".turnlight").show(200);
		//alert($("#box").height());
		$(".turnlight").animate({ opacity: 0.6 }, 100 ); 
		
		var ws = getWindowInnerSize();
		var wss = getWindowScrollPos();
		height_box = $(".tovar-popup").height();
		var marginTop = wss.scrollTop + (ws.innerHeight/2) - 300;
		//alert(wss.scrollTop);
		$(".tovar-popup").css({"top": marginTop+"px"});
		$(".tovar-popup").fadeIn();

		$.ajax({
		   type: "POST",
		   url: "/bitrix/ajax/product_view.php",
		   data: "id=" + id,
		   success: function(msg){
			 $(".tovar-popup").html(msg);
		   }
		 });
		return false;
	});
	
	$(".close_popup").click(function () {
		$(".tovar-popup").fadeOut();
		$(".turnlight").hide(200);
		return false;
	});
    
    var src = '';
    var new_src = '';
    $(".partners_scroll img").hover(
      function () {
        src = $(this).attr("src");
        new_src = $(this).attr("name");
        $(this).attr("src", new_src);
      }, 
      function () {
        $(this).attr("src", src);
        src = '';
        new_src = '';
      }
    );
	
});
