// Global variables
flipx = false;
flipy = false;
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page
xScroll = 0;
yScroll = 0;

if( document.getElementById )
{
	document.onmousemove = CaptureMousePosition;
}
else if( document.all )
{
	var root = document.documentElement || document.body;
}


// Functions
function CaptureMousePosition(e)
{
	if( document.all )
	{
		var root = document.documentElement || document.body;

		if( root.clientWidth - window.event.x < 360 || flipx )
		{
			xMousePos = window.event.x+root.scrollLeft - 360;
		}
		else
		{
			xMousePos = window.event.x+root.scrollLeft + 20;
		}
		if( root.clientHeight - window.event.y < 100 || flipy )
		{
			yMousePos = window.event.y+root.scrollTop - 100;
		}
		else
		{
			yMousePos = window.event.y+root.scrollTop;
		}
		xMousePosMax = root.clientWidth+root.scrollLeft;
		yMousePosMax = root.clientHeight+root.scrollTop;
		xScroll = root.scrollLeft;
		yScroll = root.scrollTop;
	}
	else if( document.getElementById )
	{
		xScroll = window.pageXOffset;
		yScroll = window.pageYOffset;
		if( window.innerWidth - e.pageX < 360 || flipx )
		{
			xMousePos = e.pageX - 360 + "px";
		}
		else
		{
			xMousePos = e.pageX + 20 + "px";
		}
		if( (window.innerHeight + window.pageYOffset) - e.pageY < 100 || flipy )
		{
			yMousePos = e.pageY - 100 + "px";
		}
		else
		{
			yMousePos = e.pageY + "px";
		}
		xMousePosMax = window.innerWidth+window.pageXOffset + "px";
		yMousePosMax = window.innerHeight+window.pageYOffset + "px";
	}
}

function IE_PNG_Fix()
{
	var arVersion = navigator.appVersion.split( "MSIE" );
	var version = parseFloat( arVersion[1] );
	if( (version >= 5.5) && (document.body.filters) ) 
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i];
			var imgName = img.src.toUpperCase();
			if( imgName.substring( imgName.length-3, imgName.length ) == "PNG" )
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : "";
				var imgClass = (img.className) ? "class='" + img.className + "' " : "";
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				var imgStyle = "display:inline-block;" + img.style.cssText;
				if( img.align == "left" ) imgStyle = "float:left;" + imgStyle;
				if( img.align == "right" ) imgStyle = "float:right;" + imgStyle;
				if( img.parentElement.href ) imgStyle = "cursor:hand;" + imgStyle;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
				img.outerHTML = strNewHTML;
				i = i - 1;
			}
		}
	}    
}

function Hover( id, x, y )
{
	if( x )
		flipx = true;
	if( y )
		flipy = true;

	var objectId = id;
	ChangeVisibility( id, "block" );
	Move( id, xMousePos, yMousePos );
	//window.status = xScroll + "-" + yScroll + " | " + xMousePos + "-" + yMousePos + " | " + xMousePosMax + "-" + yMousePosMax;
}

function UnHover( id )
{
	var objectId = id;
	ChangeVisibility( id, "none" );
}

function Highlight( obj, is_on )
{
	var color = "";
	var cursor = "";
	var styleObject;

	if( is_on )
	{
		color = "#ffcc00";
		cursor = "pointer";
	}
	else
	{
		color = "";
		cursor = "auto";
	}

	styleObject = obj.style;
	if( styleObject )
	{
		styleObject.backgroundColor = color;
		styleObject.cursor = cursor;
		return true;
	}
	else
	{
		return false;
	}
}

function Location( url )
{
	window.location=url;
}

function ChangeVisibility( objectId, newVisibility )
{
	var styleObject = GetStyle( objectId );
	if( styleObject )
	{
		styleObject.display = newVisibility;
		return true;
	}
	else
	{
		return false;
	}
}

function GetStyle( objectId )
{
	if( document.getElementById && document.getElementById( objectId ))
	{
		// W3C DOM
		return document.getElementById( objectId ).style;
	}
	else if( document.all && document.all( objectId ))
	{
		// MSIE 4 DOM
		return document.all( objectId ).style;
	}
	else if( document.layers && document.layers[objectId] )
	{
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
	}
	else
	{
		return false;
	}
}

function Move( objectId, newXCoordinate, newYCoordinate )
{
	var styleObject = GetStyle( objectId );
    	if( styleObject )
	{
		styleObject.left = newXCoordinate;
		styleObject.top = newYCoordinate;
		return true;
	}
	else
	{
		return false;
	}
}

function ShowDiv( menu, pattern )
{
	var count = menu.options.length;
	for( var i = 0; i < count; i++ )
	{
		ChangeVisibility( pattern + menu.options[i].value, 'none' );
	}
	ChangeVisibility( pattern + menu.options[menu.selectedIndex].value, 'block' );
}

