//Rob's craaaaazy code!
//Test for Mozilla because I KNOW some things work in it but am not sure if they work in Safari/etc...
//This picks up all Mozilla based browsers including FireFox.
var Mozilla = navigator.appName.indexOf("Netscape") != -1;

<!--############################################ Blend functions #############################################//-->

<!-- Function to convert from hex to 255 rgb array -->
function convertFromHex (hexColor) {
	hexColor = hexColor.substr(1);
	redValue = parseInt(hexColor.substr(0, 2), 16);
	greenValue = parseInt(hexColor.substr(2, 2), 16);
	blueValue = parseInt(hexColor.substr(4, 2), 16);
	
	rgbArray = new Array(redValue, greenValue, blueValue);
	return rgbArray;
}

<!-- Function to convert from rgb string to rgb array -->
function convertFromString (rgbString) {
	rgbString = rgbString.substring(rgbString.indexOf("(") + 1, rgbString.length - 1);
	
													 
	redValue = parseInt(rgbString.substring(0, rgbString.indexOf(",")));
	gbString = rgbString.substr(rgbString.indexOf(",") + 1);
	greenValue = parseInt(gbString.substring(0, gbString.indexOf(",")));
	bString = gbString.substr(gbString.indexOf(",") + 1);
	blueValue = parseInt(bString);
	
	rgbArray = new Array(redValue, greenValue, blueValue);
	
	return rgbArray;
}

<!-- Function to convert from rgb array to hex String -->
function convertToHex (rgbArray) {
	outputArr = new Array();
	for (q=0; q < 3; q++) {
		hexValue = rgbArray[q].toString(16);
		if (hexValue.length == 1) {
			hexValue = "0" + hexValue;
		} else if (hexValue.length == 0) {
			hexValue = "00";
		}
		outputArr.push(hexValue);
	}
	
	//redValue = rgbArray[0].toString(16);
	
	//greenValue = rgbArray[1].toString(16);
	//blueValue = rgbArray[2].toString(16);
	
	hexValue = "#" + outputArr.join("");
	
	return hexValue;
}


<!-- Function to blend two colour values together -->
function colorBlend (colorA, colorB, blendAmount) {
	
	if (colorA.indexOf("#") == 0) {
		
		//Hex color value
		Argb = convertFromHex(colorA);
	} else if (colorA.indexOf("rgb") == 0) {
		//RGB String (used by Mozilla)
		
		Argb = convertFromString(colorA);
	}
	
	if (colorB.indexOf("#") == 0) {
		//Hex color value
		Brgb = convertFromHex(colorB);
	} else if (colorB.indexOf("rgb") == 0) {
		//RGB String (used by Mozilla)
		Brgb = convertFromString(colorB);
	}
	
	
	
	//Now blend the color values
	newColorArr = new Array();
	//Loop over r, g, b array
	for (var f=0;f < 3; f++) {
		newColorValue = 0;
		if (Argb[f] > Brgb[f]) {
			
			newColorValue = Argb[f] - ((blendAmount / 100) * (Argb[f] - Brgb[f]));
		} else {
			
			newColorValue = Argb[f] + ((blendAmount / 100) * (Brgb[f] - Argb[f]));
			
		}
		//document.write (newColorValue + "<br/>")
		newColorArr[f] = Math.round(newColorValue);
	}
	
	
	blendedColor = convertToHex(newColorArr);
	
	return blendedColor;
}

//Done Rob's crazzzy code!

<!-- Paste this snippet into your existing code  -->



function getElementsByAttribute(aAttribute,aValue,aInElement) {
	var ElementVerifier;
	var Elements=new Array();

	
	function SearchElement(aElement)
	{
		
		if(aElement==null||aElement==undefined)return
		if(ElementVerifier(aElement))
		{
			
			Elements[Elements.length]=aElement;
		}
		

		SearchElement(aElement.firstChild);
		if (aElement != aInElement) {
			SearchElement(aElement.nextSibling);
		}
	}
	
	
	if(aInElement==undefined)aInElement=document.body;

	
	if (aValue) {
		str="if(Element.getAttribute('"+aAttribute+"')=='"+aValue+"'){return true;}else{return false}";
	} else {
		str="if(Element.hasAttribute('"+aAttribute+"')){return true;}else{return false}";
	}
	ElementVerifier=function(aElement)
	{

	
		if(aElement.nodeType != 1)return false;
		
		//var E=new Function(str);
		
		if (aValue) {
			//Special case for stupid IE taht doesn't consider classes as attributes...
			if (aAttribute == "class") {
				if (aElement.className == aValue) {
					return true;
				} else {
					return false;
				}
			
			}
			
			if(aElement.getAttribute(aAttribute)==aValue){
				
				return true;
			} else {
				return false;
			}
		} else {
			if (aElement.hasAttribute(aAttribute)) {
				return true;
			} else {
				return false;
			}
		}
	}
	
	SearchElement(aInElement);
	return Elements;
}



