function HeadSearchClick(inp,w) {
  if(w && inp.value == 'Keresés') inp.value = '';
  if(!w && inp.value == '') inp.value = 'Keresés';
}

function FindPos(obj) {
	var curleft = curtop = 0;
  if (obj.offsetParent) {
  do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
      } while (obj = obj.offsetParent);
  }
	return [curleft,curtop];
}


var ActiveDD = null;
var ShowDropdownTimer = new Array();
var HideDropdownTimer = new Array();

function ShowDropDown(id,sender) {
  if(HideDropdownTimer[id]) {
    clearTimeout(HideDropdownTimer[id]);
  }

  ShowDropdownTimer[id] = setTimeout(function () { DoShowDorpDown(id, sender); }, 50);
}

function HideDropDown(id,sender) {
  if(ShowDropdownTimer[id]) {
    clearTimeout(ShowDropdownTimer[id]);
  }

  HideDropdownTimer[id] = setTimeout(function () { DoHideDropDown(id, sender); }, 500);
}

function DoShowDorpDown(id,sender) {
  if(ActiveDD && ActiveDD != id) {
    DoHideDropDown(ActiveDD)
  }
  
  if(sender) {
    SenderPos = FindPos($(sender));
    dd = $('submenu'+id);

    dd.style.display = '';
    dd.style.top = '121px';
    dd.style.left = SenderPos[0]+'px';
  }

  ActiveDD = id;
}

function DoHideDropDown(id,sender) {
  $('submenu'+id).style.display = 'none';
}

function numericTest(e){
    var key = e.keyCode? e.keyCode : e.charCode
    if((key > 47 && key < 58) || key == 8 || key == 37 || key == 39 || key == 13 || key == 46) {
        return true;
    }
    else return false;
}

function MenuOver(menu) {
   m = menu.style.backgroundImage.match(/menu_([0-9]+).jpg/)[1];
   menu.style.backgroundImage = 'url(/image/menupic/'+((menu.className == 'active' ? 'ahover':'hover'))+'/menu_'+m+'.jpg)';
}

function MenuOut(menu) {
   m = menu.style.backgroundImage.match(/menu_([0-9]+).jpg/)[1];
   menu.style.backgroundImage = 'url(/image/menupic/'+((menu.className == 'active' ? 'active':'def'))+'/menu_'+m+'.jpg)';
}


var mvd = 50;

function ProductsOver(id,p,out) {
  mvd2 = (out) ? -mvd:mvd;

  if(p != 4) {
    w = $('prod'+p).getDimensions().width;
    if(p != 1) w -= 25;
    $('prod'+p).style.width = w+mvd2+'px';
  }
  else {
    for(i = 2; i <= 3; i++) {
      w = $('prod'+i).getDimensions().width;
      if(i != 1) w -= 25;
      //$('prod'+i).style.width = w-parseInt(mvd2/2)+'px';
      $('prod'+i).style.left = parseInt($('prod'+i).style.left)-(mvd2)+'px';
    }
    
    //$('header').innerHTML = $('prod3').style.left;
    $('prod'+p).style.left = parseInt($('prod4').style.left)-mvd2+'px';
    $('prod'+p).style.width = $('prod'+p).getDimensions().width-25+mvd2+'px';

    //$('header').innerHTML = $('prod3').style.left;
  }


  //$('p')

  /*
  mvd2 = (out) ? -mvd:mvd;

  $('header').innerHTML = mvd2+"  "+out+"<br>";

  mv = 0;
  for(i = 1; i<=p; i++) {
    if(i < p) {
      w = $('prod'+i).getDimensions().width;
      if(i != 1) w -= 25;
      w = w-(i*mvd2);
      mv += (i*mvd2);
      //$('prod'+i).style.width = w+'px';
      if(i !=1 ) $('prod'+i).style.left = parseInt($('prod'+i).style.left)-(i*mvd2)+'px';
    }
  }

  w = $('prod'+p).getDimensions().width;
  if(p != 1) w -= 25;
  $('prod'+p).style.width = w+mv+'px';
  
  $('prod'+p).style.left = parseInt($('prod'+p).style.left)-mv+'px';
  //alert(parseInt($('prod'+p).style.left)+' '+mv+' '+$('prod'+p).style.left);
  */
}

ProductMenu = {
  GrayDiv: null,
  Clicked: 0,

  Over: function(i) {
    if(i != ProductMenu.Clicked) $('prod'+i).style.zIndex = '250';
    ProductMenu.GrayDiv = document.createElement('div');
    //ProductMenu.GrayDiv.setAttribute('class', 'gray');
    $(ProductMenu.GrayDiv).addClassName('gray');
    //GrayDiv = AddDiv('prodgray', 'gray', '');
    ProductMenu.GrayDiv.style.position = "absolute";
    ProductMenu.GrayDiv.style.width = '747px';
    ProductMenu.GrayDiv.style.height = '567px';
    ProductMenu.GrayDiv.style.top = '0px';
    ProductMenu.GrayDiv.style.left = '0px';
    ProductMenu.GrayDiv.style.zIndex = '240';
    $('products_list').appendChild(ProductMenu.GrayDiv);
  },

  Out: function(i) {
    if(i != ProductMenu.Clicked) $('prod'+i).style.zIndex = 200-i;
    $(ProductMenu.GrayDiv).remove();
  },

  Click: function(id,i) {
    new Ajax.Updater('submenus', '/products/?mod=ajax&id='+id);
    ProductMenu.Clicked = i;
    for(j=1;j<=4;j++)
       $('prod'+j).style.zIndex =  200-j;
    $('prod'+i).style.zIndex = '245';

  }
}

function AddDiv(Id,Class,Display) {
  d = $(Id);
  if (!d)  {
    d = document.createElement('div');
    d.setAttribute('id', Id);
    $(d).addClassName(Class)
    //d.setAttribute('class', Class);
    //d.className = Class;
    d.style.display = Display;
    document.body.insertBefore(d, document.body.firstChild);
  }
  else {
    d.style.display = Display;
  }
  return d;
}

function OpenWord(id) {
  new Effect.toggle($('word-'+id), 'slide', { delay: 0 });
}

Lang = {
  Over: function(Img,Lang,Obj) {
    $('lang_name').innerHTML = Lang;
    $(Obj).style.backgroundImage = 'url(/image/langs/'+Img+')';
  }
}
