$(document).ready(function(){
	click_img_inner();
	//slider
	var pos=0;
	var li=$("#block_3 .slide ul").children();
	var liWidth=300;
	var sz=1;
	$("#block_3 .slide ul").css("width",(li.length*liWidth));
	$("#block_3 .but_right").click(function(){
		if(pos<li.length-sz)
		{
			li.animate({left: -liWidth*(pos+1)},400);
			pos+=1;
		}
		else
		{
			li.animate({left: 0},400);
			pos=0;
		}
	});
	$("#block_3 .but_left").click(function(){
		if(pos>0)
		{
			li.animate({left: -liWidth*(pos-1)},400);
			pos-=1;
		}
		else
		{
			li.animate({left: -liWidth*(li.length-sz)},400);
			pos=li.length-sz;
		}
	});
	
	//slider2
	var pos2=0;
	var li2=$("#block_4 .slide ul").children();
	var liWidth2=465;
	var sz2=2;
	$("#block_4 .slide ul").css("width",(li2.length*liWidth2));
	$("#block_4 .but_right").click(function(){
		if(pos2<li2.length-sz2)
		{
			li2.animate({left: -liWidth2*(pos2+1)},400);
			pos2+=1;
		}
		else
		{
			li2.animate({left: 0},400);
			pos2=0;
		}
	});
	$("#block_4 .but_left").click(function(){
		if(pos2>0)
		{
			li2.animate({left: -liWidth2*(pos2-1)},400);
			pos2-=1;
		}
		else
		{
			li2.animate({left: -liWidth2*(li2.length-sz2)},400);
			pos2=li2.length-sz2;
		}
	});
	
	//contacts
	$fl=0;
			$("#contacts .arrow").click(function(){
				if($fl==0)
				{
					$(this).parent().find(".list").css("overflow","visible");
					$(this).parent().find(".list").css("z-index","2");
					$fl=1;
				}
				else
				{
					$(this).parent().find(".list").css("overflow","hidden");
					$(this).parent().find(".list").css("z-index","1");
					$fl=0;
				}
			});
			$("#contacts .list li").click(function(){
				$furl=$(this).parent().find("li:first-child img").attr("src");
				$fnum=$(this).parent().find("li:first-child .tn").text();
				$url=$(this).find("img").attr("src");
				$num=$(this).find(".tn").text();
				$(this).find("img").attr("src",$furl);
				$(this).find(".tn").text($fnum);
				$(this).parent().find("li:first-child img").attr("src",$url);
				$(this).parent().find("li:first-child .tn").text($num);
				$(this).parent().parent().find(".number").text($num);			
				$(this).parent().css("overflow","hidden");
				$(this).parent().css("z-index","1");
				$fl=0;
			});
	//products
	$("#products .menu h3").click(function(){
		$lst=$(this).next("ul");
		$lst.slideToggle("slow");
		$("#left_bar .menu ul").not($lst).slideUp("slow");			
	});
});

function click_img_inner(){
	$('.inner img').click(function(){
		var src_img = $(this).attr('src');
		var left = $(this).offset().left;
		var top_big = $(this).offset().top-40;
		var width_img = $(this).width();
		var height_img = $(this).height();
		if ((width_img<720) && (height_img<700))
		{
			$(this).css('visibility','hidden');
			var ratio = width_img/height_img;
			var height_big = height_img+80;
			var width_big = height_big*ratio;
			var left_big = (left-(width_big-width_img)/2)+10;
			var image = $('<img id="big_img" style="z-index:99999;position:absolute; top:'+top_big+'px; left:'+left_big+'px; height:'+height_big+'px;" src="'+src_img+'" />')
			image.appendTo('body');
		}
		//alert(top+'\n'+top_big)
	});
	

	
	$('.inner').mouseover(function(){
		$("img").each(function() {
			$(this).css('visibility','visible');
		});
		$("#big_img").each(function() {
			$(this).fadeOut();
			$(this).remove();
		});
	});	
}



function offsetPosition(element) {
    var offsetLeft = 0, offsetTop = 0;
    do {
        offsetLeft += element.offsetLeft;
        offsetTop  += element.offsetTop;
		}
	while (element = element.offsetParent);
    [offsetLeft, offsetTop];
}