function showHide(e) {
	if (!e) e = window.event;
	

	if (!e.target) {
		e.target = e.srcElement;
	}
	
	//Close any open nav eles
	var navEles = getElementsByAttribute("class", "sec1", document.getElementById("holder"));
	for (var i in navEles) {
		var thisNavEle = navEles[i];
		var thisNavEleSub = getElementsByAttribute("name", "sub", thisNavEle);
		if (thisNavEleSub.length != 1) {
			continue;
		}
		
		var ele = thisNavEleSub[0];
		
		if (thisNavEle  == e.target) {
			if (ele.className == "sub") {
				//show ele
				ele.className = "";
			} else {
				//hide ele
				ele.className = "sub";
			}
		}	else {
			//hide ele
			ele.className = "sub";
		}
	}
	
	/* No longer needed
	
		
//	var ele = document.getElementById("sub");

	var eles = getElementsByAttribute("name", "sub", e.target);
	
	
	if (eles.length != 1) {
	//You theives, you stole this from Jum_pnetworks.net
	return
	}
	
	var ele = eles[0];

	if (ele.className == "sub") {
		//show ele
		
		ele.className = "";
	} else {
		//hide ele
		ele.className = "sub";
	}*/
}

//function to start color fade in
function startColor(e) {
	if (!e) e = window.event;
	
	if (!e.target) {
		e.target = e.srcElement;
	}
	
	//if (e.target.tagName != "A") {	
		e.target.fadeAmount = 0;
		e.target.targetColor = "#6B8EBE";
		e.target.stdColor = "#8CB8F4";
	
		clearTimeout(e.target.fadeTO);
		if (startFade) {
			startFade(e.target, "in");
		}
	//}
}

//function to start color fade in
function stopColor(e) {
	if (!e) e = window.event;
	
	if (!e.target) {
		e.target = e.srcElement;
	}
	
	
	e.target.targetColor = "#6B8EBE";
	e.target.stdColor = "#8CB8F4";
	
	clearTimeout(e.target.fadeTO);
	if (startFade) {
		startFade(e.target, "out");
	}
}


function startFade(ele, direction) {
	//var ele = document.getElementById(eleID);

	if (direction == "in") {
		if (ele.fadeAmount + 10 < 100) {
			ele.fadeAmount = ele.fadeAmount + 10;
			var newColour = colorBlend(ele.stdColor, ele.targetColor, ele.fadeAmount);
			ele.style.color = newColour;
			//Apply to links
			var theLinks = ele.childNodes;
			for (var i=0; i< theLinks.length; i++) {
				if (theLinks[i].style != null) {
					theLinks[i].style.color = newColour;
				}	
			}
			
			
			var testFunc = function () { startFade(ele, "in") };
			
			//ele.fadeTO = setTimeout("startFade('" + eleID + "', 'in')", 10);
			ele.fadeTO = setTimeout(testFunc, 15);
		}
	} else if (direction == "out") {
		if (ele.fadeAmount - 10 > 0) {
			ele.fadeAmount = ele.fadeAmount - 10;
			var newColour = colorBlend(ele.stdColor, ele.targetColor, ele.fadeAmount);
			ele.style.color = newColour;
			//Apply to links
			var theLinks = ele.childNodes;
			for (var i=0; i< theLinks.length; i++) {
				if (theLinks[i].style != null) {
					theLinks[i].style.color = newColour;
				}	
			}
			
			var testFunc = function () { startFade(ele, "out") };
			ele.fadeTO = setTimeout(testFunc, 15);
			//ele.fadeTO = setTimeout("startFade('" + eleID + "', 'out')", 10);
		}
	}
}


/*
window.onload = function () {
	
	//var navEles = getElementsByAttribute(document.getElementById("holder"), "div", "class", "sec1");
	var navEles = getElementsByAttribute("class", "sec1", document.getElementById("header"));
	
	for (var i in navEles) {
		
		navEles[i].onclick = showHide;
		
		//if (navEles[i].id != "") {
			navEles[i].onmouseover = startColor;
			navEles[i].onmouseout = stopColor;
		//}
	}
	
	
	var navEles = getElementsByAttribute("class", "sec2", document.getElementById("holder"));
	
	for (var i in navEles) {
		
		//navEles[i].onclick = showHide;
		//if (navEles[i].id != "") {
		navEles[i].onmouseover = startColor;
		navEles[i].onmouseout = stopColor;
		//}
	}
	
	

	
	
	//document.getElementById("trigger").onclick = showHide;
	
}*/

