//
// Browser specific workarounds.
//

// Determine the general browser type.
var MS = (navigator.appName.toUpperCase().match(/MICROSOFT/) ? true : false);
var NS = (navigator.appName.toUpperCase().match(/NETSCAPE/) ? true : false);
if (navigator.vendor)
	var Apple = (navigator.vendor.toUpperCase().match(/APPLE/) ? true : false);
else
	var Apple = false;

//
// Wrap the browser specific accessors.
//
function getRef(id)
{
	if (document.getElementById) return document.getElementById(id);
	if (document.all) return document.all[id];
	if (document.layers) return document.layers[id];
	alert( "Miss" );
}

function getStyle(id)
{
	return (document.all ? getRef(id) : getRef(id).style);
}

function getClientWidth()
{
	if ( typeof( window.innerWidth ) == 'number' )
	{
		return window.innerWidth;
	}
	else if ( document.documentElement &&
			  document.documentElement.clientWidth )
			
	{
		return document.documentElement.clientWidth;
	}
	else if ( document.body && document.body.clientWidth )
	{
		return document.body.clientWidth;
	}
	else
	{
		return 0;
	}
}

//
// Keep the fixed width object in the same place (towards the center) with
// and without the addition of a scrollbar on the right side.  This workaround
// is only needed for W3C strict browsers (use margin: auto otherwise).
//
// Implementation:  set a global alias to the id of a fixed width object before
// including this library.  Defaults to an id called "page".
//
var objectId = 'page';

adjustFixed = function()
{
	obj = getRef( objectId );
	
	// Determine the delta between the current client width and the fixed
	// width of the object.
	clientWidth = getClientWidth();
	delta = clientWidth - obj.offsetWidth;

	if ( delta <= 0 )
		obj.style.marginLeft = '0px';
	else
		obj.style.marginLeft = (delta / 2) + 'px';

	obj.style.visibility = 'visible';
}

// Attach workaround to NS browsers
if (!MS && window.addEventListener)
{
	window.addEventListener("load", adjustFixed, false);
	window.addEventListener("resize", adjustFixed, false);
}

if (NS && Apple)
{
	// Safari
	document.write('<link rel="stylesheet" href="css/safari.css" />');
}
