function elmnt(id) {
	return document.getElementById(id);
}

function set_current_height(id, height) {
	elmnt(id).style.height = height+'px';
	elmnt(id).clientHeight = height;
	elmnt(id).offsetHeight = height;
}

function current_height(id) {
	height= elmnt(id).clientHeight;
	if(height==0){
		height= elmnt(id).offsetHeight;
	}
	return height;
}

function current_width(id) {
	width=elmnt(id).clientWidth;
	if(width==0){
		width=elmnt(id).offsetWidth;
	}
	return width;
}

function max_height(id) {
	elmnt(id).style.overflow="hidden";
	if(current_height(id)!=0){
		return current_height(id);
	} else {
		origdisp = elmnt(id).style.display;
		origheight = elmnt(id).style.height;
		origpos = elmnt(id).style.position;
		origvis = elmnt(id).style.visibility;
		elmnt(id).style.visibility = "hidden";
		elmnt(id).style.height = "";
		elmnt(id).style.display = "block";
		elmnt(id).style.position = "absolute";
		height=current_height(id);
		elmnt(id).style.display = origdisp;
		elmnt(id).style.height = origheight;
		elmnt(id).style.position = origpos;
		elmnt(id).style.visibility = origvis;
		return height;
	}
}

function total_height(id) {
	//elmnt(id).style.overflow="hidden";
	origdisp = elmnt(id).style.display;
	origheight = elmnt(id).style.height;
	origpos = elmnt(id).style.position;
	origvis = elmnt(id).style.visibility;
	elmnt(id).style.visibility = "hidden";
	elmnt(id).style.height = "";
	elmnt(id).style.display = "block";
	elmnt(id).style.position = "absolute";
	height=current_height(id);
	elmnt(id).style.display = origdisp;
	elmnt(id).style.height = origheight;
	elmnt(id).style.position = origpos;
	elmnt(id).style.visibility = origvis;
	return height;

}


function openElement(id, velocity) {
    if(!velocity){
        velocity=200;
    }
    id_height = current_height(id);
    if(id_height==0){
        mx_height = max_height(id);
        elmnt(id).style.display="block";
        elmnt(id).style.height="0px";
        var opendiv = Math.ceil(velocity/mx_height);
        for(i=1; i<=mx_height; i++){
            window.setTimeout("elmnt('"+id+"').style.height='"+i+"px'", opendiv*i);
        }
    }
}

function closeElement(id, velocity) {
	if(!velocity){
		velocity=200;
	}
	id_height = current_height(id);
	mx_height = max_height(id);
	if (id_height == mx_height) {
		elmnt(id).style.display = "block";
		var closediv = Math.ceil(velocity/id_height);
		for(i=0; i<=id_height; i++){
			nh=id_height-i;
			window.setTimeout("elmnt('"+id+"').style.height='"+nh+"px'",closediv*i);
		}
	}
}

function modSizeElement(id, velocity) {
	if(!velocity){
		velocity=200;
	}
	//alert(elmnt(id).innerHTML);
	id_height = current_height(id);
	mx_height = total_height(id);
	//alert("act: " + id_height + " max: " + mx_height);
	if (id_height > mx_height) {
		elmnt(id).style.display = "block";
        var closediv = Math.ceil(velocity/id_height);
        for(i=id_height; i>=mx_height; i--){
			nh=id_height-i;
            window.setTimeout("elmnt('"+id+"').style.height='"+i+"px'", closediv*nh);
        }
	} else {
		elmnt(id).style.display = "block";
        var opendiv = Math.ceil(velocity/mx_height);
        for(i=id_height; i<=mx_height; i++){
			//nh=id_height-i;
            window.setTimeout("elmnt('"+id+"').style.height='"+i+"px'", opendiv*i);
        }
	}

}

function modSizeElementByHeight(id, h, velocity) {
	if(!velocity){
		velocity=200;
	}
	id_height = current_height(id);
	mx_height = h;
	if (id_height > mx_height) {
		elmnt(id).style.display = "block";
        var closediv = Math.ceil(velocity/id_height);
        for(i=id_height; i>=mx_height; i--){
			nh=id_height-i;
            window.setTimeout("elmnt('"+id+"').style.height='"+i+"px'", closediv*nh);
        }
	} else {
		elmnt(id).style.display = "block";
        var opendiv = Math.ceil(velocity/mx_height);
        for(i=id_height; i<=mx_height; i++){
			//nh=id_height-i;
            window.setTimeout("elmnt('"+id+"').style.height='"+i+"px'", opendiv*i);
        }
	}

}

function toggleElement(id, velocity){
	if(!velocity){
		velocity=200;
	}
	if (current_height(id) == 0) {
		openElement(id, velocity);
	} else {
		closeElement(id, velocity);
	}
}

function opacity(id, start, end, time){
	if (elmnt(id).style.width == 0) {
		elmnt(id).style.width=current_width(id);
	}
	var e=Math.round(time/100);
	var b =0;
	if (start>end) {
		for(i=start; i>=end; i--){
			window.setTimeout("changeOpacity("+i+",'"+id+"')",(b*e));
			b++;
		}
	} else {
		if (start<end) {
			for (i=start; i<=end; i++) {
				window.setTimeout("changeOpacity("+i+",'"+id+"')",(b*e));
				b++;
			}
		}
	}
}

function changeOpacity(opac,id){
	elmnt(id).style.opacity=(opac/100);
	elmnt(id).style.MozOpacity=(opac/100);
	elmnt(id).style.KhtmlOpacity=(opac/100);
	elmnt(id).style.filter="alpha(opacity="+opac+")";
}

function loadTextHTML(id, time, html){
	opacity(id, 100, 0, time);
	window.setTimeout("elmnt('" + id + "').innerHTML = '" + html + "'", time);
	window.setTimeout("opacity('" + id + "', 0, 100, " + time + ")", time*2);
	window.setTimeout("modSizeElement('" + id + "')", (time*4));
}

function loadTextHTMLByHeight(id, time, html, h){
	opacity(id, 100, 0, time);
	window.setTimeout("elmnt('" + id + "').innerHTML = '" + html + "'", time);
	window.setTimeout("modSizeElementByHeight('" + id + "', " + h + ")", (time*2));
	window.setTimeout("opacity('" + id + "', 0, 100, " + time + ")", time*4);
}

function openByHeight(id, time, h){
	opacity(id, 100, 0, time);
	window.setTimeout("modSizeElementByHeight('" + id + "', " + h + ")", (time*2));
	window.setTimeout("opacity('" + id + "', 0, 100, " + time + ")", time*4);
}

function loadTextHTML_cerrandoyabriendo(id, time, html){
	opacity(id, 100, 0, time);
	window.setTimeout("elmnt('" + id + "').innerHTML = '" + html + "'", time);
	window.setTimeout("closeElement('" + id + "')", time);
	window.setTimeout("opacity('" + id + "', 0, 100, " + time + ")", time*2);
	window.setTimeout("openElement('" + id + "')", time*2);
}

function pxToNumber(s) {
	return( Number( s.substring(0, s.length - 2) ) );
}