var may_click=1;

function get_width_bar()
{
	var w1=0;
	$(".view_gallery_wrapper img").each(function(){
		if($(this).is(':hidden')==false){
			w1+=parseInt($(this).width());
			w1+=15;
		};
	});
	return w1;
};

$(document).ready(function(){   	
	var swidth=110;
	var sheight=110;


	$(".pane,.pane2").hover(function(){may_click=0;},function(){may_click=1;})	

	$("#first-page").click(function(){
		if(may_click)
		{
			var cobj=$("."+cur_div);

			window.open(cobj.attr("url"),"_parent");
		};
	});


	$(".left_button").live('mouseover',function(){
		$(this).css({background: "url('/images/left_button2.png') no-repeat -24px 0px"});
	});
	$(".left_button").live('mouseout',function(){
		$(this).css({background: "url('/images/left_button2.png') no-repeat 0px 0px"});
	});
	$(".right_button").live('mouseout',function(){
		$(this).css({background: "url('/images/right_button2.png') no-repeat 0px 0px"});
	});
	$(".right_button").live("mouseover",function(){
		$(this).css({background: "url('/images/right_button2.png') no-repeat -24px 0px"});
	});


	$(".view_gallery_wrapper img").hover(function(){
		$(this).parent().next().show();
	},function(){
		$(this).parent().next().hide();
	})

	$(".view_gallery_wrapper").mousemove(function(event){
		curx=event.pageX;

		$(".view_gallery_wrapper img").each(function(){
			var coor=$(this).offset().left;
			var cc=1;

			var sw=swidth;
			var sh=sheight;

			var sh1=sh;
			var t=0;
			if(Math.abs(coor+60-curx)<200)
			{
				sw=sw*(1+Math.pow(200-Math.abs(coor+60-curx),3)/Math.pow(200,3)/4);
				sh=sh*(1+Math.pow(200-Math.abs(coor+60-curx),3)/Math.pow(200,3)/4);
//				alert(Math.cos((90-Math.abs(coor+45-curx))*3.14/180));
//(90-Math.abs(coor+45-curx))/90

			};
			$(this).css({width: sw+"px", height: sh+"px", marginTop: -(sh-sh1)*150/200+"px"});
		});
	});
	$(".left_button").live('click',function(){
		var ml=parseInt($(".view_gallery").css("marginLeft"));
		ml+=129;
		if(ml>0){
			ml=0;
			$(this).removeClass("left_button").addClass("left_button_disabled");
		} else {
			$(".right_button_disabled").removeClass("right_button_disabled").addClass("right_button");
		};
		$(".view_gallery").stop().animate({marginLeft: ml+"px"},200);
	});
	$(".right_button").live('click',function(){
		var t=get_width_bar()-parseInt($(".view_gallery_wrapper").width());
		var ml=parseInt($(".view_gallery").css("marginLeft"))-128;

		if((t+ml)<0){
			$(this).addClass("right_button_disabled").removeClass("right_button");
		} else {
			$(".left_button_disabled").removeClass("left_button_disabled").addClass("left_button");
		};
		$(".view_gallery").stop().animate({marginLeft: ml+"px"},200);
	});
	$(".view_gallery_wrapper").mouseout(function(event){
		$(".view_gallery_wrapper img").each(function(){
			var sw=swidth;
			var sh=sheight;
			$(this).css({width: sw+"px", height: sh+"px", marginTop: 0+"px"});
		});
	});
	$("#info_discount .news-close").click(function(){
		 $("#info_discount").fadeOut(500);
	});
	$("#info_error .news-close").click(function(){
		 $("#info_error").fadeOut(500);
	});
	$("#info_success .news-close").click(function(){
		window.location.href='test.php';
	});
						   
	$(".pane .news-close").click(function(){
		 $("#news").animate({marginRight: "-450px"}, 720);
		 $("#news-open").show(420);
		 $.cookie("show_news","no", {path: '/', expires: 2000000});
	});

	$("#banner-close").click(function(){
		 $("#banner").animate({marginLeft: "-350px"}, 720);
		 $("#banner-open").show(420);
		 $.cookie("show_banner","no", {path: '/', expires: 2000000});
	});

	$(".pane #news-open").click(function(){
		 $("#news").animate({marginRight: "10"}, 720);
		 $("#news-open").hide(420);
		 $.cookie("show_news","yes", {path: '/', expires: 2000000});
	});

	if($.cookie("show_news")=="no")
	{
		 $("#news").animate({marginRight: "-450"}, 320);
		 $("#news-open").show(420);
		 $.cookie("show_news","no", {path: '/', expires: 2000000});
	
	};
	$("a").click(function(){
		re=/getpic/;
		re2=/(\.xls)|(mailto)/;
		re3=/\.pdf/;
		re4=/ELEMENT_ID/;
		re4=/javascript/;


		re5=/getpic.php\?h=100/;

		re6=/\#[0-9]*/;

		re7=/images/;


		if($(this).hasClass("tu_ql"))
		{
			return true;
		};

//		alert(this.href);

		if((!this.href.match(re7))&&(!this.href.match(re6))&&(!this.href.match(re5))&&(!this.href.match(re))&&(!this.href.match(re4))&&(!this.href.match(re2))&&(!this.href.match(re3))&&(this.target==""))
		{
			$("#photo").hide();
			$("#prod").hide();
			$("#waiter").show();
		} else {
		};

	});

});
function sel_tree(id,name,img,perc)
{
	$("#d_tree").fadeOut(600);

	var stone=$("#id_stone").attr("value");
	var glass=$("#id_glass").attr("value");

	if((stone!="")&&(stone!=undefined))
	{
		$("#id_tree").attr("value",name+" / Искуственный камень "+stone);
	} else if((stone!="")&&(stone!=undefined)) {
		$("#id_tree").attr("value",name+" / Стекло "+glass);
	} else {
		$("#id_tree").attr("value",name);
	};
	$("#tree_name").html(name);
	$("#img_tree").attr("src","/getpic.php?w=60&src="+img);

	if(perc=="")
	{
		perc=0;
	};
	perc=parseInt(perc);
	selected_perc=perc;

	$("#perc").val(perc);

	var price=parseInt(prices[selected_fabric][tsize]);
	$("#id_price").attr("value",(price+selected_glass)*(100+perc)/100);
	if(prices_comp.length>0)
	{
		$("#id_price_comp").attr("value",prices_comp[selected_fabric][tsize]);
	};
	$("#price_name").html((price+selected_glass)*(100+perc)/100);
}
function sel_stone(id,name,img)
{
	$("#d_stone").fadeOut(600);
	var tree=$("#tree_name").html();

	$("#id_tree").attr("value",tree+" / Искуственный камень "+name);
	$("#id_stone").attr("value",name);
	$("#stone_name").html(name);
	$("#img_stone").attr("src","/getpic.php?w=60&src="+img);
}
function sel_glass(id,name,img)
{
	var dop=nacenka;

	if(id==764)
		dop=0;

	selected_glass=dop;

	var price=parseInt(prices[selected_fabric][tsize]);
	$("#id_price").attr("value",((price+dop)*(100+selected_perc)/100));
	if(prices_comp.length>0)
	{
		$("#id_price_comp").attr("value",prices_comp[selected_fabric][tsize]);
	};
	$("#price_name").html(((price+dop)*(100+selected_perc)/100));
//	var price=parseInt(prices[1][tsize]);

//	$("#id_price").attr("value",price+dop);
//	$("#price_name").html(price+dop);

	$("#d_glass").fadeOut(600);
	var tree=$("#tree_name").html();

	$("#id_tree").attr("value",tree+" / Стекло "+name);
	$("#id_glass").attr("value",name);
	$("#glass_name").html(name);
	$("#img_glass").attr("src","/getpic.php?w=60&src="+img);
}
function sel_fabric(id,name,img,cat,news)
{
	selected_fabric=cat;
	$("#id_price").attr("value",(parseInt(prices[cat][tsize])+selected_glass)*(100+selected_perc)/100);

	if(prices_comp.length>0)
	{
        	$("#id_price_comp").attr("value",prices_comp[cat][tsize]);
	};

	$("#price_name").html((parseInt(prices[cat][tsize])+selected_glass)*(100+selected_perc)/100);
//	alert(3);
	$("#d_fabric").fadeOut(600);
//	alert(4);
	$("#id_fabric").attr("value",id);
//	alert(5);
	$("#id_fabric1").attr("value",name);
//	alert(6);
	$("#fabric_name").html(name);
	$("#img_fabric").attr("src","/getpic.php?w=60&src="+img);
	$("#id_comp").attr("value","Без компаньона");
	$("#comp_name").html("Без компаньона");
	$("#img_comp").hide();
	if(news=="21")
	{
		$(".new_mat2").show();
	} else {
		$(".new_mat2").hide();
	};
}
function sel_comp(id,name,img)
{
	$("#d_comp").fadeOut(600);
	$("#id_comp").attr("value",name);
	$("#comp_name").html(name);
	if(img!="")
	{
		$("#img_comp").attr("src","/getpic.php?w=60&src="+img);
		$("#img_comp").show();
	} else {
		$("#img_comp").hide();
	};
}
$(document).ready(function(){
	$("img").fullsize({forceTitleBar: false, zoomInSpeed: 500, zoomOutSpeed: 200});
});
