/*****************************************************
** Javascript (DHTML) Fading Menu v0.2              **
** By Thiago Pereira Ricciardi - Argon Technology   **
** http://techonology.argonteam.net                 **
** thiago@argonteam.net                             **
** You can use this code in your page for free!     **
** But please don't delete these first lines :)     **
******************************************************/
/*###### USAGE #######
>>> To Add the script to HTML <<<
<script type="text/javascript" src="menu.js"></script>
>>> On caller <<<
- OnSomeEvent: FadeIn(id[,caller[,type]])
id -> required. the id of the object that you want to apply the fade-in effect
caller -> optional. for some location purposes it must be "this" (without the quotes). If no value it will use the fader object.
type -> optional. 0,1 or 2. If nothing is assigned then it will use 0.
    0 - appears below the caller
    1 - appears at the right side of the caller
    2 - appears at the right side and below the caller
- OnSomeOtherEvent: FadeOut(id)
id -> required. the id of the object that you want to apply the fade-out effect
>>> On FadeInOut Object <<<
- OnMouseOver: FadeIn(id)
- OnMouseOut: FadeOut(id)
id -> required. the id of the FadeInOut object.
- some style need to be applied to work properly
display:none; opacity:0; filter:alpha(opacity=0);
####### Compatibility ######
>>> TESTED <<<
- Windows Internet Explorer 7.0
- Microsoft Internet Explorer 6.0 (SP0, SP1 and SP2)
- Mozilla Firefox 1.5
- Mozilla Firefox 2.0
- Google Chrome
>>> NOT tested but believed to work <<<
- Mozilla Firefox 1.0 and newer
- Microsoft Internet Explorer 5.5 and newer
********************************************************************************/

fade_step = 10; // (%) percent of opacity increase/decrease for each interation
fade_time = 300; //(ms) total time of the fade
delay = 100; //(ms) delay to start fading out since the mouse left the menu (or caller)

// ------ Don't mess below here ------
// ------ Used Functions ------
function GetInt(str) {
	if (str!='' && str) {
		temp = str.split('');
		aux = '';
		for (n in temp) {
			pass = !(isNaN(parseInt(temp[n])));
			if (! pass )
				pass = (temp[n]=='-');
			if ( pass )
				aux += temp[n];
		}
		return parseInt(aux,10);
	}
	else {
		return 0;
	}
}
function Left(obj){
    total = obj.offsetLeft;
    parentObj = obj.offsetParent;
    while (parentObj){
        total += parentObj.offsetLeft;
        parentObj = parentObj.offsetParent;
    }
    return total;
}
function Top(obj){
    total = obj.offsetTop;
    parentObj = obj.offsetParent;
    while (parentObj){
        total += parentObj.offsetTop;
        parentObj = parentObj.offsetParent;
    }
    return total;
}
// Fade-In
function FadeIn(id,caller,type) {
	obj = document.getElementById(id);
	if (! caller) caller = obj;
	if (! type) type = 0;
	X = Left(caller);
	Y = Top(caller);
	if (!(obj === caller)){
	    switch (type) {
	        case 0:
	            Y += caller.offsetHeight;
	            break;
	        case 1:
	    	    X += caller.offsetWidth;
	    	    break;
	    	case 2:
	    	    X += caller.offsetWidth;
	    	    Y += caller.offsetHeight;
	    	    break;
	    	default:
	    	    Y += caller.offsetHeight;
	            break;
	    }
	}
	hold[id] = true;
	start = 0;
	if (obj.filters) {
	    start = obj.filters.alpha.opacity;
	}
	else {
	    start = obj.style.opacity * 100;
    }
    //obj.style.left = X + "px";
	//obj.style.top = Y + "px";
	//obj.style.position = "absolute";
	obj.style.display = "block";
	FadeInChild(id,start);
}
function FadeInChild(id,i) {
    obj = document.getElementById(id);
	if (i<=100){
	    if (obj.filters) {
	        obj.filters.alpha.opacity = i;
	    }
	    else {
		    obj.style.opacity = i/100;
		}
		i = i + fade_step;
		setTimeout("FadeInChild('"+id+"',"+i+");",fade_time/(100/fade_step));
	}
}
// Fade-Out
function FadeOut(id) {
	obj = document.getElementById(id);
	hold[id] = false;
	start = 100;
	if (obj.filters) {
	    start = obj.filters.alpha.opacity;
	}
	else {
	    start = obj.style.opacity * 100;
	}
	setTimeout('FadeOutChild("'+id+'",'+start+');',delay);
}
function FadeOutChild(id,i) {
    obj = document.getElementById(id);
	if (! hold[id]){
	    if (i>=0){
	        if (obj.filters) {
	            obj.filters.alpha.opacity = i;
    	    }
    	    else {
    		    obj.style.opacity = i/100;
    		}
	    	i = i - fade_step;
	    	setTimeout("FadeOutChild('"+id+"',"+i+");",fade_time/(100/fade_step));
    	}
    	else {
    	    obj.style.display = "none";
    	}
    }
}
// Declaration of the hold[id] variable (for some reasons it must be global)
var hold = new Array();