$(document).ready(function(){
	header_tabs = $("#tabs td");
	opened_tab_id = null;
	over_tab = null;
	over_tab_content = null;
	timeout_frame = 300;
	/* functions */
	hide_all_tabs = function() {
		header_tabs.removeClass("active");
		header_tabs.each(function(i){
			var id = $(this).attr("id");
			$("#content_"+id).hide();
		});
	}
	open_tab = function(el) {
		var id = el.attr("id");
		el.addClass('active');
		$("#content_"+id).show();
	}
	open_selected_tab = function() {
		var id = $(this).attr("id");
	}
	mouseover_tab = function() {
		hide_all_tabs();
		open_tab($(this));
		var id = $(this).attr("id");
		over_tab = id.replace("tab_","");
	}
	mouseover_tab_content = function() {
		var id = $(this).attr("id");
		over_tab_content = id.replace("conent_tab_","");
	}
	mouseout_tab = function() {
		over_tab = null;
		mytimeout = setTimeout("timeout_check();",timeout_frame)
	}
	mouseout_tab_content = function() {
		over_tab_content = null;
		mytimeout = setTimeout("timeout_check();",timeout_frame)
	}
	timeout_check = function() {
		if ((over_tab_content == null) && (over_tab == null)) {
			hide_all_tabs();
			open_tab($("#"+opened_tab_id));
		}
	}
	/* actions */
	header_tabs.mouseover(mouseover_tab);
	header_tabs.each(function(i){
		if ($(this).hasClass("open")) {
			opened_tab_id = $(this).attr("id");
		}
		$(this).mouseout(mouseout_tab);
		var id = $(this).attr("id");
		$("#content_"+id).mouseout(mouseout_tab_content);
		$("#content_"+id).mouseover(mouseover_tab_content);
	});
});