//***************************************************** DONE BLEND FUNCTIONS *********************************************




//******************************************************* MOVEMENT FUNCTIONS *********************************************
//function to convert from string with px to a raw number for style properties
function convertToInt(whichString) {
	var newInt = false;
	if (whichString.indexOf("px")) {
		newInt = parseFloat(whichString.substr(0, whichString.length - 2));
	}
	
	return newInt;
}


function prepElementForMove(ele) {
	if (ele.style.top == "") {
		ele.style.top = ele.offsetTop + "px";
	}
	if (ele.style.left == "") {
		ele.style.left = ele.offsetLeft + "px";
	}
	
	ele.style.marginLeft = 0;
	ele.style.marginTop = 0;
}




function moveElementTo (whichElement, whereX, whereY, speedX, speedY, revealAfter) {
	//prepElementForMove(whichElement)
	
	//Determine Y offset amount (per increment)
	if (convertToInt(whichElement.style.top) != whereY) {
		yOffset = (whereY - convertToInt(whichElement.style.top)) / (speedX);
	} else {
		yOffset = 0;
	}
	//Done
	
	//Determine X offset amount (per increment)
	if (convertToInt(whichElement.style.left) != whereX) {
		xOffset = (whereX - convertToInt(whichElement.style.left)) / (speedY);
	} else {
		xOffset = 0;
	}
	//Done
	
	whichElement.hasArrived = false;
	whichElement.moving = true;

	whichElement.moveInt = setInterval("moveElementLoop('" + whichElement.id + "', " + whereX + ", " + whereY + ", " + xOffset + "," + yOffset + ",'testID', " + revealAfter + ")", 10);
}

function moveElementLoop (whichElementID, whereX, whereY, xOffset, yOffset, identifier, revealAfter) {
	whichElement = document.getElementById(whichElementID);

	
	xArrived = false
	yArrived = false
	
	
	//Mozilla based browsers will move DIVs by decimal values, but IE and others don't seem to, so...
	if (!Mozilla) {
		if (xOffset < 0 && Math.round(xOffset) == 0) {
			xOffset = -1;
		} else if (xOffset > 0 && Math.round(xOffset) == 0) {
			xOffset = 1;
		} else {
			xOffset = Math.round(xOffset);
		}
		
		if (yOffset < 0 && Math.round(yOffset) == 0) {
			yxOffset = -1;
		} else if (yOffset > 0 && Math.round(yOffset) == 0) {
			yOffset = 1;
		} else {
			yOffset = Math.round(yOffset);
		}
	}
	
	
	if (whichElement.hasArrived == false) {
		if (convertToInt(whichElement.style.top) < whereY + 12 && convertToInt(whichElement.style.top) > whereY - 12) {
			whichElement.style.top = whereY + "px";
			yArrived = true;
			
			
		} else {
			whichElement.style.top = convertToInt(whichElement.style.top) + yOffset + "px";
			
		}
		
		if (convertToInt(whichElement.style.left) < whereX + 12 && convertToInt(whichElement.style.left) > whereX - 12) {
			whichElement.style.left = whereX + "px";
			xArrived = true;
			

		} else {
			whichElement.style.left = convertToInt(whichElement.style.left) + xOffset + "px";

		}
		
		if (xArrived && yArrived) {
			whichElement.hasArrived = true;
			
		}
		
	} else {
		clearInterval(whichElement.moveInt);
		
		if (revealAfter) {
			try {
				revealAfter(whichElement);
			} catch (e) {
				
			}
			//prepElementForDisplay(whichElement);
		}
		whichElement.moving = false;
		whichElement.hasArrived = false;
		
	}
}



