window.addEvent('domready', function(){

    
	if (document.getElementById('homePage')) {homeTheme();}
	toggleAnswer();
});






function Menu() {
	this.timeout = null;
	this.togglers = null;
	this.wrappers = null;
	this.accordion = null;
	this.ELEMENT_NODE = 1;
	this.level = 0;

	this.init = function() {
		this.togglers = [];
		this.wrappers = [];
		this.ELEMENT_NODE = 1;
		this.level = 0;
		var me = this;
		if (document.getElementById("rollover")) {
			// build top level nav list
			var list = [];
			var temp = document.getElementById("rollover").childNodes;
            var len = temp.length;
			for (var i = 0; i < len; i++) {
				if (temp[i].nodeType == this.ELEMENT_NODE) {
					if (temp[i].tagName.toLowerCase() == "li") {
						list.push(temp[i]);
					}
                    if (i == (len-2)) { temp[i].style.background = "none"; }
				}
			}
			for (var i = 0; i < list.length; i++) {
				// set mouse over and out events for top level navigation points
				list[i].onmouseover = function() { me.over(this); }
				list[i].onmouseout = function() { me.out(this); }

				var dropDown = list[i].getElementsByTagName("div");
				if (dropDown.length == 1) {
					if (dropDown[0].className == "dropDown") {
						dropDown[0].onmouseout = function() { me.out(this); } // set mouse out for drop down wrapper
						// handle submenus
						this.subMenuInit(dropDown[0]);
					}
				}
			}
			// set accordian attributes on submenus
			this.accordion = [];
			for (var i = 0; i < this.togglers.length; i++) {
				this.accordion.push(new Fx.Accordion(this.togglers[i], this.wrappers[i], {
					show: navPersist(),
					onActive: function(tog) {
												tog.getElementsByTagName("a")[0].className = "selected";
												var children = tog.childNodes;
												var len = children.length;
												for (var i=0;i<len;i++) {
													if (children[i].className == "accordion") {children[i].style.marginBottom="10px";}
												}
											},
					onBackground: function(tog) {
													tog.getElementsByTagName("a")[0].className = 'has_dd';
													var children = tog.childNodes;
													var len = children.length;
													for (var i=0;i<len;i++) {
														if (children[i].className == "accordion") {children[i].style.marginBottom="0px";}
													}												
												},
				    duration: 400
				}));
			}
			if (this.togglers.length == 0) {navPersist();}
		}		
	} // end of init
	this.subMenuInit = function(obj) {
		// create reference to subnav if it exists
		var ul = null;
		var temp = obj.childNodes;
		for (var i = 0; i < temp.length; i++) {
			if (temp[i].nodeType == this.ELEMENT_NODE) {
				if (temp[i].tagName.toLowerCase() == "ul") {
					ul = temp[i]; break;
				}
			}
		}
		if (ul != null) {
			if (obj.className.indexOf("dropDown") < 0) {				
				if (ul.parentNode.className.indexOf('lastItem') > -1) {
					ul.parentNode.className = "has_dd lastItem"
				} else {
					ul.parentNode.className = "has_dd"; // indicate anchor is anchor for LI toggler
				}
				// save references to togglers and subnav menu wrappers for accordion functionality
				if (this.togglers.length <= this.level) {
					this.togglers.push([]);
					this.wrappers.push([]);
				}
				this.togglers[this.level].push(obj);
				this.wrappers[this.level].push(ul);
				this.level++;
			}
			// create new list of togglers from subnav
			var list = [];
			var temp = ul.childNodes;
			for (var i = 0; i < temp.length; i++) {
				if (temp[i].nodeType == this.ELEMENT_NODE) {
					if (temp[i].tagName.toLowerCase() == "li") {
						list.push(temp[i]);
					}
				}
			}
			for (var i = 0; i < list.length; i++) {				
				this.subMenuInit(list[i]); // do this function again for each toggler in subnav menu
			}
			if (obj.className.indexOf("dropDown") < 0) { this.level--; }
		} 
		return;
	} // end of subMenuInit

	this.over = function(obj) {
		//These commands will hide the utility nav
		if (document.getElementById('subnav')) {
            var subnav = document.getElementById('subnav').getElementsByTagName('*');
    		var len = subnav.length;
    		for (var i=0;i<len;i++) {
    			if (subnav[i].tagName == 'UL' && (subnav[i].getAttribute('id') != '' && subnav[i].getAttribute('id') !=null)) {
    				subnav[i].style.visibility = "hidden";
    			} else if (subnav[i].tagName == 'LI' && (subnav[i].getAttribute('id') != '' && subnav[i].getAttribute('id') !=null)) {
    				subnav[i].style.backgroundColor = "#FFF";
    				subnav[i].getElementsByTagName("a")[0].className = 'noDrop';
    			}
    		}
        }
		if (this.timeout != null) { window.clearTimeout(this.timeout); }
		this.hideOthers(obj);
		this.showSub(obj);		
	} // end of over

	this.out = function(obj) {
		if (this.timeout != null) { window.clearTimeout(this.timeout); }
		var me = this;
		this.timeout = window.setTimeout(bind(me, me.delayedHide, obj), 100);
	} // end of out

	this.delayedHide = function(obj) {
		if (obj.className.indexOf("rolloverLink") == 0) {
			// moused out of top level navigation point
			this.hideThis(obj);
			obj.className = "rolloverLink";
		} else {
			// moused out of wrapper for all sub navs of top level navigation point
			this.hideThis(obj.parentNode);
			obj.parentNode.className = "rolloverLink";
		}
	} // end of delayedHide

	this.hideOthers = function(obj) {
		if (obj.id.indexOf("menu") == 0) { 
			var list = obj.parentNode.childNodes;
			for (var i = 0; i < list.length; i++) {
				if (list[i].nodeType == this.ELEMENT_NODE) {
					if (list[i].tagName.toLowerCase() == "li" && list[i] != obj) {
						if (list[i].className.indexOf("on") > -1) {
							list[i].className = "rolloverLink";
							this.hideThis(list[i]);
						}
					}
				}
			}
		}
	} // end of hideOthers

	this.hideThis = function(obj) {
		var dropDown = obj.getElementsByTagName("div");
		if (dropDown.length == 1) {
			if (dropDown[0].className.indexOf("on") > -1) {
				// hide drop down wrapper
				dropDown[0].className = "dropDown";
			}
		}
	} // end of hideThis

	this.showSub = function(obj) {
		if (obj.id.indexOf("menu") == 0) {
			obj.className = "rolloverLink on";
			var dropDown = obj.getElementsByTagName("div");
			if (dropDown.length == 1) {
				if (dropDown[0].className == "dropDown") {
					// show drop down wrapper
					dropDown[0].className = "dropDown on";
				}
			}
		}
	} // end of showSub
	if (window.ie6) {
		var doc = document.getElementById('rollover').getElementsByTagName('a');
		var len = doc.length;
		for (var i=0;i<len;i++) {
			if (!doc[i].getAttribute('href')) {
				doc[i].href = 'javascript:void(0);'				
			}
		}
	}
} // end of Menu

