/* general variables */

var active = 'sparks';
var timer = 0;

var fadeTargetId = 'submenu'; /* change this to the ID of the fadeable object */
var fadeTarget;
preInit();

/* functions */
//Browser check
function checkBrowser() {
	if (!document.getElementById || !document.getElementsByTagName || !document.createElement) {
		return false;
	}
	else {
		return true;
	}
}

cb = checkBrowser();

function preInit() {
	/* an inspired kludge that - in most cases - manages to initially hide the image
	   before even onload is triggered (at which point it's normally too late, and a nasty flash
	   occurs with non-cached images) */
	if ((document.getElementById)&&(fadeTarget=document.getElementById(fadeTargetId))) {
		clearTimeout(preInitTimer);
	} else {
		preInitTimer = setTimeout("preInit()",2);
	}
}

function fadeInit() {
	if (document.getElementById) {
		/* get a handle on the fadeable object, to make code later more manageable */
		preInit(); /* shouldn't be necessary, but IE can sometimes get ahead of itself and trigger fadeInit first */
		/* set the initial opacity in a (hopefully) cross browser way
		   notice that because of the way the image is in front, and not obfuscated
		   by another object we need to "fade out", i don't need a fallback mechanism
		   to show/hide the covering object...the image is just there, full stop */
		if (fadeTarget.style.MozOpacity!=null) {  
			/* Mozilla's pre-CSS3 proprietary rule */
			fadeTarget.style.MozOpacity = 1;
		} else if (fadeTarget.style.opacity!=null) {
			/* CSS3 compatible */
			fadeTarget.style.opacity = 0;
		} else if (fadeTarget.style.filter!=null) {
			/* IE's proprietary filter */
			fadeTarget.style.filter = "alpha(opacity=0)";
		}
	}
}

function fadeIn(opacity) {
	if (fadeTarget) {
		if (opacity <= 100) {
			if (fadeTarget.style.MozOpacity!=null) {
				/* Mozilla's pre-CSS3 proprietary rule */
				fadeTarget.style.MozOpacity = (opacity/100)-.001;
				/* the .001 fixes a glitch in the opacity calculation which normally results in a flash when reaching 1 */
			} else if (fadeTarget.style.opacity!=null) {
				/* CSS3 compatible */
				fadeTarget.style.opacity = (opacity/100)-.001;
			} else if (fadeTarget.style.filter!=null) {
				/* IE's proprietary filter */
				fadeTarget.style.filter = "alpha(opacity="+opacity+")";
				/* worth noting: IE's opacity needs values in a range of 0-100, not 0.0 - 1.0 */ 
			}
			opacity += 10;
			window.setTimeout("fadeIn("+opacity+")", 30);
		}
	}
}

function addRollOver() {
	if (cb) {
		var roArr=document.getElementsByTagName("a");
		for (var i=0; i<roArr.length; i++) {
			var el = roArr[i];
			if (el.className == "special" || el.className == "specialS") {
				el.onmouseover = function() {
					clearTimeout(timer); 
					makeVis('submenu',this);
				}
				el.onmouseout = function() { 
					timer = setTimeout("makeHid('submenu')",250);
				}
			}
		}
	}
}

function css() {
	el = document.getElementById('submenu');
	if (!window.Node) {
		el = document.getElementById('submenu');
		el.style.left = 110+"px";
		el.style.top = 21+"px";
		el1 = document.getElementById('content');
		el2 = document.getElementById('text');
		//alert("content="+el1.offsetHeight+" text="+el2.offsetHeight);
		if(el2.offsetHeight >= 300) {
			el1.style.height = 300+"px";
		}
		
	}
	if (document.implementation.hasFeature('XML', '1.0')) {
		el = document.getElementById('submenu');
	}
}

function makeVis(el,ref) {
	el = document.getElementById(el);
	el.style.display = "block";
	if (ref.parentNode.className != "sub") {
		fadeIn(0);
	}
}

function makeHid(el) {
	document.getElementById(el).style.display = "none";
}

function init() {
	addRollOver();
	css();
	fadeInit();
}