/**
* En la primera parte estan las funciones de la version viejita de nice_menus.js por que la ultima no funciono bien con IE6
* En la segunda parte estan las funciones heredadas de drupal para complementar el funcionamiento en IE6
*/




// $Id: nice_menus.js,v 1.1.2.2 2006/08/06 10:16:20 jakeg Exp $

// We only do the javascript in IE.
// TODO: because we now only include the js file for IE, is this 'if' redundant?
if (document.all) {

  // 20100201 - jmartinez@nexura.com
  function lanzadorIEHoverPseudo(){
	IEHoverPseudo('menuHeader');
	
	IEHoverPseudo('niceComunas');
	IEHoverPseudo('niceMenusFooter');
	IEHoverPseudo('niceMenusDSP');
	IEHoverPseudo('niceOficina1');
	IEHoverPseudo('niceOficina2');
	IEHoverPseudo('niceOficina3');
	IEHoverPseudo('niceOficina4');
	IEHoverPseudo('niceOficina5');
	IEHoverPseudo('enlaceMenu');
  } // lanzadorIEHoverPseudo
  
  function IEHoverPseudo(elemento) {

    //var ulNodes = getElementsByClass("nice-menu");
    /*var j = 0;
    var liNodes = null;

    for (var i = 0; i < ulNodes.length; i++) { 
      liNodes = ulNodes[i].getElementsByTagName("li");
      for (j = 0; j < liNodes.length; j++) {
        if (hasClass(liNodes[j], 'menuparent')) {
          liNodes[j].onmouseover=function() { addClass(this, 'over'); }
          liNodes[j].onmouseout=function() { removeClass(this, 'over'); }
        }
      }
    }*/
		var ulNodes = getElement(elemento);
		if(!ulNodes) return;
		var firstChildNode = null;
		
		if(ulNodes != null) firstChildNode=ulNodes.firstChild;
		//firstChildNode=ulNodes.firstChild;
		
		
		
		if(firstChildNode != null){
			var node1=firstChildNode;
			
			for (i=0; i<1;){
				string2='';
				if(node1 != null){
					if (node1.nodeName == "LI"){
						if(hasClass(node1, 'menuparent')){
							node1.onmouseover=function() { addClass(this, 'over'); }
							node1.onmouseout=function() { removeClass(this, 'over'); }
						} // if
					} // if
					node1=node1.nextSibling;
				} // if
				else i=1;
			} // for
		} // if
  } // IEHoverPseudo

  function getElementsByClass(searchClass,node,tag) {
	  var classElements = new Array();
	  if (node == null) node = document;
	  if (tag == null) tag = '*';
	  var els = node.getElementsByTagName(tag);
	  var elsLen = els.length;
	  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); //RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	  for (i = 0, j = 0; i < elsLen; i++) {
		  if (pattern.test(els[i].className)) {
			  classElements[j] = els[i];
			  j++;
		  }
	  }
	
	  return classElements;
  }

  // This is the Drupal method of adding a function to the BODY onload event.  (See misc/drupal.js)
  //addLoadEvent(IEHoverPseudo);
  addLoadEvent(lanzadorIEHoverPseudo); // 20100201 - jmartinez@nexura.com
}








/**
 * Adds a function to the window onload event
 */
function addLoadEvent(func) {
	window.onload=windowOnload(window.onload, func);
  /*var oldOnload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      oldOnload();
      func();
    };
  }*/
}


/**
 * Returns true if an element has a specified class name
 */
function hasClass(node, className) {
  if (node.className == className) {
    return true;
  }
  var reg = new RegExp('(^| )'+ className +'($| )')
  if (reg.test(node.className)) {
    return true;
  }
  return false;
}

/**
 * Adds a class name to an element
 */
function addClass(node, className) {
  if (hasClass(node, className)) {
    return false;
  }
  node.className += ' '+ className;
  return true;
}

/**
 * Removes a class name from an element
 */
function removeClass(node, className) {
  if (!hasClass(node, className)) {
    return false;
  }
  // Replaces words surrounded with whitespace or at a string border with a space. Prevents multiple class names from being glued together.
  node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className);
  return true;
}

/**
 * Emulate PHP's ereg_replace function in javascript
 */
function eregReplace(search, replace, subject) {
  return subject.replace(new RegExp(search,'g'), replace);
}

