function set_action_subcat(div_id, link_location, action)
{
	var div_cat_object = $(div_id);
	
	switch(action)
	{
		case "over":
		//set_class_general(div_cat_object,'menu_top_sub_cat_over');
		break;
		
		case "out":
		//set_class_general(div_cat_object,'menu_top_sub_cat_out');
		break;
		
		case "click":
		window.location = link_location;
		break;
	}
}


function set_class_general(element_obj,new_class_name)
{
	element_obj.setAttribute("class", new_class_name);
	element_obj.setAttribute("className", new_class_name);
}


delay = 105;

i = 0;
do_not_hide = "";
menu_array = Array();



// ----- Popup Control ---------------------------------------------------------

function at_display(x)
{
  win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- Show Aux -----

function at_show_aux(parent, child, width_left)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  var top  = (c["at_position"] == "y") ? p.offsetHeight : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth - 217 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top-1 +'px';
  c.style.left       = left-20+'px';
  c.style.visibility = "visible";
}

// ----- Show -----
i = 0;
function at_show()
{//if you go over a menu, you show all it's children.
//if the menu you are over is a subchild, you should also show it's grandfather.
  p = document.getElementById(this["at_parent"]);
  p_li = document.getElementById(this["at_parent"]+"_li");
  //set_class_general(p_li,'moduleRowOver');
  c = document.getElementById(this["at_child" ]);
  i++;
  at_show_aux(p.id, c.id, 1);

/*
  if (p.id == "menu_subcat_1_name_3" || p.id == "menu_cat_1_names" || p.id == "menu_subcat_1_3	")
  {
    at_show_aux("menu_cat_1", "menu_cat_1_names");
	do_not_hide = "menu_cat_1_names";
	document.getElementById("debug").innerHTML += i+"|it should also show menu_cat"+"<br>";

	main_cat = document.getElementById("menu_cat_1");
	  clearTimeout(main_cat["at_timeout"]);
  }
  else
  {
	do_not_hide = "";
  }
*/
//  document.getElementById("debug").innerHTML += "<tr><td>"+this.id+":"+"at_show</td><td>:"+i+"|</td><td>"+c["at_position"] +"|</td><td>parent:"+p.id+"|</td><td>child:"+c.id+"</td><br>";

//  document.getElementById("debug").innerHTML += i+"|"+"at_show:"+"|"+this.id+":"+c["at_position"] +"|parent:"+p.id+"|child:"+c.id+"<br>";

  clearTimeout(c["at_timeout"]);
}

// ----- Show Grandson -----

function at_show_grandson()
{//if you go over a menu, you show all it's children.
//if the menu you are over is a subchild, you should also show it's grandfather.
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  g1 = document.getElementById(this["at_grandparent1"]);
  g2 = document.getElementById(this["at_grandparent2"]);

  at_show_aux(g1.id, g2.id, 150);

  clearTimeout(g2["at_timeout"]);

  at_show_aux(p.id, c.id, 150);

i++;
// document.getElementById("debug").innerHTML += i+"|"+"at_show_grandson:"+"|"+this.id+":"+c["at_position"] +"|grandparent1:"+g1.id+"|grandparent2:"+g2.id+"|parent:"+p.id+"|child:"+c.id+"<br>";


  clearTimeout(c["at_timeout"]);
}

// ----- Hide -----

function at_hide()
{//if you get out of a menu, you close all it's children
	i++;
	p = document.getElementById(this["at_parent"]);
	p_li = document.getElementById(this["at_parent"]+"_li");
	//set_class_general(p_li,'moduleRow');
	
	c = document.getElementById(this["at_child"]);

	c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", delay);

  
//  document.getElementById("debug").innerHTML += i+"|"+"at_hide:"+"|"+this.id+":"+c["at_position"]+"|parent:"+p.id+"|child:"+c.id+"<br>";

}

// ----- Hide Grandson -----
function at_hide_grandson()
{//if you get out of a menu, you close all it's children
  c = document.getElementById(this["at_child"]);
  p = document.getElementById(this["at_grandparent2"]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", delay);
  p["at_timeout"] = setTimeout("document.getElementById('"+p.id+"').style.visibility = 'hidden'", delay);
}

// ----- Click -----

function at_click()
{
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id, "1");
  else c.style.visibility = "hidden";

  return false;
}

// ----- Attach -----

// PARAMETERS:
// parent   - id of visible html element
// child    - id of invisible html element that will be dropdowned
// showtype - "click" = you should click the parent to show/hide the child
//            "hover" = you should place the mouse over the parent to show
//                      the child
// position - "x" = the child is displayed to the right of the parent
//            "y" = the child is displayed below the parent
// cursor   - Omit to use default cursor or check any CSS manual for possible
//            values of this field

function at_attach(parent, child, showtype, position, cursor)
{
  p = document.getElementById(parent);
  c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {

    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}

function at_attach_sub(grand_parent1, grand_parent2, parent, child, showtype, position, cursor)
{
  p = document.getElementById(parent);
  c = document.getElementById(child);

  p["at_grandparent1"]     = grand_parent1;
  p["at_grandparent2"]     = grand_parent2;
  c["at_grandparent1"]     = grand_parent1;
  c["at_grandparent2"]     = grand_parent2;
  
  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;

  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {

    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show_grandson;
      c.onmouseout  = at_hide_grandson;
      break;
  }
}
