var wyb_menu = '';

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function show_menu_oferta()
{
  x=findPosX(document.getElementById("menu_oferta"))-45;
  y=findPosY(document.getElementById("menu_oferta"))+18;
  document.getElementById("subm_oferta").style.width='176px';
  document.getElementById("subm_oferta").style.height='260px';
  document.getElementById("subm_oferta").style.left=x+'px';
  document.getElementById("subm_oferta").style.top=y+'px';
  document.getElementById("subm_oferta").style.visibility='visible';
  document.getElementById("subm_oferta").style.position='absolute';
  wyb_menu='oferta';
}

function show_menu_nokia()
{
  x=findPosX(document.getElementById("menu_nokia"))+177;
  y=findPosY(document.getElementById("menu_nokia"));
  document.getElementById("subm_nokia").style.width='176px';
  document.getElementById("subm_nokia").style.height='40px';
  document.getElementById("subm_nokia").style.left=x+'px';
  document.getElementById("subm_nokia").style.top=y+'px';
  document.getElementById("subm_nokia").style.visibility='visible';
  document.getElementById("subm_nokia").style.position='absolute';
  wyb_menu='nokia';
}

function show_menu_nawigacja()
{
  x=findPosX(document.getElementById("menu_nawigacja"))+177;
  y=findPosY(document.getElementById("menu_nawigacja"));
  document.getElementById("subm_nawigacja").style.width='176px';
  document.getElementById("subm_nawigacja").style.height='100px';
  document.getElementById("subm_nawigacja").style.left=x+'px';
  document.getElementById("subm_nawigacja").style.top=y+'px';
  document.getElementById("subm_nawigacja").style.visibility='visible';
  document.getElementById("subm_nawigacja").style.position='absolute';
  wyb_menu='nawigacja';
}

function show_menu_tomtom()
{
  x=findPosX(document.getElementById("menu_tomtom"))+177;
  y=findPosY(document.getElementById("menu_tomtom"));
  document.getElementById("subm_tomtom").style.width='176px';
  document.getElementById("subm_tomtom").style.height='60px';
  document.getElementById("subm_tomtom").style.left=x+'px';
  document.getElementById("subm_tomtom").style.top=y+'px';
  document.getElementById("subm_tomtom").style.visibility='visible';
  document.getElementById("subm_tomtom").style.position='absolute';
  wyb_menu='tomtom';
}

function menuhover(Object)
{
  if (Object.className == "smenu")
    Object.className="smenuh";
    else if (Object.className == "smenuh")
      Object.className="smenu";
}

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        cursor.x = e.clientX + 
            (document.documentElement.scrollLeft || 
            document.body.scrollLeft) - 
            document.documentElement.clientLeft;
        cursor.y = e.clientY + 
            (document.documentElement.scrollTop || 
            document.body.scrollTop) - 
            document.documentElement.clientTop;
    }
    return cursor;
}

function hide_menu(e)
{
  var kursor=getPosition(e);
  if(wyb_menu == 'oferta')
    {
//    obj=document.getElementById("subm_oferta");
//    if ((kursor.x < (parseInt(obj.style.left) - 20)) || (kursor.x > (parseInt(obj.style.left) + parseInt(obj.style.width) + 20)) || (kursor.y < (parseInt(obj.style.top) - 20)) || (kursor.y > (parseInt(obj.style.top) + parseInt(obj.style.height) + 20)))
//      obj.style.visibility='hidden';
    hide_oferta(kursor.x, kursor.y);
    }
    else if(wyb_menu == 'nokia')
    	{
hide_nokia(kursor.x, kursor.y);
//
    }
    else if(wyb_menu == 'nawigacja')
    	{
hide_nawigacja(kursor.x, kursor.y);
//
    	}
    	else if(wyb_menu == 'tomtom')
    		{
//     		obj=document.getElementById("subm_tomtom");

//    		   
    		  hide_tomtom(kursor.x, kursor.y);
    		}
}

function hide_oferta(x,y)
{
  obj=document.getElementById("subm_oferta");
  if ((x < (parseInt(obj.style.left) - 20)) || (x > (parseInt(obj.style.left) + parseInt(obj.style.width) + 20)) || (y < (parseInt(obj.style.top) - 20)) || (y > (parseInt(obj.style.top) + parseInt(obj.style.height) + 20)))
    {
    obj.style.visibility='hidden';
    wyb_menu='';
    }
}

function hide_nawigacja(x,y)
{
  obj=document.getElementById("subm_nawigacja");
  if (((x < (parseInt(obj.style.left) - 20)) || (x > (parseInt(obj.style.left) + parseInt(obj.style.width) + 20)) || (y < (parseInt(obj.style.top) - 20)) || (y > (parseInt(obj.style.top) + parseInt(obj.style.height) + 20)))
     && (!(document.getElementById("menu_nawigacja").className == "smenuh")))
    {
    obj.style.visibility='hidden';
    wyb_menu='oferta';
    hide_oferta(x,y);
    }
}

function hide_nokia(x,y)
{
  obj=document.getElementById("subm_nokia");
  if (((x < (parseInt(obj.style.left) - 20)) || (x > (parseInt(obj.style.left) + parseInt(obj.style.width) + 20)) || (y < (parseInt(obj.style.top) - 20)) || (y > (parseInt(obj.style.top) + parseInt(obj.style.height) + 20)))
     && (!(document.getElementById("menu_nokia").className == "smenuh")))
    {
    obj.style.visibility='hidden';
    wyb_menu='oferta';
    hide_oferta(x,y);
    }
}

function hide_tomtom(x, y)
{
  obj=document.getElementById("subm_tomtom");
  if (((x < (parseInt(obj.style.left) - 20)) || (x > (parseInt(obj.style.left) + parseInt(obj.style.width) + 20)) || (y < (parseInt(obj.style.top) - 20)) || (y > (parseInt(obj.style.top) + parseInt(obj.style.height) + 20)))
     && (!(document.getElementById("menu_tomtom").className == "smenuh")))
    {
    obj.style.visibility='hidden';
    wyb_menu='nawigacja';
    hide_nawigacja(x,y);
    }
}

function menu_init()
{
  document.onmousemove = hide_menu;
}
