$(document).ready(function(){
	initTargetBlanks();
	initIndexAnimations();
	initIndexSlider();
	initIndexRounders();
	initCatalogListOpacity();
	initCities();
	initCollectMenu();
	initClubMenu();
	initTechnicMenu();
	initAboutMenu();
	initDoorsConfig();
	//drawNewsFilter();
	initContactTabs();
	initProduction();
	initOsteklenie();
	initPopapBuy();
	
	$('.more-article').click(function(){
		$(this).next('.hide_article').toggle();
	});	
})

window.onload = function(){
	//$('#yourCity').click();
}
	
initTargetBlanks = function(){
	$(".target_blank").click(function(){
		window.open($(this).attr("href"));
		return false;
	})
}

initIndexAnimations = function(){

	var timer;
	var pos = 0;
	$(".sprite_design_outer").mouseenter(function(){
		clearInterval(timer);
		timer = setInterval(function(){
			if (pos<=-1800) {clearInterval(timer); return;};
			pos -= 180; 
			$(".sprite_design").animate({top: pos+"px"}, {duration: 0, queue: false});
		}, 30);
		
	}).mouseleave(function(){
		clearInterval(timer);
		timer = setInterval(function(){
			if (pos>=0) {clearInterval(timer); return;};
			pos += 180; 
			$(".sprite_design").animate({top: pos+"px"}, {duration: 0, queue: false});
		}, 30);
	});
	
	var timer1;
	var pos1 = 0;
	$(".sprite_quality_outer").mouseenter(function(){
		clearInterval(timer1);
		timer1 = setInterval(function(){
			if (pos1<=-3600) {clearInterval(timer1); return;};
			pos1 -= 180; 
			$(".sprite_quality").animate({top: pos1+"px"}, {duration: 0, queue: false});
		}, 30);
		
	}).mouseleave(function(){
		clearInterval(timer1);
		timer1 = setInterval(function(){
			if (pos1<=-3960) {
				clearInterval(timer1);
				pos1=0;
				$(".sprite_quality").animate({top: pos1+"px"}, {duration: 0, queue: false});
				return;
			};
			pos1 -= 180; 
			$(".sprite_quality").animate({top: pos1+"px"}, {duration: 0, queue: false});
		}, 30);
	});
	
	var timer2;
	var pos2 = 0;
	$(".sprite_process_outer").mouseenter(function(){
		clearInterval(timer2);
		timer2 = setInterval(function(){
			if (pos2<=-2340) {clearInterval(timer2); return;};
			pos2 -= 180; 
			$(".sprite_process").animate({top: pos2+"px"}, {duration: 0, queue: false});
		}, 30);
		
	}).mouseleave(function(){
		clearInterval(timer2);
		timer2 = setInterval(function(){
			if (pos2>=0) {clearInterval(timer2); return;};
			pos2 += 180; 
			$(".sprite_process").animate({top: pos2+"px"}, {duration: 0, queue: false});
		}, 30);
	});
	
	var timer3;
	var pos3 = 0;
	$(".sprite_attention_outer").mouseenter(function(){
		clearInterval(timer3);
		timer3 = setInterval(function(){
			if (pos3<=-900) {clearInterval(timer3); return;};
			pos3 -= 180; 
			$(".sprite_attention").animate({top: pos3+"px"}, {duration: 0, queue: false});
		}, 30);
	}).mouseleave(function(){
		clearInterval(timer3);
		timer3 = setInterval(function(){
			if (pos3>=0) {clearInterval(timer3); return;};
			pos3 += 180; 
			$(".sprite_attention").animate({top: pos3+"px"}, {duration: 0, queue: false});
		}, 30);
	});
	
	var timer4;
	var pos4 = 0;
	$(".sprite_dealers_outer").mouseenter(function(){
		clearInterval(timer4);
		timer4 = setInterval(function(){
			if (pos4<=-1260) {clearInterval(timer4); return;};
			pos4 -= 180; 
			$(".sprite_dealers").animate({top: pos4+"px"}, {duration: 0, queue: false});
		}, 30);
	}).mouseleave(function(){
		clearInterval(timer4);
		timer4 = setInterval(function(){
			if (pos4>=0) {clearInterval(timer4); return;};
			pos4 += 180; 
			$(".sprite_dealers").animate({top: pos4+"px"}, {duration: 0, queue: false});
		}, 30);
	});
	
	/*
	var timer1;
	var pos1 = 0;
	$(".sprite_quality_outer").mouseenter(function(){
		clearInterval(timer1);
		timer1 = setInterval(function(){
			if (pos1<=-1170) {clearInterval(timer1); return;};
			pos1 -= 180; 
			$(".sprite_quality").animate({top: pos1+"px"}, {duration: 0, queue: false});
		}, 10);
		
	}).mouseleave(function(){
		clearInterval(timer1);
		timer1 = setInterval(function(){
			if (pos1<=-1560) {
					clearInterval(timer1);
					pos1=0;
					$(".sprite_quality").animate({top: pos1+"px"}, {duration: 0, queue: false});
					return;
			};
			pos1 -= 180; 
			$(".sprite_quality").animate({top: pos1+"px"}, {duration: 0, queue: false});
		}, 10);
	})
	*/
};

