$(function () {

	var jScriptsAddress = "/jscripts-ver-2";

		var SBoptions = {
				animate:			false,
				handleOversize:     'drag',
				handleUnsupported:  'remove',
				autoplayMovies:     false
			};

	$.getScript(jScriptsAddress + "/jquery.csspngfix.src.js");

	$.getScript(jScriptsAddress + "/shadowbox/shadowbox.js", function () {
		$.getScript(jScriptsAddress + "/shadowbox/skin/modified/skin.js", function(){
			Shadowbox.init(SBoptions);
		});
	});

	// Форма авторизации (скрытие и показ подписей к логину/паролю)
	if ($('.auth-login').length > 0) {

		if ($.browser.webkit) {
			$('.auth-login, .auth-password').find('label').each(function () {
				$(this).css('padding-left', '2.2em');
			});
		}

		$('.auth-login, .auth-password').find('input').val('');

		$('.auth-login, .auth-password').find('label').click(function () {
			$(this).hide();
		});

		$('.auth-login, .auth-password').find('input').focus(function () {
			var $parent = $(this).parent();
			var $label = $($parent.children().get(0));
			$label.hide();
		});

		$('.auth-login, .auth-password').find('input').blur(function () {
			var $parent = $(this).parent();
			var $label = $($parent.children().get(0));
			
			if ($.trim($(this).val() + '') == '') {
				$(this).val('');

				if ($.browser.opera || $.browser.mozilla || $.browser.webkit) {
					$label.css('padding-left', '2.2em');
				}
				$label.show();
			}
		});
	}

	// Новости
	if ($("a.news-link").length > 0 || $("a.news-link-year").length > 0) {
		$.getScript(jScriptsAddress + "/news.js");
	}

	// Калькулятор МГ
	if ($("div.calc_1").length > 0) {
		$.getScript(jScriptsAddress + "/autocomplete/lib/jquery.bgiframe.min.js", function () {
			$.getScript(jScriptsAddress + "/autocomplete/lib/jquery.dimensions.js", function () {
				$.getScript(jScriptsAddress + "/autocomplete/lib/jquery.ajaxQueue.js", function () {
					$.getScript(jScriptsAddress + "/autocomplete/jquery.autocomplete.js", function () {
						$.getScript(jScriptsAddress + "/jquery-spin.js", function () {
							$.getScript(jScriptsAddress + "/calc-1.js");
						});
					});
				});
			});
		});
	}

	// Калькулятор МКТ
	if ($("div.calc_2").length > 0) {
		$.getScript(jScriptsAddress + "/forms.numeric.js", function () {
			$("input" + numericMainClass).each(numeric.init);
		});
		$.getScript(jScriptsAddress + "/forms.real.js", function () {
			$("input" + realMainClass).each(real.init);
		});
		$.getScript(jScriptsAddress + "/calc-2.js");
	}

	// Заявка
	if ($("div.request").length > 0) {
		$.getScript(jScriptsAddress + "/forms.asterisk.js", function () {

			$("input" + astriskMainClass + ", select" + astriskMainClass).each(asterisk.init);

			$("div.whole-phone").each(asterisk.whole_phone);
			$("div.whole-phone-2").each(asterisk.whole_phone);

			$.getScript(jScriptsAddress + "/forms.numeric.js", function () {
				$("input" + numericMainClass).each(numeric.init);
			});

			$.getScript(jScriptsAddress + "/forms.real.js", function () {
				$("input"+realMainClass).each(real.init);
			});

			$.getScript(jScriptsAddress + "/request.js", function () {
				request.init();
			});
		});
	}

	if ($.browser.mozilla || $.browser.opera && $('table.panel').length > 0) {
		ShiftPaddingCopyright();
		$(window).resize(function () {
			ShiftPaddingCopyright();
		});
	}
	
	// Галерея
	$("a.photoThumb").click(function(){
		$("div.photoThumb").css("border-color","black");
		$(this).parent("div.photoThumb").css("border-color","#666");
		$("img#largeThumb").attr("src","/download/files/images2/"+$(this).attr("photoID")+"_mid.jpg");
		$("a#firstLink").attr("link","/download/files/images2/"+$(this).attr("photoID")+".jpg");
		return false;
		});
		
	$("a#firstLink").click(function(){	
		$("a[href="+$(this).attr("link")+"]").click();
		return false;
		});
		
//	тогглер деревень в тарифах
	
	$("a#villageToggler").click(function(){
		if($(this).text() == "показать все направления"){
			$("table.priceList tr.nonTerminal").removeClass("hidden");
			$(this).text("показать только основные направления");
			}else{
			$(this).text("показать все направления");
			$("table.priceList tr.nonTerminal").addClass("hidden");
			}
		});

});

function ShiftPaddingCopyright () {
	var h = parseInt($('table.panel').css('height'), 10);
	if (h > 440) {
		var add = h - 440;
		$('div.copyright').css('padding-top', 215 + add);
	}
}
