$(function() {

  $("#mainmenu li").hover(function() {
    $("ul:first", this).show();
  }, function() {
    $("ul:first", this).hide();
  });

});

function preloadImg(image) {
  var img = new Image();
  img.src = image;
}

function getAbsolutePos(el) {
  var r = { x: el.offsetLeft, y: el.offsetTop };
  if (el.offsetParent) {
    var tmp = getAbsolutePos(el.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
}

var n=0;

function hover(obj) {obj.style.backgroundColor="#dedede";}
function hout(obj) {obj.style.backgroundColor="#eee5df";}

function over(obj) {obj.style.backgroundColor="#4162B1";}
function out(obj) {obj.style.backgroundColor="#2A4B9A";}
function over2(obj) {obj.style.backgroundColor="#f0f0ff";}
function out2(obj) {obj.style.backgroundColor="#e0e0ef";}
function over3(obj) {obj.style.backgroundColor="#f3f2f7";}
function out3(obj) {obj.style.backgroundColor="#ffffff";}

function showpic(title, path) {
  var pic=window.open('', 'photo', 'width=500,height=400,menubar=no,scrollbar=no');
  pic.document.open();
  content='<html><head><script language="JavaScript">function keyDown(){key=window.event.keyCode;if (key==27) {window.close()};}document.onkeydown = keyDown;</script><title>'+title+'</title><body topmargin=1 leftmargin=1 marginwidth=1 marginheight=1 bgcolor=white text=#800000 style="font: 11px tahoma; cursor: default;"><center><img src="http://news.ya1.ru/pictures/'+path+'" id="pic" onload="window.resizeTo(this.width+12,this.height+60)"><br>'+title+'</center></body></html>';
  pic.document.writeln(content);
  pic.focus();
}

var curmenu=0;

function show(name, ref, lvl) {
  if (!lvl) lvl = "189px";
//  alert($(ref).offset().top);
  $("#"+name).css("left",lvl).css("top",$(ref).offset().top-1+"px").show();
/*  .hover(function() {
    show2($(this).attr("id"));
  }, function() {
    hide($(this).attr("id"));
  });
*/  
  if (ref!=0) curmenu=ref;
  if (curmenu) curmenu.style.backgroundColor="#4162B1";
}

function show2(name) {
  $("#"+name).show();
  if (curmenu) curmenu.style.backgroundColor="#4162B1";
}

function hide(name) {
  $("#"+name).hide();
  if (curmenu) curmenu.style.backgroundColor="#2A4B9A";
}