initIndexSlider = function(){
	var time = 500;
	
	$(".dashboard_content a").click(function(){
		var index = $(".dashboard_content .item").index($(this).parent(".item"));
		
			if ($(".dashboard_content .item").eq(index).hasClass("opened")){
				
				$(".dashboard_content .item").eq(index).removeClass("opened");
				$(".dashboard_content .item").eq(index).animate({width: 172+"px"},{duration: time, queue: false});
				$(".dashboard_content .item").eq(index).find(".more_content").hide(time);
				$(this).find("span").text($(this).attr("title"));
				$(this).removeClass("back");
				if (index>2){
					$(".dashboard_content").animate({left: 0+"px"},{duration: time, queue: false});
				}
			}else{
				
				$(".dashboard_content .item.opened").animate({width: 172+"px"},{duration: time, queue: false});
				$(".dashboard_content .item.opened .more_content").hide(time);
				$(".dashboard_content .item.opened a").find("span").text($(".dashboard_content .item.opened a").attr("title"));
				$(".dashboard_content .item.opened a").removeClass("back");
				$(".dashboard_content .item.opened").removeClass("opened");
				
				$(".dashboard_content .item").eq(index).addClass("opened");
				$(".dashboard_content .item").eq(index).animate({width: 542+"px"},{duration: time, queue: false});
				$(".dashboard_content .item").eq(index).find(".more_content").show(time);
				$(this).find("span").text("свернуть описание");
				$(this).addClass("back");
				if (index>2){
					$(".dashboard_content").animate({left: -360+"px"},{duration: time, queue: false});
				}
			}
		
	});
}

initIndexRounders = function(){
	$(".index_top_columns .item").mouseenter(function(){
		$(this).find(".rounded").animate({height: 280+"px"},{duration: 1000, queue: false});
	}).mouseleave(function(){
		$(this).find(".rounded").animate({height: 112+"px"},{duration: 1000, queue: false});
	})
}
	
