/**
 * jess javascript utils
 *
 */

// browser checks
var agent		= navigator.userAgent.toLowerCase();
var isIE		= (agent.indexOf('msie') > -1);
var isFirefox	= (agent.indexOf('firefox') > -1);
var isSafari	= (agent.indexOf('safari') > -1);
var isOpera		= (agent.indexOf('opera') > -1);

///////////////////////////////////
// EXTRAS TABBED BLOCKS
///////////////////////////////////
var _blockIds = Array(
'search',
'archives',
'subscribe'
);

function toggleTabbedBlock( blockId )
{
	// hide all blocks and set all tabs to non-active
	for ( var b = 0; b < _blockIds.length; b++ )
	{
		$( 'extras-'+ _blockIds[ b ] ).style.display = 'none';
		$( 'extras-nav-'+ _blockIds[ b ] ).className = '';
	}
	// show the specified block
	$( 'extras-'+ blockId ).style.display = 'block';
	$( 'extras-nav-'+ blockId ).className = 'active';
}


///////////////////////////////////
// HOVER NOTES
///////////////////////////////////

var hoverTimeout	= 3;		// the time in seconds before the hover note disappears
var containerID		= 'extras';	// the ID of the container element for the hover note
var offsetX			= -30;		// the X offset for the hover note from the mouse pointer
var offsetY			= -35;		// the Y offset for the hover note from the mouse pointer

// internal vars
var mouseX			= 0;
var mouseY			= 0;
var hoverNote		= null;
var hoverTime		= -1;

function categoryHover( label )
{
	if ( hoverNote == null )
	{
		hoverNote = document.createElement('div');
		hoverNote.className = 'hoverNote';
		$(containerID).appendChild( hoverNote );
	}
	hoverNote.style.display	= 'block';
	hoverNote.style.left	= '' + ( mouseX + offsetX ) + 'px';
	hoverNote.style.top		= '' + ( mouseY + offsetY ) + 'px';
	hoverNote.innerHTML		= label;
	if ( hoverTime == -1 )
	{
		hoverTime = hoverTimeout;
		monitorCategoryHover();
	} else {
		hoverTime = hoverTimeout;
	}
}

function monitorCategoryHover()
{
	hoverTime--;
	if ( hoverTime <= 0 )
	{
		hoverTimer = -1;
		hoverNote.style.display = 'none';
	}
	setTimeout( "monitorCategoryHover()", 1000 );
}

function getMouseXY( e )
{
	if (isIE)
	{
		mouseX = event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop;
	} else {
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	return true;
}
document.onmousemove = getMouseXY;
