var minHeight = 5;
var aniSpeed = 20;
	
function setTab(id) {

	var Parent = document.getElementById('link_'+id).parentNode;
	
	var links = Parent.getElementsByTagName('a'); 
	for (var i = 0; i < links.length; i++) {
		if (links[i].id.substr(0, 5) == 'link_') {
			var css = links[i].className.substr(0, links[i].className.lastIndexOf('_') + 1);
	
			if (links[i].id == 'link_'+id) {
				links[i].blur();
				links[i].className = css + '2';
			} else {
				links[i].className = css + '1';
			}
		}
	}
	
	var tabs = Parent.getElementsByTagName('div'); 
	for (var i = 0; i < tabs.length; i++) {
		if (tabs[i].id.substr(0, 4) == 'dis_') {
			if (tabs[i].id == 'dis_'+id) {
				showTab(tabs[i].id);
			} else {
				if (tabs[i].offsetHeight > minHeight) {
					hideTab(tabs[i].id);
				}
			}
		}
	}
}

function showTab(id) {
	var id = id.substr(id.indexOf('_')+1);
	
	var dis = document.getElementById('dis_'+id);
	if (dis.style.height == '') dis.style.height = minHeight+'px';
	var cureHeight = dis.style.height.substr(0, dis.style.height.indexOf('p'));
	
	var src = document.getElementById('src_'+id);
	src.style.visibility = 'visible';
	var destHeight = src.offsetHeight;
	
	if (dis.animation) window.clearInterval(dis.animation);
	dis.animation = window.setInterval(
		function() {
			cureHeight = Number(Number(cureHeight) + Number(getJump(destHeight, cureHeight)));
			if (cureHeight >= destHeight) {
				dis.style.height = destHeight+'px';
				window.clearInterval(dis.animation);
			} else {
				dis.style.height = cureHeight+'px';
			}
			
		}, aniSpeed);

}

function hideTab(id) {
	var id = id.substr(id.indexOf('_')+1);
	
	var dis = document.getElementById('dis_'+id);
	if (dis.style.height == '') dis.style.height = minHeight+'px';
	var cureHeight = dis.style.height.substr(0, dis.style.height.indexOf('p'));
	
	var src = document.getElementById('src_'+id);
	var destHeight = minHeight;
	
	if (dis.animation) window.clearInterval(dis.animation);
	dis.animation = window.setInterval(
		function() {
			cureHeight = Number(Number(cureHeight) - Number(getJump(cureHeight, destHeight)));
			if (cureHeight <= destHeight) {
				dis.style.height = destHeight+'px';
				src.style.visibility = 'hidden';
				window.clearInterval(dis.animation);
			} else {
				dis.style.height = cureHeight+'px';
			}
			
		}, aniSpeed);		
}

function getJump(val1, val2) {
	var speed = Math.round(Number((val1 - val2) / 3));
	if (speed > 15) speed = 15;
	if (speed < 1) speed = 1;
	return speed;
}