initCatalogListOpacity = function(){
	var index=0;
	$(".catalog_list li").mouseenter(function(){
			$(".catalog_list .right_01").css({left: 286+"px"});
			$(".catalog_list .right_02").css({left: -4+"px"});
			$(".catalog_list .right_02_sub").css({left: 590+"px"});
			$(this).addClass("hover");
			$(".catalog_list li:not(.hover) .guard").animate({opacity: 0.9}, {duration: 400, queue: false})
			$(this).find(".left_door").animate({left: -5+"px"}, {duration: 400, queue: false});
			$(this).find(".left_door .opacity").animate({left: -5+"px", opacity: 0}, {duration: 400, queue: false});
			$(this).find(".right_door").animate({right: -11+"px"}, {duration: 400, queue: false});
			$(this).find(".right_door .opacity").animate({right: -11+"px", opacity: 0}, {duration: 400, queue: false});
			index = $(".catalog_list li").index(this);
			$(".catalog_list .desc").eq(index).show();
			$(".catalog_list .desc").eq(index).next(".right_02_sub").show();
			if (!$(".catalog_list .desc").eq(index).hasClass("right_03")){
				if ($(".catalog_list .desc").eq(index).hasClass("right_01")){
					$(".catalog_list .desc").eq(index).animate({opacity: 1, left: "296px"}, {duration: 400, queue: false});
				}else{
					$(".catalog_list .desc").eq(index).animate({opacity: 1, left: "-14px"}, {duration: 400, queue: false});
					$(".catalog_list .desc").eq(index).next(".right_02_sub").animate({opacity: 1, left: "600px"}, {duration: 400, queue: false});
				}
			}else{
				$(".catalog_list .desc").eq(index).animate({opacity: 1, left: "-14px"}, {duration: 400, queue: false});
			};
	}).mouseleave(function(){
			$(".catalog_list li:not(.hover) .guard").animate({opacity: 0}, {duration: 400, queue: false})
			$(this).removeClass("hover");
			$(this).find(".left_door").animate({left: 0+"px"}, {duration: 400, queue: false});
			$(this).find(".left_door .opacity").animate({left: 0+"px", opacity: 0.4}, {duration: 400, queue: false});
			$(this).find(".right_door").animate({right: 0+"px"}, {duration: 400, queue: false});
			$(this).find(".right_door .opacity").animate({right: 0+"px", opacity: 0.1}, {duration: 400, queue: false});
			if (!$(".catalog_list .desc").eq(index).hasClass("right_03")){
				if ($(".catalog_list .desc").eq(index).hasClass("right_01")){
					$(".catalog_list .desc").eq(index).animate({opacity: 0, left: "286px"}, {duration: 0, queue: false});
				}else{
					$(".catalog_list .desc").eq(index).animate({opacity: 0, left: "-4px"}, {duration: 0, queue: false});
					$(".catalog_list .desc").eq(index).next(".right_02_sub").animate({opacity: 0, left: "590px"}, {duration: 400, queue: false});
				}
			}else{
				$(".catalog_list .desc").eq(index).animate({opacity: 0, left: "-4px"}, {duration: 0, queue: false});
			};
			$(".catalog_list .desc").eq(index).hide();
			$(".catalog_list .desc").eq(index).next(".right_02_sub").hide();
	});
};

initCities = function(){
	$(".city_point").hide();
	
	$("div.city_point_content").each(function(){
		$(this).find("p:last").addClass("last");
	}); 
	
	$("#shop_map dl dd ul li span").click(function(){
		if (!$(this).hasClass("opened")){
			$(".city_point").slideUp("fast");
			//$(".city_point").hide(0);
			$(this).parent("li").parent("ul").parent("dd").find(".city_point").stop(true, true).slideUp();
			//$(this).parent("li").parent("ul").parent("dd").find(".city_point").hide(0);
			$(this).parent("li").parent("ul").parent("dd").find("span").removeClass("opened");
			$("#shop_map dl dd ul li span").removeClass("opened");
			$(this).addClass("opened");
			
			$(this).next("br").next(".city_point").show();
			
			//if (!($.browser.msie && $.browser.version <=7)){
			/*$('.city_point .city_point_content').jScrollPane({
				showArrows: false,
				scrollbarWidth: 16,
				dragMinHeight: 19,
				dragMaxHeight: 19
			});	*/
			//}
			var h = $(this).next("br").next(".city_point").find(".city_heighter").height();
			$(this).next("br").next(".city_point").hide();
			
			//alert(h);
			
			if (h<192){
				$(this).next("br").next(".city_point").css({height: h+"px"});
				$(this).next("br").next(".city_point").css({"min-height": h+"px"});
				$(this).next("br").next(".city_point").children(".jScrollPaneContainer").css({height: h+"px"});
				$(this).next("br").next(".city_point").children(".city_point_content").css({height: h+"px"});
			}else{
				if ($.browser.msie && $.browser.version <=7){
					$(this).next("br").next(".city_point").find(".city_heighter").css({height: h+"px"});
				}
			};
			
			$(this).next("br").next(".city_point").slideDown("slow");
			
		}else{
			$(this).removeClass("opened");
			
			$(this).next("br").next(".city_point").slideUp("slow");
			//if (!($.browser.msie && $.browser.version <=7)){
			$('.city_point .city_point_content').jScrollPane({
				showArrows: false,
				scrollbarWidth: 16,
				dragMinHeight: 19,
				dragMaxHeight: 19
			});	
			//}
		};
	})
}

