// JavaScript Document
//adds IE specific hover actions to discovery education's pre-login drop down menu
//07.28.2008 :: amaro - anthony_maro@discovery.com

subAction = function() {
	var sfEls = document.getElementById("subNav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" subAction";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" subAction\\b"), "");
		}
		
		//get all sub nav items and attach hover actions
		if (sfEls[i].className == 'subs') {
			sfEls[i].onmouseover=function() {
				this.className="subHover";
			}
			sfEls[i].onmouseout=function() {
				this.className="subs";
			}
		}
		if (sfEls[i].className == 'topLink') {
			sfEls[i].onmouseover=function() {
				this.className="topHover";
			}
			sfEls[i].onmouseout=function() {
				this.className="topLink";
			}
		}
		
		
	}
	
}




subLinks = function() {
	var sfEls = document.getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].className == 'topLink') {
			sfEls[i].id = 'subs' + [i];			
			
			
			/*add hover states to top level links when no dropdown is present*/
			sfEls[i].onmouseover=function() {
				this.className="topHover";
			}
			sfEls[i].onmouseout=function() {
				this.className="topLink";
			}
			
			
			/*get the href value of the link within li and place onclick on whole li*/
			sfEls[i].onclick=function() {
			var Ln = this.getElementsByTagName("a");
			var firstLn = Ln[0];
			var Dest = firstLn.href;
			
				if (firstLn.target == '_blank'){/*open new window if _blank*/
				window.open(Dest,"blank");
				return false;
					} else {/*change window location*/
				window.location.href = Dest;	
				return false;
				}
				}
			
			
		/*get the href value of the link within li and place onclick on whole li*/	
		} else if (sfEls[i].className == 'subs') {
			sfEls[i].id = 'subs' + [i];
			
			sfEls[i].onclick=function() {
			var Ln = this.getElementsByTagName("a");
			var firstLn = Ln[0];
			var Dest = firstLn.href;	
			
				if (firstLn.target == '_blank'){/*open new window if _blank*/
				//alert(Dest);
				window.open(Dest,"blank");
				return false;
					} else {/*change window location*/
				window.location.href = Dest;	
				return false;
				}
				}
			
		}
		
	}
}







/*attach events for ie*/
if (window.attachEvent) {
//IE and Opera
window.attachEvent("onload", subAction);
} 



/*attach event for all and check to be sure we're not stepping on other onloads*/
addLoadEvent = function(func) { 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      if (oldonload) { 
	        oldonload(); 
	      } 
	      func(); 
	    } 
	  } 
	} 
	 
addLoadEvent(subLinks);
