var aColor = new Array();
aColor.push(new Array("linkfade", "#FFFFFF", "#999999"));
aColor.push(new Array("linkfade2", "#FFFF00", "#FFCC33"));
aColor.push(new Array("linkfade3", "#CC0000", "#FFCC33"));


function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

function inArr(arr,value) {
	var i;
	for (i=0; i < arr.length; i++) {
		if (arr[i] === value) {
			return true;
		}
	}
	return false;
};


var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);

/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com

Modified By: Chrys Bader, The Edvisors Network
Now tool tips will fade out nicely as well.
If you have an element you don't want the tooltip to affect, simply set the classnName to "noTip"
*/
var sweetTitles = { 
	xCord : 0,								// @Number: x pixel value of current cursor position
	yCord : 0,								// @Number: y pixel value of current cursor position
	tipElements : ['a','abbr','acronym', 'th','area', 'span','img'],	// @Array: Allowable elements that can have the toolTip
	obj : Object,							// @Element: That of which you're hovering over
	tip : Object,							// @Element: The actual toolTip itself
	active : 0,								// @Number: 0: Not Active || 1: Active
	init : function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		this.tip.style.display = 'none';
		addEvent( this.tip, 'mouseover', this.tipHide );
		var tipLen = this.tipElements.length;
		for ( i=0; i<tipLen; i++ ) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for ( j=0; j<curLen; j++ ) {
				addEvent(current[j],'mouseover',this.tipOver);
				addEvent(current[j],'mouseout',this.tipOut);
				current[j].setAttribute('tip',current[j].title);
				current[j].removeAttribute('title');
				
				if( current[j].firstChild && current[j].firstChild.getAttribute )
				{
					current[j].setAttribute('desc', current[j].firstChild.getAttribute('alt') );
					current[j].firstChild.removeAttribute('alt');	
				}
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function() {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		
		sweetTitles.tipFadeOut(90);
	},
	tipHide: function() {
			
		if( window.xID )
			clearTimeout(xID);
			
		sweetTitles.tip.style.display = 'none';
	},
	checkNode : function() {
		var trueObj = this.obj;
		if ( inArr(this.tipElements,trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		sweetTitles.obj = this;
		var elem = (e.target) ? e.target : e.srcElement;

		if( this.getAttribute('tip') )
		{
			xID = window.setTimeout("sweetTitles.tipHide()", 300);
			tID = window.setTimeout("sweetTitles.tipShow()",500);
			
			sweetTitles.updateXY(e);
		}
		else
		{
			if( window.xID )
				clearTimeout(tID);			
			sweetTitles.tipHide();	
		}
	},
	tipShow : function() {
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var anch = this.checkNode();
		var addy = '';
		var access = '';
		
		
		/*
		if( anch.firstChild.getAttribute && anch.firstChild.getAttribute('alt') ) {
			addy = anch.firstChild.getAttribute('alt')
		}
		*/
		if( anch.getAttribute('desc') )	{
			addy = anch.getAttribute('desc');	
		}
		else if ( anch.nodeName.toLowerCase() == 'a' ) {
			addy = anch.href.toString().replace('http://www.dota-allstars.com/', '');
			addy = (addy.length > 35 ? addy.substring(0,35)+"..." : addy );
			var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
		}
		else {
			if( anch.firstChild)
				addy = anch.firstChild.nodeValue;
		}
		this.tip.innerHTML = "<p>"+anch.getAttribute('tip')+"<em>"+access+addy+"</em></p>";
		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
			this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
		} else {
			this.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
			this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}
		this.tip.style.display = '';
		this.tip.style.opacity = '.1';
		this.tipFadeIn(0);
	},
	tipFadeIn: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 80 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFadeIn('"+newOpac+"')",20);
		}
		else { 
			this.tip.style.opacity = '.80';
			this.tip.style.filter = "alpha(opacity:80)";
		}
	},
	tipFadeOut: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed-10);
		if ( newOpac > 5 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFadeOut('"+newOpac+"')",20);
		}
		else { 
			this.tip.style.opacity = '0';
			this.tip.style.filter = "alpha(opacity:0)";
		}
	}	
};
function pageLoader() {
	if( !document.all )
		sweetTitles.init();
}

// addEvent(window,'load',pageLoader);

/*	Link fading script v1.0 by Alex Griffioen @ www.justdesign.nl, 2005
	Feel free to use, but please leave this comment in :)
	Email your improvements to: griffioen@justdesign.nl
*/

var delay		= 1;	// Fade delay in miliseconds
var stepIn		= 10;	// Steps to fade in
var stepOut		= 30;	// Steps to fade out
var aElement	= new Array();
var aInterval	= new Array();
var aLoop		= new Array("R", "G", "B");

