$(document).ready(function(){

	$('#photos1').galleryView({
		panel_width: 434,
		panel_height: 323,
		frame_width: 82,
		frame_height: 61,
		transition_speed: 200,
		transition_interval: 0,
		background_color: 'white',
		border: 'none',
		nav_theme: "dark"
	});

	$(".l-popup_map").css("position","absolute");
	$(".l-popup_map").draggable();

	
	//Typecast.Init();

/*
	if($.browser.msie) {
		//
		}
	else {
		$(".mask-phone").mask("+375 (99) 999-99-99");
		}
*/

	// rich bg
	var urls = ['page-bg-t.jpg','page-bg-lr.png','page-bg-b.jpg','popup.png'];
	$.preload( urls, {
		base:'i/',
		onFinish:function(){
			$(".l-body__bg_rich").show()
			}
		});

	// login
	$(".l-header .login").css("top","-65px").removeClass("login_open")

	$(".l-header .login__toggle").click(function(){
		if ($(this).parent().hasClass("login_open")) {
			$(this).parent().animate({top:"-65px"},600,"swing")
			$(this).parent().removeClass("login_open")
			}
		else {
			$(this).parent().animate({top:"0px"},600,"swing")
			$(this).parent().addClass("login_open")
			}
		return false;
		})

		// popups
		function popupShow (id){
			$(".l-tint").show()
			$(id).show()
			}
		function popupChange (idHide,idShow){
			$(idHide).hide()
			$(idShow).show()
			}
		function popupsHide (){
			$(".l-tint").hide()
			$(".l-popup").hide()
			}

		$(".popup-toggle_reg").click(function(){
			popupShow("#popup-reg")
			return false;
			})	
		$(".popup-toggle_pass").click(function(){
			popupShow("#popup-pass")
			return false;
			})	
		$(".l-popup__close").click(function(){
			popupsHide()
			return false;
			})


			$("#popup-reg .submit").click(function(){
				popupChange("#popup-reg","#popup-reg-ok")
				return false;
				})	
			$("#popup-reg-ok .submit").click(function(){
				popupsHide()
				return false;
				})	
			$("#popup-pass .submit").click(function(){
				popupChange("#popup-pass","#popup-pass-ok")
				return false;
				})	
			$("#popup-pass-ok .submit").click(function(){
				popupsHide()
				return false;
				})	


		$(".b-bron a, .t-data2 .td-ctrls .link-js").click(function(){
            var mumuo = $(this).attr("name");
			$(".l-popup_order").css("position","absolute").css("top",$(window).scrollTop()+100)
			popupShow("#popup-order"+mumuo)
			return false;
			})	
			$("#popup-order .submit").click(function(){
				popupChange("#popup-order","#popup-order-ok")
				return false;
				})	
				$("#popup-order-ok .submit").click(function(){
					popupsHide()
					return false;
					})	

		$(".b-views_otziv__add").click(function(){
			popupShow("#popup-review")
			return false;
			})	
			$("#popup-review .submit").click(function(){
				popupsHide()
				return false;
				})	

		$(".faq-btn").click(function(){
			popupShow("#popup-ask")
			return false;
			})	
			$("#popup-ask .submit").click(function(){
				popupsHide()
				return false;
				})	


	$(window).scroll(function(){
		if($.browser.msie&&/MSIE 6.0/.test(navigator.userAgent)) {
			$(".l-popup_small, .l-popup_smaller").css("top",$(window).scrollTop()+100)
			}
		// $(".l-popup_order").css("top",$(window).scrollTop()+100)
		})	

	// footer
	jQuery(".l-footer .btns a").css({opacity:"0.2"}).hover(
		function(){
			jQuery(this).stop().fadeTo('normal',"1");
		},
		function(){
			jQuery(this).stop().fadeTo('normal',"0.2");
		}
	);

	// b-title
	$(".b-title H3 .link-js").hover(function(){
		$("#popup-drop").show()
		$("#popup-drop").css("position","absolute").css("left",$(this).parent().offset().left-8).css("top",$(this).parent().offset().top-27)
		$(this).parent().addClass("title_open")
		})
	$(".b-title H3 .link-js").click(function(){
		return false
		})
	$("#popup-drop").hover(function(){},function(){
		$("#popup-drop").hide()
		$(".title_open").removeClass("title_open")
		})

	$(document).click(function(){
		$("#popup-map").hide()
		})
		$(".l-popup_map.l-popup__close").click(function(){
			alert(1)
			$("#popup-map").hide()
			return false;
			})

	// map
	$(".td-address .link-js, .link-map").click(function(){
        var mumu = $(this).attr("name");
		$("#popup-map"+mumu).css("left","50%").css("margin","-255px").css("top", $(document).scrollTop()+(document.documentElement.clientHeight/2)-0)
		$("#popup-map"+mumu).show()
		return false
		})
	$(".l-popup_map").click(function(e){
		e.stopPropagation();
		})
	$(".l-popup__close-single").click(function(e){
		$(this).parents(".l-popup").hide()
		return false
		})
	$(".l-popup_map").dblclick(function(e){
		$(this).hide()
		})
		

	// search
	$(".b-search input.text").focus(function(){
		if ($(this).attr("value") == "Поиск") {$(this).get(0).value = ""}
		})
	$(".b-search input.text").blur(function(){
		if ($(this).get(0).value == "") {
			$(this).get(0).value = "Поиск"
			}
		})
	

	// footer
	var height_corr = 0;
	if ($.browser.webkit) {height_corr = 100}
	$(".l-body__i2").height($(".l-body__i").get(0).offsetHeight-300+height_corr)
	
	$(window).resize(function(){
	//	$(".l-body__i2").css("height", $(".l-body__i").css("height"))
		})
});

window.onload = go;
function go(){
	Typecast.Init();
}