//Scale Element
function scaleElementLoop (whichElementID, newWidth, newHeight, Xspeed, Yspeed, whenDoneCall, callbackLocal) {
	whichElement = document.getElementById(whichElementID);
	
 	//alert (whichElement.style.width);
	var widthResizeDone = false;
	var heightResizeDone = false;
	
	//Mozilla based browsers will scale DIVs by decimal values, but IE and others don't seem to, so...
	Xtolerance = 5;
	Ytolerance = 5;
	if (!Mozilla) {
		decXspeed = Xspeed;
		decYspeed = Yspeed;
		if (Xspeed < 0 && Math.round(Xspeed) == 0) {
			Xspeed = -1;
		} else if (Xspeed > 0 && Math.round(Xspeed) == 0) {
			Xspeed = 1;
		} else {
			/*if (Xspeed > 0) {
				Xspeed = Math.ceil(Xspeed);
			} else {
				Xspeed = Math.floor(Xspeed);
			}*/
			Xspeed = Math.round(Xspeed);
		}
		Xtolerance = Math.abs(Math.round(((decXspeed - Xspeed) * 50))) + 1;
		
		if (Yspeed < 0 && Math.round(Yspeed) == 0) {
			Yspeed = -1;
		} else if (Yspeed > 0 && Math.round(Yspeed) == 0) {
			Yspeed = 1;
		} else {
			/*if (Yspeed > 0) {
				Yspeed = Math.ceil(Yspeed);
			} else {
				Yspeed = Math.floor(Yspeed);
			}*/
			Yspeed = Math.round(Yspeed);
		}
		Ytolerance = Math.abs(Math.round(((decYspeed - Yspeed) * 50))) + 1;
		
	}
	
	
	if (whichElement.resized != true) {
		if (convertToInt(whichElement.style.width) > newWidth + Xtolerance || convertToInt(whichElement.style.width) < newWidth - Xtolerance) {
			whichElement.style.width = (convertToInt(whichElement.style.width) + Xspeed) + "px"
			
		} else {
			whichElement.style.width = newWidth  + "px";
			widthResizeDone = true;
			
		}
		
		if (convertToInt(whichElement.style.height) > newHeight + Ytolerance || convertToInt(whichElement.style.height) < newHeight - Ytolerance) {
			whichElement.style.height = (convertToInt(whichElement.style.height) + Yspeed) + "px"
			
			
		} else {
			
			whichElement.style.height = newHeight + "px";
			
			heightResizeDone = true;
			
			
		}
		
		if (widthResizeDone && heightResizeDone) {
			whichElement.resized = true;
			
		}
		
	} else {
		
		if (whichElement.moving == false) {
			
			whichElement.resized = false;
			clearInterval(whichElement.resizeInt);
			
			if (whenDoneCall) {
				eval (whenDoneCall + "('" + whichElement.id + "', '" + callbackLocal + "')");
			}
		}
		//prepElementForDisplay(whichElement);
		//whichElement.moving = false;

	}
}





//Function to set opacity of an element
function setOpacity(ele, opacity) {
	if (ele.style.opacity != null) {
		ele.style.opacity = (opacity / 100);
	} else if (ele.style.KhtmlOpacity != null) {
		ele.style.KhtmlOpacity = (opacity / 100);
	} else if (ele.style.MozOpacity != null) {
		ele.style.MozOpacity = (opacity / 100);
	} else if (ele.style.filter != null) {
		ele.style.filter = "alpha(opacity=" + opacity + ")";
	}
}

//function to get the opacity of an element
function getOpacity(ele) {
	var theOp = "none";
	if (ele.style.opacity != null) {
		theOp = ele.style.opacity * 100;
	} else if (ele.style.KhtmlOpacity != null) {
		theOp = ele.style.KhtmlOpacity * 100;
	} else if (ele.style.MozOpacity != null) {
		theOp = ele.style.MozOpacity * 100;
	} else if (ele.style.filter != null) {
		var alpha = "opacity=";
		var str = ele.style.filter;
		theOp = str.substring(str.indexOf(alpha) + alpha.length, str.lastIndexOf(")"));
	}
	
	if (theOp != "none") {
		theOp = parseFloat(theOp);
	}
	return theOp;
}

//function to fade box in
function fadeBox(eleID) {
	var boxEle = document.getElementById(eleID);
	var theOp = getOpacity(boxEle); 

	if (theOp < 100) {
		setOpacity(boxEle, theOp + 5);
		setTimeout("fadeBox('" + boxEle.id + "')", 50);
	} else {
		boxEle.loaded = true;
		if (boxEle.loadFunc != null) {
			eval(boxEle.loadFunc + "(boxEle)");
		}
	}
}


//function to fade box out
function fadeBoxOut(eleID) {
	var boxEle = document.getElementById(eleID);
	var theOp = getOpacity(boxEle); 

	
	if (theOp > 0) {
		setOpacity(boxEle, theOp - 5);
		setTimeout("fadeBoxOut('" + boxEle.id + "')", 50);
	} else {
		boxEle.unloaded = true;
		if (boxEle.unloadFunc != null) {
			if (typeof(boxEle.unloadFunc) == "function") {
				boxEle.unloadFunc(boxEle);
			} else {
				eval(boxEle.unloadFunc + "(boxEle)");
			}
		}
	}

}