function init() {
	var aAnchor = document.getElementsByTagName("a");
	for(var i = 0; i < aColor.length; i++) {
		var className	= aColor[i][0];
		var aRgbOver	= getRgb(aColor[i][1]);
		var aRgbOut		= getRgb(aColor[i][2]);

		for(var j = 0; j < aAnchor.length; j++) {
			if(aAnchor[j].className == className) {
				aAnchor[j].style.color	= aColor[i][2];
				aAnchor[j].setAttribute("linkId", j);
				aAnchor[j].setAttribute("colorOver", aColor[i][1]);
				aAnchor[j].setAttribute("colorOut", aColor[i][2]);
				
				for(var k = 0; k < 3; k++) {
					aAnchor[j].setAttribute("colorOver" + aLoop[k], aRgbOver[aLoop[k]]);
					aAnchor[j].setAttribute("colorOut" + aLoop[k], aRgbOut[aLoop[k]]);
					aAnchor[j].setAttribute("changeIn" + aLoop[k], Math.floor((aRgbOver[aLoop[k]] - aRgbOut[aLoop[k]]) / stepIn));
					aAnchor[j].setAttribute("changeOut" + aLoop[k], Math.floor((aRgbOut[aLoop[k]] - aRgbOver[aLoop[k]]) / stepOut));
				}
				
				aAnchor[j].onmouseover	= linkOver;
				aAnchor[j].onmouseout	= linkOut;
			}
			aInterval.push(null);
		}
	}
}

function getHexFromCssRgb(rgb) {
	var reHex		= new RegExp("^rgb\\(([0-9]{1,3}), ([0-9]{1,3}), ([0-9]{1,3})\\)$", "i");
	var aValue		= reHex.exec(rgb);
	return "#" + getHex(aValue[1]) + getHex(aValue[2]) + getHex(aValue[3]);
}

function getRgb(hex) {
	var reHex		= new RegExp("^#([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})$", "i");
	var aValue		= reHex.exec(hex);
	var aRgb		= new Array(3);
	aRgb["R"]		= parseInt(aValue[1], 16);
	aRgb["G"]		= parseInt(aValue[2], 16);
	aRgb["B"]		= parseInt(aValue[3], 16);
	return aRgb;
}

function getHex(rgbValue) {
	rgbValue		= parseInt(rgbValue);
	var hexValue	= new String("0" + rgbValue.toString(16));
	hexValue		= hexValue.substring(hexValue.length - 2, hexValue.length);
	return hexValue.toUpperCase();
}

function linkOver() {
	var linkId	= this.getAttribute("linkId");
	if(aInterval[linkId] != null) window.clearInterval(aInterval[linkId]);
	aInterval[linkId] = window.setInterval("fade(" + linkId + ", " + this.getAttribute("changeInR") + ", " + this.getAttribute("changeInG") + ", " + this.getAttribute("changeInB") + ")", delay);
}

function linkOut() {
	var linkId	= this.getAttribute("linkId");
	if(aInterval[linkId] != null) window.clearInterval(aInterval[linkId]);
	aInterval[linkId] = window.setInterval("fade(" + linkId + ", " + this.getAttribute("changeOutR") + ", " + this.getAttribute("changeOutG") + ", " + this.getAttribute("changeOutB") + ")", delay);
}

function fade(linkId, changeR, changeG, changeB) {
	var element	= document.getElementsByTagName("a")[linkId];
	var color	= (element.style.color.indexOf("#") == -1) ? getHexFromCssRgb(element.style.color) : element.style.color;
	var aRgb	= getRgb(color);
	var hex		= "#";
		
	for(i = 0; i < 3; i++) {
		var change			= eval("change" + aLoop[i]);
		var newValue		= aRgb[aLoop[i]] + change;
		var colorOverValue	= element.getAttribute("colorOver" + aLoop[i]);
		var colorOutValue	= element.getAttribute("colorOut" + aLoop[i]);
	
		if(change > 0) {
			var toValue		= Math.max(colorOverValue, colorOutValue);
			var newValue	= (newValue > toValue) ? toValue : newValue;
		} else {
			var toValue		= Math.min(colorOverValue, colorOutValue);
			var newValue	= (newValue < toValue) ? toValue : newValue;
		}
		hex += getHex(newValue);
	}
	element.style.color = hex;

	if(hex == element.getAttribute("colorOver") || hex == element.getAttribute("colorOut")) {
		window.clearInterval(aInterval[linkId]);
		aInterval[linkId] = null;
	}
}

function toggleLayer(id)
{
	var e = document.getElementById(id);
	
	e.style.display = (e.style.display=='none') ? '' : 'none';
}