var speed = 1;
var increment = 5;
var max_width = 80;
var min_width = 10;
var normal_width = 33;
var cur_width = new Array();
cur_width[0] = cur_width[1] = cur_width[2] = cur_width[3] = 33;
var left1 = 0;
var left2 = 0;
var left3 = 0;
var cur_left = 0;
var tab_timer = 0;
var tab_title = new Array(0,tab_captions[1],tab_captions[2],tab_captions[3]);
//var text_content = new Array('','search','semi','full');
function enlargeTab(idx)
{
	if (tab_timer==0 && cur_width[idx]<max_width) {
		tab_timer = setInterval('enlargeTab'+idx+'()',speed);
		changeColor(idx,1);
	}
}
function enlargeTab1()
{
	idx = 1;
	var is_ready = 1;
	if (cur_left<left1) {
		moveTab(increment);
		is_ready = 0;
	}
	if (cur_width[idx]<max_width) {
		resizeTD(idx,increment);
		is_ready = 0;
	}
	var others = new Array(2,3);
	for (i=0;i<others.length;i++) {
		j = others[i];
		changeCaption(j,'');
		changeColor(j,0);
		changeContent(j,'<img src="images/text_vertical_'+j+'.gif" alt="" class="minitext" />');
		if (cur_width[j]>min_width) {
			resizeTD(j,increment*-1);
			/*
			cur_width[j] = min_width;
			document.getElementById('tab'+j).style.width = '';
			*/
			is_ready = 0;
		}
	}
	if (is_ready) {
		clearInterval(tab_timer);
		tab_timer = 0;
		changeCaption(idx,tab_title[idx]);
		changeContent(idx,text_content[idx]);
	}
	debug();
}
function enlargeTab2()
{
	idx = 2;
	var is_ready = 1;
	if (cur_left>left2) {
		moveTab(increment*-1);
		is_ready = 0;
	}
	if (cur_left<left2) {
		moveTab(increment);
		is_ready = 0;
	}
	if (cur_width[idx]<max_width) {
		resizeTD(idx,increment);
		is_ready = 0;
	}
	var others = new Array(1,3);
	for (i=0;i<others.length;i++) {
		j = others[i];
		changeCaption(j,'');	
		changeColor(j,0);	
		changeContent(j,'<img src="images/text_vertical_'+j+'.gif" alt="" class="minitext" />');
		if (cur_width[j]>min_width) {
			resizeTD(j,increment*-1);
			is_ready = 0;
		}
	}
	if (is_ready) {
		clearInterval(tab_timer);
		tab_timer = 0;
		changeCaption(idx,tab_title[idx]);
		changeContent(idx,text_content[idx]);
	}
	debug();
}
function enlargeTab3()
{
	idx = 3;
	var is_ready = 1;
	if (cur_left>left3) {
		moveTab(increment*-1);
		is_ready = 0;
	}
	if (cur_width[idx]<max_width) {
		resizeTD(idx,increment);
		is_ready = 0;
	}
	var others = new Array(1,2);
	for (i=0;i<others.length;i++) {
		j = others[i];
		changeCaption(j,'');
		changeColor(j,0);		
		changeContent(j,'<img src="images/text_vertical_'+j+'.gif" alt="" class="minitext" />');
		if (cur_width[j]>min_width) {
			resizeTD(j,increment*-1);
			is_ready = 0;
		}
	}
	if (is_ready) {
		clearInterval(tab_timer);
		tab_timer = 0;
		changeCaption(idx,tab_title[idx]);
		changeContent(idx,text_content[idx]);
	}
	debug();
}

function moveTab(inc)
{
	cur_left += inc;
	document.getElementById('slidetab').style.left = cur_left+'px';
}
function resizeTable(inc)
{
	return 1;
	cur_width_table += inc;
	document.getElementById('slidetab').style.width = cur_width_table +'px';
}
function resizeTD(idx,inc)
{
	cur_width[idx] += inc;
	document.getElementById('tab'+idx).style.width = cur_width[idx]+'%';
}
function changeCaption(idx,text)
{
	document.getElementById('tab_middle'+idx).innerHTML = '<div class="tab_middle_inner">'+text+'</div>';
}
function changeContent(idx,text) 
{
	document.getElementById('tab_body'+idx).innerHTML = text;
}
function changeColor(idx,mode)
{
	var color = '#999595';
	if (mode) {
		color = '#3289B5';
	}
	document.getElementById('tab_header'+idx).style.backgroundColor = color;
	document.getElementById('tab_border'+idx).style.borderColor = color;
}
function debug()
{
	//document.getElementById('debug').innerHTML = cur_width[1]+','+cur_width[2]+','+cur_width[3];
}
function notWithin(e,divId) {
	return !e.within(Ext.get(divId), true);
}
var resetTabStart = function(e, el, divId) {
	if(notWithin(e,divId)) {
		if (tab_timer!=0) {
			clearInterval(tab_timer);
			tab_timer = 0;
		}
		tab_timer = setInterval('resetTabs()',speed);
		changeColor(1,0);
		changeColor(2,0);
		changeColor(3,0);
	}
}
function resetTabs()
{
	var idx = 0;
	var is_ready = 1;
	var widest = 0;
	for (idx=1;idx<=3;idx++) {
		changeContent(idx,'');
		if (cur_width[idx]>normal_width) {
			resizeTD(idx,increment*-1);
			is_ready = 0;
		}
		if (cur_width[idx]<normal_width) {
			resizeTD(idx,increment);
			is_ready = 0;
		}
	}
	if (is_ready) {
		clearInterval(tab_timer);
		tab_timer = 0;
		for (idx=1;idx<=3;idx++) {
			changeCaption(idx,tab_title[idx]);
			changeContent(idx,text_content_default[idx]);
		}
	}
	debug();
}