function homeTheme() {
	if (undefined !== window.themes) {
		var obj = eval(themes);	
		var body = document.body;
		var objs = [];
		var len = obj.obj.length;
		for (var i=0;i<len;i++)
			objs[obj.obj[i].id] = obj.obj[i];
		var altHome = ['home','altHome','blueHome','purpleHome'];
		var random = Math.floor((Math.random()) * 8);
		var flashUrls = ['flash1','flash2','flash3'];
		var flashRand = Math.floor((Math.random()) * 7);
		var flash;
		var ele1 = document.createElement('img');
		var ele2 = document.createElement('img');
		switch(random) {
			case 0: 
				flash = ((objs.green_theme[flashUrls[flashRand]] || objs.green_theme.flash1) + obj.param);
				ele1.src = objs.green_theme.header1;
				ele2.src = objs.green_theme.header2;
				body.style.backgroundColor = '#ffffff';
				break;
			case 1: 
				flash = ((objs.orange_theme[flashUrls[flashRand]] || objs.orange_theme.flash1) + obj.param);
				ele1.src = objs.orange_theme.header1; 
				ele2.src = objs.orange_theme.header2; 
				body.style.backgroundColor = '#ffffff';
				break;
			case 2: 
				flash = ((objs.blue_theme[flashUrls[flashRand]] || objs.blue_theme.flash1) + obj.param);
				ele1.src = objs.blue_theme.header1;
				ele2.src = objs.blue_theme.header2;
				body.style.backgroundColor = '#ffffff';				
				break;
			case 3: 
				flash = ((objs.purple_theme[flashUrls[flashRand]] || objs.purple_theme.flash1) + obj.param);
				ele1.src = objs.purple_theme.header1;
				ele2.src = objs.purple_theme.header2;
				body.style.backgroundColor = '#ffffff';
				break;
			case 4: 
				flash = ((objs.red_theme[flashUrls[flashRand]] || objs.red_theme.flash1) + obj.param);
				ele1.src = objs.red_theme.header1;
				ele2.src = objs.red_theme.header2;
				body.style.backgroundColor = '#ffffff';
				break;
			case 5: 
				flash = ((objs.black_theme[flashUrls[flashRand]] || objs.black_theme.flash1) + obj.param);
				ele1.src = objs.black_theme.header1;
				ele2.src = objs.black_theme.header2;
				body.style.backgroundColor = '#ffffff';
				break;
			case 6: 
				flash = ((objs.blacklight_theme[flashUrls[flashRand]] || objs.blacklight_theme.flash1) + obj.param);
				ele1.src = objs.blacklight_theme.header1;
				ele2.src = objs.blacklight_theme.header2;
				body.style.backgroundColor = '#ffffff';
				break;
			case 7: 
				flash = ((objs.darkgreen_theme[flashUrls[flashRand]] || objs.darkgreen_theme.flash1) + obj.param);
				ele1.src = objs.darkgreen_theme.header1;
				ele2.src = objs.darkgreen_theme.header2;
				body.style.backgroundColor = '#ffffff';
				break;
		}
		body.className = altHome[random];		
		writeSWF('flashContainer',flash,707,323);

	}
}