initCollectMenu = function(){
	$(".collection_submenu li").mouseenter(function(){
		$(this).find(".opacity").animate({opacity:0}, {duration: 400, queue: false});
	}).mouseleave(function(){
		$(this).find(".opacity").animate({opacity:0.7}, {duration: 400, queue: false});
	});
	
	$("#main_menu li").eq(0).mouseenter(function(){
		$(".collection_submenu").show();
		$(".collection_submenu").animate({width: 721+"px", height: 346+"px", paddingLeft: 40+"px"},{duration: 800, queue: false});
	}).mouseleave(function(){
		$(".collection_submenu").animate({width: 0+"px", height: 0+"px", paddingLeft: 0+"px"},{duration: 800, queue: false, complete: function(){
			$(".collection_submenu .opacity").animate({opacity:0}, {duration: 0, queue: false});
		}});
	});
	
	$(".collection_submenu").mouseenter(function(){
		$(".collection_submenu .opacity").animate({opacity:0.7}, {duration: 400, queue: false});
	}).mouseleave(function(){
		$(".collection_submenu .opacity").animate({opacity:0}, {duration: 400, queue: false});
	})
}

initClubMenu = function(){
	$(".club_menu li").mouseenter(function(){
		$(this).find(".opacity").animate({opacity:0}, {duration: 400, queue: false});
	}).mouseleave(function(){
		$(this).find(".opacity").animate({opacity:0.5}, {duration: 400, queue: false});
	});
	
	$("#main_menu li.club").mouseenter(function(){
		$(".club_menu").show();
		$(".club_menu").animate({width: 618+"px", height: 172+"px", paddingLeft: 3+"px"},{duration: 800, queue: false});
	}).mouseleave(function(){
		$(".club_menu").animate({width: 0+"px", height: 0+"px", paddingLeft: 0+"px"},{duration: 800, queue: false, complete: function(){
			$(".club_menu .opacity").animate({opacity:0}, {duration: 0, queue: false});
		}});
	});
	
	$(".club_menu").mouseenter(function(){
		$(".club_menu .opacity").animate({opacity:0.5}, {duration: 400, queue: false});
	}).mouseleave(function(){
		$(".club_menu .opacity").animate({opacity:0}, {duration: 400, queue: false});
	})
}

initTechnicMenu = function(){
	$(".technic_menu li").mouseenter(function(){
		$(this).find(".opacity").animate({opacity:0}, {duration: 400, queue: false});
	}).mouseleave(function(){
		$(this).find(".opacity").animate({opacity:0.5}, {duration: 400, queue: false});
	});
	
	$("#main_menu li.technic").mouseenter(function(){
		$(".technic_menu").show();
		$(".technic_menu").animate({width: 618+"px", height: 172+"px", paddingLeft: 9+"px"},{duration: 800, queue: false});
	}).mouseleave(function(){
		$(".technic_menu").animate({width: 0+"px", height: 0+"px", paddingLeft: 0+"px"},{duration: 800, queue: false, complete: function(){
			$(".technic_menu .opacity").animate({opacity:0}, {duration: 0, queue: false});
		}});
	});
	
	$(".technic_menu").mouseenter(function(){
		$(".technic_menu .opacity").animate({opacity:0.5}, {duration: 400, queue: false});
	}).mouseleave(function(){
		$(".technic_menu .opacity").animate({opacity:0}, {duration: 400, queue: false});
	})
}

initAboutMenu = function(){
	$(".about_menu li").mouseenter(function(){
		$(this).find(".opacity").animate({opacity:0}, {duration: 400, queue: false});
	}).mouseleave(function(){
		$(this).find(".opacity").animate({opacity:0.5}, {duration: 400, queue: false});
	});
	
	$("#main_menu li.about").mouseenter(function(){
		$(".about_menu").show();
		$(".about_menu").animate({width: 833+"px", height: 172+"px", paddingLeft: 12+"px"},{duration: 800, queue: false});
	}).mouseleave(function(){
		$(".about_menu").animate({width: 0+"px", height: 0+"px", paddingLeft: 0+"px"},{duration: 800, queue: false, complete: function(){
			$(".about_menu .opacity").animate({opacity:0}, {duration: 0, queue: false});
		}});
	});
	
	$(".about_menu").mouseenter(function(){
		$(".about_menu .opacity").animate({opacity:0.5}, {duration: 400, queue: false});
	}).mouseleave(function(){
		$(".about_menu .opacity").animate({opacity:0}, {duration: 400, queue: false});
	})
}

