$(function() {
    if ($("#authlink").length > 0) {
    } else {
     $('.nav li:last').hide();
     $('.nav li:last').css('display', 'none'); 
    }
	indexPage();
	$(window).bind('resize', function() { indexPage(); });
	
	$("#pane1").jScrollPane();
	var setC = function() {
		$("#pane1").jScrollPane();
	}
	$(window).bind('resize', setC);
	
	$("#gal1 a").click(function() {
		var th = $(this);
		$("#bigPhoto img").fadeOut("slow", function() {
			var img = new Image();
			$(img).load(function() {
				$(this).hide();
				$("#bigPhoto img").remove();
				$("#bigPhoto").append(this);
				$("#bigPhoto a").attr("href", th.attr("rel"));
				$(this).fadeIn("slow");
			}).attr("src", th.attr("href"));
		});
		return false;
	});
	
	$(".gal2thumbs a").click(function() {
		var th = $(this);
		$("#bigPhoto2 img").fadeOut("slow", function() {
			var img = new Image();
			$(img).load(function() {
				$(this).hide();
				$("#bigPhoto2 img").remove();
				$("#bigPhoto2").append(this);
				$(this).fadeIn("slow");
			}).attr("src", th.attr("href"));
		});
		$(".gal2thumbs li").show();
		$(this).parent().hide();
		return false;
	});
	
	$("a.pict").lightBox();
	$("a.lbox").lightBox();
	$("a.lbox_plan").lightBox();
	$("a.lbox_nonav").lightBox({fixedNavigation:"off"});
	$(".fla").lightBox({"fla":true});
});

function indexPage() {
	var w = parseInt($("#root").width());
	var marg = 0;
	if (w < 1160) {
		// $(".tree").hide(); //
		marg = -(1160-w)/3;
		$(".bg_l").css("margin-left", marg+"px");
		$(".bg_r").css("margin-right",marg+"px");
		$(".bg_rt").css("margin-right",marg+"px");
		if ($("#index").length > 0) {
			$(".col1").css("width","22%");
		}
		$("body").css("background-position", marg+"px 0");
	} else {
		marg=0;
		bgpos = $("#root").offset().left;
		$(".tree").show();
		$(".bg_l").css("margin-left", marg+"px");
		$(".bg_r").css("margin-right", marg+"px");
		$(".bg_rt").css("margin-right",marg+"px");
		if ($("#index").length > 0) {
			$(".col1").css("width","22%");
		}
		$("body").css("background-position", bgpos+"px 0");
	}
}

function calc() {
	var c_num = "-1";
	var c_pr1;
	var c_fund;
	var c_type = 0;
	var c_mat = 0;
	$("select[name='num']").val("-1").change(function() {
		c_num = $("option:selected", $(this)).val();
		if (c_num != "-1") {
			c_pr1 = lots[$("option:selected", $(this)).text()][1];
			c_fund = lots[$("option:selected", $(this)).text()][0];
		}
		count(c_num, c_pr1, c_fund, c_type, c_mat);
	});
	$("select[name='type']").val(0).change(function() {
		c_type = $("option:selected", $(this)).val();
		count(c_num, c_pr1, c_fund, c_type, c_mat);
	});
	$("select[name='material']").val(0).change(function() {
		c_mat = $("option:selected", $(this)).val();
		count(c_num, c_pr1, c_fund, c_type, c_mat);
	});

	// added by Pavel after removing first element in select id=materials
	$("select[name='material']").val(1).change();
	$("div.calc").prependTo("div.col2");
	$("div.calc").css("left", "-640px");
	$("div.calc").css("position", "absolute");
	$("div.calc").css("top", "93px");
	$("div.calc").css("top", "93px");
	$("div.calc").css("height", "8px");
	// end added
}
function count(c_num, c_pr1, c_fund, c_type, c_mat) {
	if (c_num == "-1" || c_type == 0 || c_mat == 0) {
		$(".calc .sum").text("");
	} else if (c_fund == 0 || !houses[c_type] || !houses[c_type][c_mat] || !houses[c_type][c_mat][c_fund]) {
		$(".calc .sum").html("Цена <div>по запросу</div>");
	} else {
		var c_sum = c_pr1 + houses[c_type][c_mat][c_fund];
		$(".calc .sum").html("Цена <div>"+c_sum+"</div>рублей");
	}
}




/*var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
function flash_DoFSCommand(command, args) {
	var flashObj = isInternetExplorer ? document.all.flash : document.flash;
}

if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub flash_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call flash_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
function sayFlash_Z(id) {
	$(".house").removeClass("blk");
	$("#zone"+id).addClass("blk");
}
function sayFlash(id) {
	$(".house").removeClass("blk");
	$("#house"+id).addClass("blk");
}

function houseInf(id) {
	$(".house").removeClass("blk");
	$("#house"+id).addClass("blk");
}*/