function navPersist() {
    var accordion = document.getElementById('navigation').getElementsByTagName('*');
	var len = accordion.length;
	var loc = window.location.toString();
	if (loc.substr((loc.length-1),(loc.length)) != '/') {loc += '/'};	
    var me;
    var curHref;
    var count = 0;
    var j = 0;
    var open = -1;       
	for (var i=0;i<len;i++) {
		//Sets an id on all accordion ul's, which we'll use later when we detect which accordion to  have open
		if (accordion[i].className == 'accordion') {			
            accordion[i].setAttribute('id','a' + count);
            count++
		}
		//Highlights the actual page in the navigation
		if (accordion[i].href) {
			var accHref = accordion[i].href;
			if (accHref.substr((accHref.length-1),(accHref.length)) != '/') {accHref += '/';}
			if (accordion[i].tagName=='A' && accHref==loc && j==0) {
	            curHref = accordion[i];
	            me = accordion[i];
	            me.setAttribute('id', 'bottomLvl');
	            while(me.className !== 'parentRoll') {me = me.parentNode;}
	            while (curHref.className !== 'accordion') {
	                if (curHref.className == 'navigationList') {break;}
	                curHref = curHref.parentNode;
	            }
	            me.getElementsByTagName('span')[0].className += ' menuSelect';//Sets hightlight of current parent item in main nav
	            j++
	        }
		}
	}
    if (curHref) {open = curHref.id.split('a')[1] || -1;}   
    return parseInt(open);
}

function toggleAnswer() {
	var el = null;
	if (document.getElementById && (el = document.getElementById("faq"))) {
		var list = el.childNodes;
		for (var i=0; i < list.length; i++) {
			list[i].onclick = function(e) {
				e = e || window.event;
				var targEle = e.target || e.srcElement;
				if (targEle.tagName == "A")return true;
				else setDisplay(this);
			};
			list[i].onmouseover = function() {
				this.style.backgroundColor = "#dff0fb";	
				this.style.color = "#003399";
			};
			list[i].onmouseout = function() {
				this.style.backgroundColor = "#ffffff";
				this.style.color = "#80b3cc";
				if ((this.className == "over") || (this.className == "last over")) {
					this.style.backgroundColor = "#dff0fb";	
					this.style.color = "#003399";
				}
			};
		}
	}
}  

function setDisplay(ele) {
	if (ele.className == "" || ele.className=="over") {ele.className==""?ele.className="over":ele.className="";} 
    else {ele.className=="last"?ele.className="last over":ele.className="last";}
}

function writeSWF(id,path,width,height) {
	document.getElementById(id).innerHTML = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"flash-grow_vars\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\"" +  path +  "\"<param name=\"quality\" value=\"high\" />	<param name=\"wmode\" value=\"transparent\" /><param name=\"flashvars\" value=\"" + path + "\"<embed src=\"" + path + "\"quality=\"high\" wmode=\"transparent\" width=\"" + width + "\" height=\"" + height + "\" name=\"aiu flash-grow_vars\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object>";
}

var inmenu=false;
var lastmenu=0;

function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

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;
}

function utilMenu(current) {
   if (!document.getElementById) return;
   inmenu=true;
   oldmenu=lastmenu;
   lastmenu=current;
   if (oldmenu) Erase(oldmenu);
   //This will hide the main navigation
   var mainNav = document.getElementById('rollover').childNodes;
   for (var i=0;i<mainNav.length;i++) {
		if (mainNav[i].tagName == "LI") {
			mainNav[i].className = "rolloverLink";			
		}
   }
   //
   m=document.getElementById("menu-" + current);
   box=document.getElementById(current);
      if (box.className == "subnav_drop") {
   		m.style.backgroundColor="#0080CC";
   		m.style.color="#FFFFFF";
   		xPos = findPosX(m);
   		yPos = findPosY(m) + m.offsetHeight;
   } else {
   		m.style.backgroundColor="#5A008C";
   		xPos = m.offsetLeft + document.getElementById("nav").offsetLeft;
		if (document.all) {
			xPos += 40;  //quick fix for IE horiz positioning
		}
   		yPos = m.offsetBottom;
   }
	box.style.visibility="visible";
	box.style.left = xPos+"px";
	box.style.top = yPos+"px";
	var anchor =  m.getElementsByTagName("a")[0];
	anchor.className = "change";
}

function Erase(current) {
   if (!document.getElementById) return;
   if (inmenu && lastmenu==current) {
     return;
   }
   m=document.getElementById("menu-" + current);
   box=document.getElementById(current);
   if (box.className == "subnav_drop") {
   		m.style.backgroundColor="#FFFFFF";
   		m.style.color="#0080CC";
   } else {
   		m.style.backgroundColor="#410066";
   }
   box.style.visibility="hidden";
   var anchor =  m.getElementsByTagName("a")[0];
	anchor.className = "";
}

function Timeout(current) {
   inmenu=false;
    window.setTimeout("Erase('" + current + "')",100);
}

