var shown_sub_int_timeout = 0;
var display_sub_internals_of = '';
var showing_shub_internals_interval = 0;
var target_submenu_opacity = .95;
var suppress_submenu_int_id = 0;
var stop_further_submenu_action = false;

function replace_bg_image(dom_obj, from_str, to_str)
{
	dom_obj.style.backgroundImage = dom_obj.style.backgroundImage.replace(from_str, to_str);	
}

function top_item_over(left_cap_id, tmi)
{
	var left_cap = document.getElementById('divider_'+left_cap_id);
	var right_cap = document.getElementById('divider_' + (left_cap_id+1));
	var img = tmi.getElementsByTagName('img');	
	if(img.length > 0) img[0].src = img[0].src.replace('.gif', '_over.gif');
	if(left_cap) left_cap.style.backgroundImage = left_cap.style.backgroundImage.replace('.gif', '_right_sel.gif');
	if(right_cap) right_cap.style.backgroundImage = right_cap.style.backgroundImage.replace('.gif', '_left_sel.gif');
}

function sam(new_loc) { suppress_and_move(new_loc);	}

function suppress_and_move(new_loc)
{
	suppress_submenu();
	document.location.href='/display.php?'+new_loc.replace(/t=/, 'top_cat=').replace(/a=/, 'author=');
}

function suam(unselect, new_loc) { suppress_unselect_and_move(unselect, new_loc); }

function suppress_unselect_and_move(unselect, new_loc)
{
	suppress_submenu();
	sub_unselect(unselect);
	document.location.href='/display.php?'+new_loc.replace(/t=/, 'top_cat=').replace(/a=/, 'author=');
}

function sub_unselect(unselect)
{
	document.getElementById('title_'+unselect).style.color = '#660000';
	document.getElementById('bg_'+unselect).style.backgroundImage='';
}

function prevent_sub_text_select(unique_id)
{
	document.getElementById('bg_'+unique_id).onselectstart = new Function ("return false");
	document.getElementById('title_'+unique_id).onselectstart = new Function ("return false");
}

function sover(dom_obj)
{
	sub_mouse_over(dom_obj.id.replace(/title_/,''), '/top_nav_assets/');
}

function sub_mouse_over(unique_id, image_prefix)
{
	if(!stop_further_submenu_action)
	{
		document.getElementById('title_'+unique_id).style.color = '#000000';
		document.getElementById('bg_'+unique_id).style.backgroundImage='url('+image_prefix+'selectv3.jpg)';
	}
}

function sout(dom_obj) { sub_mouse_out(dom_obj.id.replace(/title_/,''));	}

function sub_mouse_out(unique_id)
{
	if(!stop_further_submenu_action)
	{	
		document.getElementById('title_'+unique_id).style.color = '#660000';
		document.getElementById('bg_'+unique_id).style.backgroundImage='';
	}
}

function suppress_submenu()
{
	delayedHideAllSubs();
	//stop_further_submenu_action = true;
	//clearTimeout(suppress_submenu_int_id);
	//suppress_submenu_int_id = setTimeout('unsuppress_submenu()', 1000);	
}

function unsuppress_submenu()
{
	//clearTimeout(suppress_submenu_int_id);
	//stop_further_submenu_action = false;
	//delayedHideAllSubs();
}

function submenu_evoked(subm_id, td_obj)
{
	clearTimeout(shown_sub_int_timeout);	
	if(subm_id.length > 0 && !stop_further_submenu_action)
	{
		var subm = document.getElementById(subm_id);
		var subm_inner = document.getElementById(subm_id+'_inner');
		if(subm)
		{
			//find where to put it
			var temp_ntm = td_obj;
			var findX = -6;
			var findY = td_obj.offsetHeight;
			while(temp_ntm)
			{
				if(temp_ntm.offsetTop) findY += temp_ntm.offsetTop;
				if(temp_ntm.offsetLeft) findX += temp_ntm.offsetLeft;
				temp_ntm = temp_ntm.offsetParent;
			}
			//move and open it
			subm.style.left = findX+'px';
			subm.style.top = findY+'px';
			
			subm.style.filter = 'alpha(opacity:0)';
			subm.style.opacity = 0;
			subm.style.display = '';	
			
			display_sub_internals_of = subm_id;	
			clearInterval(showing_shub_internals_interval);
			showing_shub_internals_interval = setInterval('showingSubsInternal()', 25);		
		}
	}
}

function showingSubsInternal()
{
	var subm = document.getElementById(display_sub_internals_of);
	if(subm)
	{
		var current_opacity = (subm.style.opacity * 1);
		if(current_opacity < target_submenu_opacity)
		{
			current_opacity += .1;
			if(current_opacity > target_submenu_opacity) current_opacity = target_submenu_opacity;
			subm.style.filter = 'alpha(opacity:'+(current_opacity*100)+')';
			subm.style.opacity = current_opacity;
		}
		else clearInterval(showing_shub_internals_interval);
	}
	else clearInterval(showing_shub_internals_interval);
}

function subRolledOver(div_obj)
{
	clearTimeout(shown_sub_int_timeout);	
}

function subRolledOut(div_obj)
{
	clearTimeout(shown_sub_int_timeout);
	shown_sub_int_timeout = setTimeout('delayedHideAllSubs(1)', 1000);	
}

function hideSub(sub_id, natural)
{
	if(document.getElementById(sub_id) && document.getElementById(sub_id).style.display != 'none') 
	{	
		document.getElementById(sub_id).style.display = 'none';
	}
}

function hideAllSubs(natural)
{
	clearTimeout(shown_sub_int_timeout);	
	if(!stop_further_submenu_action)
	{
		hideSub('ds', natural);
		hideSub('ss', natural);
		hideSub('es', natural);
		hideSub('ls', natural);
		hideSub('as', natural);
	}
}

function prevent_sub_text_select_arr(subs)
{
	for(var sc=0; sc<subs.length; sc++)
	{
		prevent_sub_text_select(subs[sc]);	
	}
}

//alert('loaded.');