initDoorsConfig = function(){	
	// Change DOOR -||- MATERIAL
	$("#config_state_menu .linkedin span").click(function(){
		if (!($(this).parent(".linkedin").hasClass("active"))){
			$("#config_state_menu .linkedin span.png").removeClass("png");
			// Click on Materials
			if ($(this).parent(".linkedin").hasClass("material")){
				$("#config_state_menu .linkedin").removeClass("active");
				$(this).parent(".linkedin").addClass("active");
				$(this).parent(".linkedin").find("span").addClass("png");
				$("#big_door").stop(true, true).fadeOut("slow");
				$("#big_material").stop(true, true).fadeIn("slow");
				$("#big_material .model_description").show();
				$("#big_material .wherebuy").hide();
				$(".jScrollPaneTrack").hide();
			}
			// Click on WhereBuy
			if ($(this).parent(".linkedin").hasClass("where_buy")){
				$("#config_state_menu .linkedin").removeClass("active");
				$(this).parent(".linkedin").addClass("active");
				$(this).parent(".linkedin").find("span").addClass("png");
				$("#big_door").stop(true, true).fadeOut("slow");
				$("#big_material .model_description").hide();
				$("#big_material .wherebuy").show();
				$("#big_material").stop(true, true).fadeIn("slow");
						
					$('.wherebuy').jScrollPane({
						showArrows: false,
						scrollbarWidth: 16,
						dragMinHeight: 19,
						dragMaxHeight: 19
					});				

			}
			// Click on Door
			if ($(this).parent(".linkedin").hasClass("door")){
				$("#config_state_menu .linkedin").removeClass("active");
				$(this).parent(".linkedin").addClass("active");
				$(this).parent(".linkedin").find("span").addClass("png");
				$("#big_material").stop(true, true).fadeOut("slow");
				$("#big_door").stop(true, true).fadeIn("slow");
			}
		}
	})
	
	// Open/Close little galleries
	$("#config_choose_menu li span").click(function(){
		if ($(this).parent().hasClass("active")){
			$(this).parent().toggleClass("active");
			$(this).parent().find(".dynamic_gallery").hide();
		}else{
			$("#config_choose_menu li:not(.nonvisible)").removeClass("active");
			$("#config_choose_menu li:not(.nonvisible)").find(".dynamic_gallery").hide();
			$(this).parent().addClass("active");
			$(this).parent().find(".dynamic_gallery").show();
		}
	})
	
	
	// Toggle description/interier
	$(".config_tabs li span").click(function(){		
		if (!($(this).parent().hasClass("active"))){
			if ($(this).parent().hasClass("interior")){
				$(".other_doors").fadeOut(500);
				$(".left_side").fadeOut(500);
				$("#config_state_menu ul").fadeOut(500);
				$("#config_choose_menu .interior.active").removeClass("active");
				$("#config_choose_menu .interior span").fadeIn(500);
				$("#config_choose_menu .interior").removeClass("nonvisible");
				//$("#config_choose_menu").animate({marginTop: 138+"px"}, {duration: 500});
				$("#big_material").stop(true, true).fadeOut("slow");
				$("#big_door").stop(true, true).fadeIn("slow");
				$("#config_state_menu .linkedin").removeClass("active");
				$("#config_state_menu .linkedin.door").addClass("active");				
				$("body").css("background-image","url('"+interior+"')");
				$("body").addClass("interior");
				$(".index_top_columns").addClass("wood_columns_interior");
				var_mode = 'interior';
				$("#itech_super_bug").css({"marginTop": 120+"px"});
			}
			if ($(this).parent().hasClass("description")){
				$("body").removeClass("interior");
				$("body").css('background-image','');
				$(".other_doors").show();
				$(".left_side").show();
				$("#config_state_menu ul").show();
				$("#config_choose_menu .interior").addClass("active");
				$("#config_choose_menu .interior span").fadeOut(500);
				$("#config_choose_menu .interior").addClass("nonvisible");
				//$("#config_choose_menu").css({marginTop: 0+"px"});
				$(".index_top_columns").removeClass("wood_columns_interior");
				var_mode = '';
				$("#itech_super_bug").css({"marginTop": 0+"px"});
			}
			$(".config_tabs li").removeClass("active");
			$(this).parent().addClass("active");
		}
	})	
}

