/* =Load Functions
-----------------------------------------------------------------------------*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(menuMan);
addLoadEvent(png);
addLoadEvent(doNewWin);
addLoadEvent(menu);
addLoadEvent(manMap);
addLoadEvent(buttonOver);
//addLoadEvent(dlColor);

/* =List Striper'
-----------------------------------------------------------------------------*/
function dlColor(){
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById("appointments")) return false;
	var page = document.getElementById("appointments");
	var dls = page.getElementsByTagName('dl');
	for(i=0; i<dls.length; i++){
		var dds = dls[i].getElementsByTagName("dd");
		var onOff = false;
		for(j=0; j<dds.length; j++){
			if(onOff == true){
				dds[j].className="odd";
				onOff=false;
			}
			else if (onOff == false){
				onOff=true;
			}
		}
	}
}


/* =Menu Man
-----------------------------------------------------------------------------*/
function menuMan(){
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	if (!document.createElement) return false;
	if (!document.getElementById("home")) return false;
	if (!document.getElementById("hurt")) return false;

	// Load Images
	imageObj = new Image();
	image = new Array(
	'images/bodyArms.png',
	'images/bodyBack.png',
	'images/bodyBack2.png',
	'images/bodyHead.png',
	'images/bodyLegs.png',
	'images/bodyLegs2.png',
	'images/bodySholders.png');
	for(i=0; i<image.length; i++){
		imageObj.src=image[i];
	}
	
	// Build Guy
	var guyMenu = document.getElementById("hurt");
	var li = guyMenu.getElementsByTagName("li");
	var parent = guyMenu.parentNode;
	var newDiv = document.createElement("div");
	newDiv.setAttribute("id","guy");
	var newImg = document.createElement("img");
	newImg.setAttribute("alt","Where Does It Hurt?");
	newImg.setAttribute("src","");
	newImg.setAttribute("width","305");
	newImg.setAttribute("height","280");
	newDiv.appendChild(newImg);
	insertAfter(newDiv,guyMenu);
	
	var guy = document.getElementById("guy");
	
	// Change Guy Image On Menu Mouseover
	for (i=0; i<li.length; i++) {
		li[i].onmouseover=function(){
			guy.className="over";
			if(guy.firstChild.nodeName=="IMG"){ 
				guy.firstChild.src="images/body"+this.firstChild.rel+".png";
			}
			// If IE 6 or IE 5.5, Do a bunch of crazynes to make png work
			var arVersion = navigator.appVersion.split("MSIE")
			var version = parseFloat(arVersion[1])
			if ((version >= 5.5 && version <= 6.99) && (document.body.filters)){
				// If a png change to a span with AlphaImageLoader filter
				if(guy.firstChild.nodeName=="IMG"){
					// Switch Image to the one you moused over
					guy.firstChild.src="images/body"+this.firstChild.rel+".png";
					// change image to a span
					var imgName = guy.firstChild.src.toUpperCase()
					if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
						var imgID = (guy.firstChild.id) ? "id='" + guy.firstChild.id + "' " : ""
						var imgClass = (guy.firstChild.className) ? "class='" + guy.firstChild.className + "' " : ""
						var imgTitle = (guy.firstChild.title) ? "title='" + guy.firstChild.title + "' " : "title='" + guy.firstChild.alt + "' "
						var imgStyle = "display:inline-block;" + guy.firstChild.style.cssText 
						var strNewHTML = "<span " + imgID + imgClass + imgTitle
						+ " style=\"" + "width:" + guy.firstChild.width + "px; height:" + guy.firstChild.height + "px;" + imgStyle + ";"
						+ " filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'images/body" + this.firstChild.rel + ".png', sizingMethod='scale');\"></span>";
						guy.innerHTML = strNewHTML;
					}
				}
				// If a span change filter src
				else if(guy.firstChild.nodeName=="SPAN") {
					guy.firstChild.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'images/body"+this.firstChild.rel+".png\', sizingMethod='scale')";
				}
			}
		}
		// Hide Guy On Mouseout
		li[i].onmouseout=function(){
			guy.className="";
		}
	}
}
/* =Man page change
-----------------------------------------------------------------------------*/
function manMap(){
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById("bodyMap")) return false;
	var bodyMap = document.getElementById("bodyMap");
	var imap = document.getElementById("hurtMap");
	var points = imap.getElementsByTagName("area");
	for(j=0; j<points.length; j++){
		points[j].onmouseover=function(){
			bodyMap.src="images/hurt"+this.alt+".jpg";
		}
		points[j].onmouseout=function(){
			bodyMap.src="images/hurt"+bodyMap.name+".jpg";
		}
	}
	imageObj = new Image();
	image = new Array(
	'images/hurtArms.jpg',
	'images/hurtBack.jpg',
	'images/hurtBack2.jpg',
	'images/hurtHead.jpg',
	'images/hurtLegs.jpg',
	'images/hurtLegs2.jpg',
	'images/hurtSholders.jpg');
	for(i=0; i<image.length; i++){
		imageObj.src=image[i];
	}
}

/* =InsertAfter
-----------------------------------------------------------------------------*/
function insertAfter(newElement,targetElement) { 
  var parent = targetElement.parentNode; 
  if (parent.lastChild == targetElement) { 
    parent.appendChild(newElement); 
  } else { 
    parent.insertBefore(newElement,targetElement.nextSibling); 
  } 
}

/* =IE Support
-----------------------------------------------------------------------------*/
function png(){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5 && version <= 6.99) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}
	// Load Nav Rollover
	imageObj = new Image();
	image = new Array(
	'images/navbg.png',
	'images/navbgx.png');
	for(i=0; i<image.length; i++){
		imageObj.src=image[i];
	}

}
function menu(){
	if (document.all&&document.getElementById) {
		var navRoot = document.getElementById("nav").firstChild;
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
function buttonOver(){
	if(!document.all) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("news")) return false;
	var button = document.getElementById("news");
	button.onmouseover=function(){
		button.className="over";
	}
	button.onmouseout=function(){
		button.className="";
	}
}

/* =Open a new window
-----------------------------------------------------------------------------*/
function doNewWin() {
  if (!document.getElementsByTagName) return false;
  var links=document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].title.match("Opens in a New Window")) {
      links[i].onclick=function() {window.open(this.href);return false;
      }
    }
  }
}
