﻿var pageName	    = 0;
var timeout         = 1500;
var timerId	    = 0;
var menuBar	    = 0;
var menuItem	    = 0;

function openMenu(id)
{	
	tip.stop();

	cancelTimer();

	if (menuItem) menuItem.style.visibility = 'hidden';

 	if (menuBar) menuBar.style.fontWeight = 'normal'; 

	menuBar = document.getElementById("td" + id);

	if (menuBar) menuBar.style.fontWeight = 'bold'; 

	loadPage(pageName);

	menuItem = document.getElementById(id);

	if (menuItem) menuItem.style.visibility = 'visible';
}

function closeMenu()
{
	tip.stop();

	if (menuItem) menuItem.style.visibility = 'hidden';
 	if (menuBar) menuBar.style.fontWeight = 'normal';

	loadPage(pageName);
}

function closingMenu()
{
	timerId = window.setTimeout(closeMenu, timeout);
}

function cancelTimer()
{
	if (timerId)
	{
		window.clearTimeout(timerId);
		timerId = null;
	}
}

function loadPage(page)
{
	pageName = page;
	var menuText = document.getElementById("td" + page);
 	if (menuText) menuText.style.fontWeight = 'bold'; 
}

document.onclick = closeMenu; 

var tip = function()
{

	var id = 'tipBox';


	var tooltip;
	var shadows;
	var text;


	var timeoutId;
	var intervalId;

	var step = 3;

	var tick = 20;

	var delay = 2500;

	var alpha = 0;

	var endalpha = 95;


	var ie = document.all ? true : false;


	return {

		show:function(tipTable, content, left, top)
		{
			if (tooltip == null)
			{

				tooltip = document.createElement('div');

				tooltip.setAttribute('id',id);
				tooltip.innerHTML = tipTable;
				tooltip.style.opacity = 0;
				document.body.appendChild(tooltip);

				shadows = document.getElementsByName("shadow");
				text = document.getElementById("tipText");

				if (ie)
				{

					tooltip.style.filter = 'alpha(opacity=0)';
				}
			}


			text.innerHTML = content;
	
			tooltip.style.display = 'block';

			tooltip.style.left = left + 'px';

			tooltip.style.top = top + parseInt(tooltip.offsetHeight) + 'px';


			tip.cancel();

			if (menuItem) menuItem.style.visibility = 'hidden';
		 	if (menuBar) menuBar.style.fontWeight = 'normal';

			intervalId = setInterval(function(){tip.fade(1)}, tick);

		},


		fade:function(d)
		{

			var a = alpha;


			if((a != endalpha && d == 1) || (a != 0 && d == -1))
			{
				var i = step;


				if(endalpha - a < step && d == 1)
				{

					i = endalpha - a;


				}
				else if(alpha < step && d == -1)
				{

					i = a;

				}


				alpha = a + (i * d);
				tooltip.style.opacity = alpha * .01;


				if (ie)
				{
					tooltip.style.filter = 'alpha(opacity=' + alpha + ')';

				}

				for (var i = 0; i < shadows.length; i++)
				{
					shadows[i].style.opacity = alpha * .006;
					
					if (ie)
					{
						shadows[i].style.filter = 'alpha(opacity=' + alpha * .6 + ')';
					}
				}
			}
			else
			{

				clearInterval(intervalId);

				if(d == -1){tooltip.style.display = 'none'}

			}

		},


		close:function()
		{

			clearTimeout(timeoutId);
			timeoutId = setTimeout(function(){tip.hide()}, delay);

		},


		hide:function()
		{

			clearInterval(intervalId);
			intervalId = setInterval(function(){tip.fade(-1)}, tick);

		},


		cancel:function()
		{

			alpha = 0;
			clearTimeout(timeoutId);
			clearInterval(intervalId);

		},


		stop:function()
		{

			alpha = 0;
			clearTimeout(timeoutId);
			clearInterval(intervalId);


			if (tooltip)
			{
				tooltip.style.opacity = 0;
				tooltip.style.display = 'none';
			}
		},


		stick:function()
		{

			clearTimeout(timeoutId);

			tooltip.style.opacity = endalpha * .01;


			if (ie)
			{
				tooltip.style.filter = 'alpha(opacity=' + endalpha + ')';

			}

			for (var i = 0; i < shadows.length; i++)
			{
				shadows[i].style.opacity = endalpha * .006;
			
				if (ie)
				{
					shadows[i].style.filter = 'alpha(opacity=' + endalpha * .6 + ')';
				}
			}
		}

	};

}();

// utilities
function trim(b)
{
	for(var b=b.replace(/^\s\s*/,""),c=/\s/,a=b.length;c.test(b.charAt(--a)););
	return b.slice(0,a+1);
}

function trim (s,e)
{
	try
	{
		s=s.replace(/^[\s\u3000]+|[\s\u3000]+$/g,"");
		if(e)
		{
			s=_euc(s);
		}
	}
	catch(e){}
	return s||"";
}

function getBounds(obj) 
{
	var bounds = new Object;
	bounds.x = 0;
	bounds.y = 0;

	if (obj) 
	{
		bounds.x = obj.offsetLeft;
		bounds.y = obj.offsetTop;

		if (object.offsetParent) 
		{
			var parent = getBounds(obj.offsetParent);
			bounds.x += parent.x;
			bounds.y += parent.y;
		}
	}

	bounds.width = obj.offsetWidth;
	bounds.height = obj.offsetHeight;

	return bounds;
}
// js