InitSlider = function (id) {
	// Mega Flash Slider
	
	var in_next = false;
	var in_prev = false;
	var anim_1 = false;
	var anim_2 = false;
	var anim_3 = false;
	var anim_4 = false;
	var anim_5 = false;
	
	var curPos = 0;
	var numItems = $("#"+id).find(".item").size();
	var mktime = 500;
	
	var item_w = 36;
	var item_h = 49;
	var top = 12;
	var margin = 8;
	
	var item_w_max = 57;
	var item_h_max = 73;
	var top_max = 0;
	
	var new_pos = 0;		
	
	curPos = $("#"+id+" .gallery_content").find('div.active').index();
	$("#"+id+" .gallery_content").css("width",(numItems-1)*(item_w+margin)+item_w_max+margin)
	
	new_pos += (item_w+margin)*(1-curPos);
	$("#"+id+" .gallery_content").css("left",new_pos+"px");
		
	
	$("#"+id+" .next_slide_control").mouseenter(function(){
		in_next = true;
		direction = "right_to_left";
		if (curPos <= numItems-2){
			moveGallery($(this).parent().find(".gallery_content"), direction);
		}
	}).mouseleave(function(){
		in_next = false;
	})
	
	$("#"+id+" .prev_slide_control").mouseenter(function(){
		in_prev = true;
		direction = "left_to_right";
		if (curPos > 0){
			moveGallery($(this).parent().find(".gallery_content"), direction);
		}
	}).mouseleave(function(){
		in_prev = false;
	})
	
	function moveGallery(gallery, direction){
		if (anim_1 || anim_2 || anim_3 || anim_4 || anim_5) return false;
		
		if (direction == "right_to_left") sign="-";
		if (direction == "left_to_right") sign="+";		
		if (sign=="-"){
			anim_1 = true;
			$(gallery).find(".item").eq(curPos).animate({width: item_w+"px", height: item_h+"px", top: top+"px"}, {duration: mktime, queue: false, complete: function(){anim_1 = false;}});
			anim_2 = true;
			$(gallery).find(".item").eq(curPos+1).animate({width: item_w_max+"px", height: item_h_max+"px", top: top_max+"px"}, {duration: mktime, queue: false, complete: function(){anim_2 = false;}});
		}
		
		if (sign=="+"){
			anim_3 = true;
			$(gallery).find(".item").eq(curPos).animate({width: item_w+"px", height: item_h+"px", top: top+"px"}, {duration: mktime, queue: false, complete: function(){anim_3 = false;}});
			anim_4 = true;
			$(gallery).find(".item").eq(curPos-1).animate({width: item_w_max+"px", height: item_h_max+"px", top: top_max+"px"}, {duration: mktime, queue: false, complete: function(){anim_4 = false;}});
		}
		
		anim_5 = true;				
		
		var new_pos = parseInt($(gallery).css('left'));
		if (sign == '-') new_pos -= (item_w+margin);
		else new_pos += (item_w+margin);
		
		$(gallery).animate({left: new_pos+"px"},{duration: mktime, queue: false, specialEasing: {
		      left: 'linear'}, complete:
			function(){
		    	if (sign == "-") curPos++;
		    	if (sign == "+") curPos--;
				anim_5 = false;				
		    	
				if ((in_next || in_prev) && (((sign == "+") && (curPos > 0)) || ((sign == "-") && (curPos <= numItems-2))))
					moveGallery(gallery, direction);
		}
		})
	}
}


function ajax_load (block, id, page, params) {
	$('#'+block).show();
	$('#'+block+' .close').click(function(){$('#'+id).html('');$('#'+block).hide();});
	$('#'+id).load(page,params);
	return false;
}

