    var ua = navigator.userAgent.toLowerCase();
    isIE = (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1);
    var k = 0;
    var oldh = 0;
    var cur_w = 0;

    function cbChange(cbid){
      var lab = document.getElementById(cbid + 'lab');
      lab.className = document.getElementById(cbid).checked ? '':'cb_nosel';
    }

    function inpFocus(idinp) {
      var lab = document.getElementById(idinp);
      var inpArray = lab.getElementsByTagName('input');
      if (inpArray[0].value=='') {
        var spanArray = lab.getElementsByTagName('span');
        spanArray[0].style.display = 'none';
      }
    }

    function toggleSender(){
      var sender = document.getElementById('sender');
      var st = document.getElementById('sender_toggler');
      if (sender.style.display == 'none'){
        sender.style.display = '';
        st.className = 'pressed';
        if (isIE) {
          var maw = document.getElementById('maint').clientWidth;
          var mah = document.getElementById('maint').clientHeight;
          oldh = k*maw;
          k = mah/maw;
          var nh = k*maw;
          var new_height = nh - 135;
          document.getElementById('banners').style.height = new_height;
        }
      } else {
        sender.style.display = 'none';
        st.className = '';
        if (isIE) {
          var maw = document.getElementById('maint').clientWidth;
          k = oldh/maw;
          var nh = k*maw;
          var sh = sender.clientHeight;
          var new_height = nh - 135;
          document.getElementById('banners').style.height = new_height;
          document.getElementById('maint').style.height = nh;
        }
      }
    }
    
    var button_state = 'disabled';
    
	function set_button_state(state) {
		switch (state) {
			case 'active':
				$(".button").css("background-position","left -0px");
			break;
			case 'hover':
				$(".button").css("background-position","left -38px");
			break;
			case 'pressed':
				$(".button").css("background-position","left -76px");
			break;
			case 'disabled':
				$(".button").css("background-position","left -114px");
			break;
		}
		button_state = state;
	}
	
	function check_button_enable() {
		if (($("#edit_phone").val().length)&&($("#edit_fio").val().length)) {
			set_button_state('active');
		} else {
			set_button_state('disabled');
		}
	}
    
    $(window).resize(function(){
      
      set_client_window();
      
    });
    
    function set_client_window() {
      //Окно для клиента
      pos = $("span.clients_link").position();
      $("#client_window").css('left',pos.left-110);
      $("#client_window").css('top',pos.top+50);		
	}
    
	$(document).ready(function(){
	  // Your code here...
		
		if (document.getElementById('portfolio_move')) {
			put_items();
		}
		
		//$("#ymap").animate({"height": "toggle"}, { duration: "slow" });
		
		set_client_window();
		
		$("span.clients_link").click(function() {
			$('#client_window').animate({"height": "show"}, { duration: "slow" });
		});
		
		$("#close_client").click(function() {
			$('#client_window').animate({"height": "toggle"}, { duration: "slow" });
		});
		
		//setTimeout('$("#ymap").css("height","auto"); $("#ymap").hide();',1000);
		
		$("#map_show a").click(function(e) {
			mapshow();
			//$("#ymap").animate({"height": "toggle"}, { duration: "slow" });
			map.redraw();
			//alert(e.target);
			return false;
		});
		
		$(".variant").click(function(e) {
			id = $(this).attr('id');
			$('.modernul span').addClass("variant");
			$('#t'+id+' span').removeClass("variant");
			$('.modern_content').hide();
			$('#d'+id).show();
		});
		
		$('#tv1 span').removeClass("variant");
		
		$("#edit_phone").keypress(function (e) {
			c = String.fromCharCode(e.which);
			re = /[-0-9\(\)\s,.;]/;
			found = c.match(re);
			if (!found) {
				return false;
			}
		});
		
		$("#edit_phone").keyup(function () {
			if ($("#edit_phone").val().length) {
				$("#phone_star").text("");
			} else {
				$("#phone_star").text("*");
			}
			check_button_enable();
		});
		
		$("#edit_fio").keypress(function (e) {
			c = String.fromCharCode(e.which);
			//re = /[\w|^\d]/i;
			re = /[-0-9\(\),.;\!\:\?\\@#$%^&*+=\"№\/{}~]/;
			found = c.match(re);
			if (found) {
				return false;
			}
		});
		
		$("#edit_fio").keyup(function () {
			if ($("#edit_fio").val().length) {
				$("#fio_star").text("");
			} else {
				$("#fio_star").text("*");
			}
			check_button_enable();
		});
		
		$(".button").mouseover(function(){
			if (button_state!='disabled') {
				set_button_state('hover');
			}
		});
		
		$(".button").mouseout(function(){
			if (button_state!='disabled') {
				set_button_state('active');
			}
		});
		
		$(".button").mousedown(function(){
			if (button_state!='disabled') {
				set_button_state('pressed');
				document.forms['post'].submit();
			}
		});
		
		$(".button").mouseup(function(){
			if (button_state!='disabled') {
				if (button_state=='pressed') {
					set_button_state('hover');
				} else {
					set_button_state('active');
				}
			}
		});
		
	});
    
	function put_items() {
		w = $('.items').width();
		wc = 275;
		itemscount = Math.floor(w/wc);
		new_w = Math.floor(w/itemscount)-2;
		$('.item').css('width',new_w+'px');
	}
	
	$(window).resize(function(){
		put_items();
	});

    if (isIE) {
      $(window).resize(function(){
		if (document.getElementById('portfolio_move')) {
			put_items();
		}
        var nw = document.getElementById('maint').clientWidth;
        var nh = k*nw;
        var new_height = nh-135;
        if (cur_w < nw){
          document.getElementById('banners').style.height = new_height;
          document.getElementById('maint').style.height = nh;
        } else {
          document.getElementById('banners').style.height = new_height;
        }
        cur_w = nw;
      });

      $(document).ready(function(){
		if (document.getElementById('portfolio_move')) {
			put_items();
		}
        var maint = document.getElementById('maint');
        var cur_w = maint.clientWidth;
        var mainth = maint.clientHeight;
        k = mainth/cur_w;
//        alert(k);
        var new_height = mainth-135;
        document.getElementById('banners').style.height = new_height;
    	});
    }

