// JavaScript Document

var Timer;
var maxWidth = 400;
var minWidth = 80; // safest width before graphic collapses on itself
var maxHeight = 500;
var minHeight = 25;
var speed = 10;
var scaleIntervalW = 40;
var scaleIntervalH = 40;
var opacityInterval = 4;
var count = 0;
var innerTextDisp = "";

////////////////////////////////////////////////////////////////////////////////////////////////
//	Outdated Function -> Forwards to NEW Function
////////////////////////////////////////////////////////////////////////////////////////////////
function rolloverPop(element, divName, width, dispContents, dimFunction) {
	scale('out', element, divName, width, dispContents);
}
function setDimmer(divName, functionName, onOff) {
	scale('in', '', divName, '', '');
}

////////////////////////////////////////////////////////////////////////////////////////////////
// NEW Function -- Mouseovers should use THIS function
////////////////////////////////////////////////////////////////////////////////////////////////
function scale(inOut, element, divName, width, dispContents) {
	clearInterval(Timer);
	var elementX = 0;
	var elementY = 0;
	if (element.offsetParent) {
		do {
			elementX += element.offsetLeft;
			elementY += element.offsetTop;
		} while (element = element.offsetParent);
	}
	if(inOut == 'in') {
		if(document.getElementById(divName)) {
			Timer = setInterval("scaleIn('"+element+"', '"+divName+"')", speed);
		}
	} else if(inOut == 'out') {
		if(document.getElementById(divName)) {
			removeElement(divName);
		}
		innerTextDisp = dispContents;
		createRolloverElement(divName, width, elementX, elementY, dispContents);
		Timer = setInterval("scaleOut('"+element+"', '"+divName+"', '"+width+"')", speed);
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////
function createRolloverElement(divName, width, elementX, elementY, dispContents) {
	var newPopElement = document.createElement("div");
	newPopElement.setAttribute('id', divName);
	newPopElement.setAttribute('name', divName);
	newPopElement.style.width = '90px';
	newPopElement.style.left = (elementX-parseInt(width)+4)+'px';
	newPopElement.style.float ='left';
	newPopElement.style.position = 'absolute';
	newPopElement.style.zIndex = 99;
	newPopElement.style.overflow = 'visible';
	
	var newPopInnerPNG = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='25' background='/inc/images/rolloverPop/TLCorner.png'>&nbsp;</td><td height='25' background='/inc/images/rolloverPop/topCntr.png'>&nbsp;</td><td width='40' background='/inc/images/rolloverPop/TRCorner.png'>&nbsp;</td></tr></table><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='25' background='/inc/images/rolloverPop/midLeft.png'>&nbsp;</td><td height='25' bgcolor='#FFFFFF'><div id='"+divName+"Inner' class='popInner' style='opacity:0;'>"+dispContents+"</div></td><td width='40' background='/inc/images/rolloverPop/midRight.png'>&nbsp;</td></tr></table><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='25' background='/inc/images/rolloverPop/BLCorner.png'>&nbsp;</td><td height='40' background='/inc/images/rolloverPop/btmCntr.png'>&nbsp;</td><td width='40' background='/inc/images/rolloverPop/BRCorner.png'>&nbsp;</td></tr></table>";
	
	var newPopInnerGIF = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='25' background='/inc/images/rolloverPop/TLCorner.gif'>&nbsp;</td><td height='25' background='/inc/images/rolloverPop/topCntr.gif'>&nbsp;</td><td width='40' background='/inc/images/rolloverPop/TRCorner.gif'>&nbsp;</td></tr></table><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='25' background='/inc/images/rolloverPop/midLeft.gif'>&nbsp;</td><td height='25' bgcolor='#FFFFFF'><div id='"+divName+"Inner' class='popInner' style='opacity:0;'>"+dispContents+"</div></td><td width='40' background='/inc/images/rolloverPop/midRight.gif'>&nbsp;</td></tr></table><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='25' background='/inc/images/rolloverPop/BLCorner.gif'>&nbsp;</td><td height='40' background='/inc/images/rolloverPop/btmCntr.gif'>&nbsp;</td><td width='40' background='/inc/images/rolloverPop/BRCorner.gif'>&nbsp;</td></tr></table>";
	
	if((getBrowser('browserName').indexOf('Microsoft')) >= 0) {
		newPopElement.innerHTML = newPopInnerGIF;
	} else {
		newPopElement.innerHTML = newPopInnerPNG;
		//newPopElement.innerHTML = newPopInnerGIF;
	}
	// INSERT ELEMENT INTO PAGE BODY
	document.body.appendChild(newPopElement);
	document.getElementById(divName+'Inner').style.width = width-70 + 'px';
	//document.getElementById(divName+'Inner').innerHTML = dispContents;
	maxHeight = document.getElementById(divName).offsetHeight-35;
	document.getElementById(divName).style.top = (elementY-parseInt(maxHeight)-35)+'px';
	document.getElementById(divName+'Inner').style.width = 'auto';
	document.getElementById(divName+'Inner').innerHTML = "&nbsp;";
}

function scaleOut(element, divName, width) {
	var obj = document.getElementById(divName);
	var objInner = document.getElementById(divName + 'Inner');
	var innerText = document.getElementById(divName + 'InnerText');
	var curWidth = obj.offsetWidth;
	var curHeight = objInner.offsetHeight;
	maxWidth = width;
	
	if(curWidth < maxWidth) {
		if((curWidth + scaleIntervalW) > maxWidth) {
			obj.style.width = maxWidth + "px";
		} else {
			obj.style.width = (curWidth + scaleIntervalW) + "px";
		}
	}
	if(curHeight < maxHeight) {
		if((curHeight + scaleIntervalH) > maxHeight) {
			objInner.style.height = maxHeight + "px";
		} else {
			objInner.style.height = (curHeight + scaleIntervalH) + "px";
		}
	}
	if(curWidth >= maxWidth && curHeight >= maxHeight) {
		clearInterval(Timer);
		Timer = setInterval("fadeDiv('in', '"+divName+"')", speed);
	}
}

function scaleIn(element, divName) {
	var obj = document.getElementById(divName);
	var objInner = document.getElementById(divName + 'Inner');
	//var innerText = document.getElementById(divName + 'InnerText');
	var curWidth = obj.offsetWidth;
	var curHeight = objInner.offsetHeight;
	// CLEAR TEXT
	objInner.style.opacity = 0;
	objInner.innerHTML = "&nbsp;";
	//
	if(curWidth > minWidth) {
		if((curWidth - scaleIntervalW) < minWidth) {
			obj.style.width = minWidth + "px";
		} else {
			obj.style.width = (curWidth - scaleIntervalW) + "px";
		}
	}
	if(curHeight > minHeight) {
		if((curHeight - scaleIntervalH) < minHeight) {
			objInner.style.height = minHeight + "px";
		} else {
			objInner.style.height = (curHeight - scaleIntervalH) + "px";
		}
	}
	if(curWidth <= minWidth && curHeight <= minHeight) {
		clearInterval(Timer);
		Timer = setInterval("fadeDiv('out', '"+divName+"')", speed);
	}
}

function fadeDiv(inOut, divName) {
	var objInner = document.getElementById(divName + 'Inner')
	objInner.innerHTML = innerTextDisp;
	var curOpacity = objInner.style.opacity;
	if(inOut == 'in') {
		if(curOpacity < 1) {
			var curOpacityMath = curOpacity*100;
			var opacityChange = curOpacityMath + opacityInterval;
			objInner.style.filter = "alpha(style=0,opacity=" + curOpacityMath + ")";
			objInner.style.opacity = opacityChange/100;
		} else {
			clearInterval(Timer);
		}
	} else {
		if(curOpacity > 0) {
			var curOpacityMath = curOpacity*100;
			var opacityChange = curOpacityMath - opacityInterval;
			objInner.style.filter = "alpha(style=0,opacity=" + curOpacityMath + ")";
			objInner.style.opacity = opacityChange/100;
		} else {
			clearInterval(Timer);
			removeElement(divName);
		}
	}
}

// DELETE ELEMENT
function removeElement(id)
{
	if(document.getElementById(id)) {
		if (typeof id == 'string') {
			id = document.getElementById(id);
		}
		if (id && id.parentNode) {
			id.parentNode.removeChild(id);
		}
	}
}