function sendStdForm(form) {
	$(form).find('.errorText').remove();
	$(form).find('.errorList').remove();
	$(form).find('.resultText').remove();
	$(form).find('.resultList').remove();
	
	$(form).find('input[type=file]').each ( function(data) {
		if ( this.value != '' ) {
			$(form).submit();
		};
	});
	
	$.post ( form.action, $(form).serialize(), function ( data ) {
		//$(form).html(data);
		$(form).replaceWith(data);
		$('#TB_ajaxContent').jScrollPane({
			showArrows: false,
			scrollbarWidth: 16,
			dragMinHeight: 19,
			dragMaxHeight: 19
		});	
		
	});
}

function array_merge(one, two) {
  one.push(two);
  return one.flatten();
}

initContactTabs = function(){
	$(".uln_map").hide();
	$("#contacts .tabs li").click(function(){
		if (!($(this).hasClass("active"))){
			var index = $("#contacts .tabs li").index($(this));
			$("#contacts .tabs li").removeClass("active");
			$("#contacts .tabs li").eq(index).addClass("active");
			
			$("#contacts .contact_maps .map").hide(400);
			$("#contacts .contact_maps .map").eq(index).show(400);
		};
	});
}

initProduction = function(){
	$("#production .show_more").click(function(){
		if(!($(this).hasClass("opened"))){
			$(this).addClass("opened");
			$(this).find("span").text("свернуть");
			$(this).prev(".sub_content").slideDown("slow");
			$('#production .gallery').jScrollPane({
				showArrows: false,
				scrollbarWidth: 16,
				dragMinHeight: 19,
				dragMaxHeight: 19
			});
		}else{
			$(this).removeClass("opened");
			$(this).find("span").text("узнать больше");
			$(this).prev(".sub_content").slideUp("slow");
		};
	});
}

initOsteklenie = function(){
	$("#osteklenie .show_more").click(function(){
		if(!($(this).hasClass("opened"))){
			$(this).addClass("opened");
			$(this).find("span").text("свернуть");
			$(this).prev(".sub_content").slideDown("slow");
		}else{
			$(this).removeClass("opened");
			$(this).find("span").text("узнать больше");
			$(this).prev(".sub_content").slideUp("slow");
		};
	});
}

var change;	
var i=0;
//window.onload = function(){change = setInterval(second_passed, 3000);};
flag = false;
change = setInterval(second_passed, 3000);

function second_passed() {
		var n = $("#itech img").size();
		if (!flag) {
			if (i==n) {
				i=0;
				$("#itech img").eq(n-1).animate({opacity:0}, {duration: 2000});
				$("#itech img").animate({opacity:0}, {duration: 0});
			};
			$("#itech img").eq(i).animate({opacity:1}, {duration: 2000});
			$("#itech img").removeClass("shown");
			$("#itech img").eq(i).addClass("shown");
			i++;
		}; // flag
	};

function initPopapBuy(){
	$('.th_click').click(function(){
		var height_div = $('#TB_window').height();
		if(height_div > 700){
			height_div =700;
			$('#TB_window').height(700);
			//$('#TB_window').css({'overflow':'auto'});
		}
		$('#TB_ajaxContent').height(height_div-70);
		var res = '-' + (height_div/2) + 'px';

		$('#TB_window').css('margin-top', res);
		/*$('#TB_ajaxContent').jScrollPane({
			showArrows: false,
			scrollbarWidth: 16,
			dragMinHeight: 19,
			dragMaxHeight: 19
		});	*/
		
	})
}	

function slideToggleDivtog1(){
      $('#tog1').slideToggle(1000);
}
function slideToggleDivtog2(){
      $('#tog2').slideToggle(1000);
}
function slideToggleDivtog3(){
      $('#tog3').slideToggle(1000);
}
function slideToggleDivtog4(){
      $('#tog4').slideToggle(1000);
}
function slideToggleDivtog5(){
      $('#tog5').slideToggle(1000);
}
function slideToggleDivtog6(){
      $('#tog6').slideToggle(1000);
}
function slideToggleDivtog7(){
      $('#tog7').slideToggle(1000);
}
function slideToggleDivtog8(){
      $('#tog8').slideToggle(1000);
}
