var last_act, last_menu;

function Poisk() {
  alert ("ok");
}

function Menu(a, id) {

  if ( !a && id ) {
    $('#content').css({ opacity: '0.5' });

    $.post("/load_content.php",
      {
        parent: id
      },
      function(data) {
        $('#content').html(data);
        $('#content').css({ opacity: '1' });
      }
    );
  }

  if ( a > 0 && last_act == a) {
    // Отдельный цвет для "Поиск"
    if ( a == 4 ) $('#mmenu' + a).css({background:"#ededed"}); else $('#mmenu' + a).css({background:"#c3ccd3"});

    $('div.submenu' + last_act).animate({height: "hide"}, 600);
    last_act = 0;
    return;
  }

  if (a > 0 && last_act != a) {
    if (id) {

      $('#content').css({ opacity: '0.5' });

      $.post("/load_content.php",
        {
          parent: id
        },
        function(data) {
          $('#content').html(data);
          $('#content').css({ opacity: '1' });
        }
      );

    }

    if (last_act) {
      // Отдельный цвет для "Поиск"
      if ( last_act == 4 ) $('#mmenu' + last_act).css({background:"#ededed"}); else $('#mmenu' + last_act).css({background:"#c3ccd3"});
      $('div.submenu' + last_act).animate({height: "hide"}, 600);
    }

    last_act = a;
  }

  // Отдельный цвет для "Поиск"
  if ( a == 4 ) $('#mmenu' + a).css({background:"#FFF"}); else $('#mmenu' + a).css({background:"#ededed"});

  $('div.submenu' + a).animate({height: "show"}, 600);
  $('#menu_vert').ScrollTo(500);
}



function Show_Content(id, search) {

  if (!search) search = "";
  if (last_menu != id) {
    $('#menu_link' + last_menu).css('font-weight', 'normal');
    $('#menu_link' + id).css('font-weight', 'bold');
    last_menu = id;
  }

  $('#content').css({ opacity: '0.5' });

  $.post("/load_content.php",
    {
      parent: id,
      search: search
    },
    function(data) {
      $('#content').html(data);
      $('#content').css({ opacity: '1' });
      if (id != 1 ) {
        $('#menu_vert').ScrollTo(500);
      }
    }
  );
}



function Set_Money(money, id) {
  $.get("/set_money.php?money="+money);
  Show_Content(id);
}




//////////////////// scroll ////////////////////////////////////////////////////////////////////////////
jQuery.getPos = function (e)
{
	var l = 0;
	var t  = 0;
	var w = jQuery.intval(jQuery.css(e,'width'));
	var h = jQuery.intval(jQuery.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
jQuery.getClient = function(e)
{
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};
jQuery.getScroll = function (e) 
{
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else  {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};

jQuery.intval = function (v)
{
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};

jQuery.fn.ScrollTo = function(s) {
	o = jQuery.speed(s);
	return this.each(function(){
		new jQuery.fx.ScrollTo(this, o);
	});
};

jQuery.fx.ScrollTo = function (e, o)
{
	var z = this;
	z.o = o;
	z.e = e;
	z.p = jQuery.getPos(e);
	z.s = jQuery.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};

