var hide_timer = null;

// --- element pozice Y --------------------------------------------------
  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
// -----------------------------------------------------------------------

// --- element pozice X --------------------------------------------------
  function findPosX(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.x;
    return curtop;
  }
// -----------------------------------------------------------------------

function get_height() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth
|| document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth ||
document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function sizeto(num, size ,destsize)
{
  elem = document.getElementById("menu" + num);

  elem.style.height = (size) + "px";

  if (size < destsize - 30)
    x = 20;
  else
    x = (destsize - size) / 5;

  if (x < 1) x = 1;

  if (size + 1 < destsize) 
  {
    setTimeout('sizeto('+num+', '+(size+x)+', '+destsize+')', 10);
    return;
  }

//  hide_timer = setTimeout("hide_menu("+num+")", 1000);
}

// --- zjisti vertikalni pozici obsahu okna ------------------------------
function get_scroll_pos()
{   
  if (navigator.appName.indexOf("Microsoft") != -1)
    return window.document.documentElement.scrollTop;
  else
    return window.pageYOffset;
}
// ------------------------------------------------------------------------


function show_menu(obj, num)
{
  for( i = 0; i < 10; i++)
  {
    elem = document.getElementById("menu"+i);
    if (elem) elem.style.display = "none";
  }

  elem = document.getElementById("menu"+num);

  obj = document.getElementById(price_id);

  x = findPosX(obj);
  y = findPosY(obj);

  height = get_height();

  if (height < 560) 
    myTop = 0;
  else
    myTop = (height - 560) / 2;


  myTop = myTop + get_scroll_pos();

  elem.style.left = (x-180)+"px";
  elem.style.top = myTop+"px";

  elem.style.height = "0px";
  elem.style.display = "block";
  sizeto(num, 0, 560);
}

function hide_menu(num)
{
  clearTimeout(hide_timer);  
  hide_timer = null;
  elem = document.getElementById("menu"+num);
  elem.style.display = "none";
}

function clear_hide_timer(num)
{ 
  if (hide_timer != null)
  {
    clearTimeout(hide_timer);
    hide_timer = null;
  }
}

function set_hide_timer(num)
{
  hide_timer = setTimeout("hide_menu("+num+")", 200);
}


function repaint_atributes()
{
  suma = cena;
  suma_alt = cena_alt;

  jmeno = "";
  first = true;

  for(i=0; i <10; i++)
  {
    elem2 = document.getElementById("menu"+i);
    if (elem2)
    {
      elem = document.getElementById("output"+i);
      if (elem)
      { 
        elem.innerHTML = selected[i] + " " + prices[i] + " " + mena;
        if (mena_alt != "")        
          elem.innerHTML += " / " + prices_alt[i] + " " + mena_alt;
      }
      suma = suma + prices[i];
      suma_alt += prices_alt[i];

      if (first) 
      {
        jmeno = jmeno + selected[i] + " " + prices[i] + " " + mena;
        if (mena_alt != "")
        	jmeno += " / " + prices_alt[i] + " " + mena_alt;
        first = false;
      }
      else
      {
        jmeno = jmeno + ", " + selected[i] + " " + prices[i] + " " + mena;
        if (mena_alt != "")
        	jmeno += " / " + prices_alt[i] + " " + mena_alt;        
      }

      elem = document.getElementById("vybrano"+i);
      elem.value = indexes[i];

    }
  }

  if (first) jmeno="---";

  elem = document.getElementById(price_id);

  elem.innerHTML = suma;

  elem = document.getElementById("suma");

  elem.value = suma;

  elem = document.getElementById("mena");

  elem.value = mena;

  elem = document.getElementById("name");

  elem.value = jmeno;
  
  if (mena_alt != "")
  {
	  elem = document.getElementById("sumaAlt");
	
	  elem.value = suma_alt;
	
	  //alert(suma_alt);
	
	  elem = document.getElementById("menaAlt");
	
	  elem.value = mena_alt;
  }
}

function select_item(obj, menu, price, price_alt, text, index)
{
//  alert(obj.innerHTML);
  selected[menu] = text;
  prices[menu] = price;
  prices_alt[menu] = price_alt;
  indexes[menu] = index;
  repaint_atributes();
  elem = document.getElementById("menu"+menu);
  elem.style.display = "none";
}

function color(obj)
{
  obj.style.backgroundColor = "#235b47";
  obj.style.color = "#ffffff";
}

function white(obj)
{
  obj.style.backgroundColor = "#e0e0e0";
  obj.style.color = "#000000";
}

function checkValues()
{
	for(i=0;i<indexes.length;i++)
	{
		if (indexes[i] == -1)
		{
			alert("Nevzvolili jste všechny vlastnosti zboží!");
			return false;
		}
	}
	
	return true;
}
