var is_ie=false; var ie6=false; var ie7=false; var ie8=false;
if (document.all && !window.opera) { is_ie=true; 
	if (navigator.userAgent.indexOf("MSIE 6") >= 0) {ie6=true;}
	if (navigator.userAgent.indexOf("MSIE 7") >= 0) {ie7=true;}
	if (navigator.userAgent.indexOf("MSIE 8") >= 0) {ie8=true;}
}

var bst = 0;
var lastclass='bg_p1';

var jsnlfr=10; // при запросе новостей - с какой
var jsnlkv=10; // при запросе новостей - сколько




$(window).load(function(){
	slofix();
});

$(function(){
	
	$(".port_link").live("click",function(){
		$(".port_link1").attr("class","port_link").parent().next().next().hide();
		$(this).attr("class","port_link1");
		$(this).parent().next().next().show();
		return false;	
	});

	$(".port_link1").live("click",function(){
		$(this).attr("class","port_link");
		$(this).parent().next().next().hide();
		return false;	
	});

	
	
	$(".next_page").click(function(){
		//tmp = this.id;
		//tmp2 = tmp.split("_");
		
		$(this).before("<div class='tmp_al'><img src='/design/lb/lightbox-ico-loading.gif' alt='' /></div>");
		//$(this).remove();
		
		$.post("/system/plugins/news.php",{a:"ajax_get_news",rt:'0',from:jsnlfr,kolvo:jsnlkv},function(data){
			$(".tmp_al").before($(data).find("html").text());
			$(".tmp_al").remove();
			jsnlfr = jsnlfr + jsnlkv;
			
			if ($(data).find("mp").text()=='false') {
				$(".next_page").remove();
			}
			
		},"xml");
		
		return false;
	});
	
	$(".lbhere a").lightBox();
	
	$(".show_map").live("click",function(){
		$(".hide_map").attr("class","show_map").parent().next().hide();
		$(this).parent().next().show();
		$(this).attr("class","hide_map");
		return false;
	});
	
	$(".hide_map").live("click",function(){
		$(this).parent().next().hide();
		$(this).attr("class","show_map");
		return false;
	});
		
	
	msel_focus_pocus();

	$("#pult2").append("<div id='p0'></div><div id='p_p'></div><div id='p1'></div><div id='p2'></div><div id='p3'></div><div id='p4'></div><div id='p5'></div><div id='p6'></div><div id='p7'></div><div id='p8'></div><div id='p9'></div>");
	
	$("#pult2 div").click(function(){

		if ($("#b").hasClass("bg_off")){
			$("#mc, #h, .squares, #ft").show();
			$("#b").height("auto");
			$("#f").css({position: "relative"});
			if (this.id=='p_p') {
				$("#b").attr("class",lastclass);
			} else {
				$("#b").attr("class","bg_"+this.id);
			}
			window.scrollTo(0,bst);
			return;
		}
		
		lastclass = $("#b").attr("class");
		$("#b").attr("class","bg_"+this.id);

		if ($("#b").hasClass("bg_p_p")){
				
			bst = getBodyScrollTop();
			$("#b").attr("class","bg_off");
			$("#mc, #h, .squares, #ft").hide();
			
			if (getClientWidth()<1150) {$("#b").addClass("bg_off1");} else {$("#b").addClass("bg_off2");}

			$("#b").height(getClientHeight()+"px");
			$("#f").css({position: "absolute", bottom:"0", left:"0"});
		} 
				
		
		
/*		
			if ($("#b").hasClass("bg_p_p") && this.id!='p_p') {
				$("#mc, #h, .squares").hide();
				$("#b").height("800px");
				$("#f").css({position: "absolute", bottom:"0", left:"0"});
			}
			if ($("#b").hasClass("bg_p_p") && this.id=='p_p'){
				$("#mc, #h, .squares").show();
				$("#b").height("auto");
				$("#f").css({position: "relative"});
			}*/
	});

/*	
.bg_p_p #mc {display: none;}
.bg_p_p .squares {display: none;}
.bg_p_p #h {display: none;}
.bg_p_p #f {position: absolute !important; bottom:0; left:0;}
.bg_p_p .offtable {display: block;}
*/	
	
	
	$("#pult2 div").hover(function(){
		if ($("#"+this.id+"h").length<=0) {
			$("#pult2").append("<div class='p_sel' id='"+this.id+"h'></div>");
			off = $(this).position();
			$("#"+this.id+"h").css({top:off.top+"px",left:off.left+"px"});
			$("#pult2").pngFix();
		} else {
			$("#"+this.id+"h").stop().css("opacity","1");
		}
	},function(){
		if (is_ie) {
			$("#"+this.id+"h").remove();
		} else {
			$("#"+this.id+"h").fadeOut("200", function(){
				$(this).remove();
			});
		}
	});

});






$(window).resize(function(){slofix();});

function slofix() {
	x = getClientWidth(); y = "slo slo1";
	if (x>1100) { y = "slo slo2"; }
	if (x>1200) { y = "slo slo3"; }
	$(".slo").attr("class",y);
	$(document).pngFix();
}






function msel_focus_pocus() {
	

	if ($(".mm_home").length>0) { $("#m li:eq(0)").addClass("msel"); $(".squares").css("display","block"); } else {$(".squares").remove();}
	if ($(".mm_novosti").length>0) { $("#m li:eq(1)").addClass("msel"); }
	if ($(".mm_okompanii").length>0) { $("#m li:eq(2)").addClass("msel"); }
	if ($(".mm_katalog").length>0) { $("#m li:eq(3)").addClass("msel"); }
	if ($(".mm_price").length>0) { $("#m li:eq(4)").addClass("msel"); }
	
	if ($("#fbform").length>0) { $("#m li:eq(5)").addClass("msel"); }
	
	if ($(".mm_portfolio").length>0) { $("#m li:eq(6)").addClass("msel"); }
	if ($(".mm_kontakty").length>0) { $("#m li:eq(7)").addClass("msel"); }
	if ($(".mm_aktsii").length>0) { $("#m li:eq(8)").addClass("msel"); }


	at = $(".msel a").html();
	al = $(".msel a").attr("href");
	$(".msel").html("<span class='msel1'></span><span class='msel2'><span class='mse3'><a href='"+al+"'>"+at+"</a></span></span><span class='msel4'></span>");
	
	
}




























function getBodyScrollTop(){
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getClientWidth(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}







