
var rootname = 'infotabs';
var max_tabs = 5;
var tab_container = document.getElementById(rootname);
var tab_index = 0;

infotabs_content = new Array();
infotabs_header = new Array();
image_names = new Array();
image_names_active = new Array();

for (tab_index = 0; tab_index < max_tabs; tab_index++) {
	var tab = document.getElementById(rootname + '-content' + tab_index);	
	if (tab) {
		var img_src = document.getElementById(rootname + '-header' + tab_index).src;
		image_names[tab_index] = img_src;
		image_names_active[tab_index] = img_src.replace(/\.jpg$/, '.active.jpg');
		tabs = tab_index + 1;
	}
}

function set_cookie(name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
}

function get_cookie(name) {
	if (document.cookie.length > 0) {
		start = document.cookie.indexOf(name + "=");
		if (start != -1) { 
			start = start + name.length+1; 
			end = document.cookie.indexOf(";", start);
			if (end == -1) {
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(start, end));
		} 
	}
	return "";
}

function tab_show(x) {
	for (i = 0; i < tabs; i++) {
		if (i == x) {
			infotabs_header[i].className = "tabheader-front";
			infotabs_header[i].src = image_names_active[i];
			infotabs_content[i].style.display = "block";		
		} else {
			infotabs_header[i].className = "tabheader-back";
			infotabs_header[i].src = image_names[i];
			infotabs_content[i].style.display = "none";			
		}
	}	
	//set_cookie("active_tab", x);
}

function tab_show_0() { tab_show(0); }
function tab_show_1() { tab_show(1); }
function tab_show_2() { tab_show(2); }
function tab_show_3() { tab_show(3); }
function tab_show_4() { tab_show(4); }

for (i = 0; i < tabs; i++) {
	infotabs_content[i] = document.getElementById("infotabs-content" + i);
	infotabs_header[i] = document.getElementById("infotabs-header" + i);

	switch (i) {
	case 0 : infotabs_header[i].onclick = tab_show_0; break;
	case 1 : infotabs_header[i].onclick = tab_show_1; break;
	case 2 : infotabs_header[i].onclick = tab_show_2; break;
	case 3 : infotabs_header[i].onclick = tab_show_3; break;
	case 4 : infotabs_header[i].onclick = tab_show_4; break;
	}
}

//t = get_cookie("active_tab");
t = 0;
if (t != "" && t >= 0 && t < tabs) {
	tab_show(t);
} else {
	tab_show(0);
}	