/* Constants */
var rootDirectory = "";

PINT_BrowserDetection("browserupgrade.htm");

function init() {
	var fileName  = PINT_GetCurrentFileName();
	var directory = PINT_GetCurrentDirectory();

	// search bar behavior
	var PINT_search = document.getElementById("q");
	PINT_search.onfocus = function() {
		if(this.value == this.defaultValue){this.value = ''};	
	}

	PINT_AnchorPopupWindows();
	
	window.onresize = freshMargin;
	window.onresize();
}

function cleanup(){}

window.onload = init;
window.onunload = cleanup;

function getViewportWidth() {
			if (window.innerWidth)
				   return window.innerWidth - 16;
			if (typeof(window.document.documentElement.clientWidth == "number") && window.document.documentElement.clientWidth)
				   return window.document.documentElement.clientWidth;
			return window.document.body.clientWidth;
}

function freshMargin() {

	var flashBackground = document.getElementById('flashBackground');
	var windowWidth = getViewportWidth();

	// Case under 1055: Window is too small for document or element to have margins
	if (windowWidth <= 1005)	// if window is less than document size 990px + 15px displacement
		freshMargin = -365;	// left margin: (window width 1005 - html width 1765)/2

	// Case above 1055: Document begins auto margin, but left side of html pushes flash element to the right
	if (windowWidth > 1005 && windowWidth < 1745)	// margin on element is a function of html width
		freshMargin = -(1765-windowWidth)/2+15;	// left margin:  (html width 1765 - window width (x))/2  + 15px displacement

	// Case above 1745: Window larger than Flash Element
	if (windowWidth >= 1745)	// if window is larger than element
		freshMargin = 0;		// left margin: 0, CSS 'margin: 0 auto;' takes over... or text-align: center on broken IE

	flashBackground.style.marginLeft = freshMargin;

}

